-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionHopper.js
100 lines (79 loc) · 1.79 KB
/
ActionHopper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module.exports = class ActionHopper {
constructor(signer, api) {
this.hopper = [];
this.signer = signer;
this.permission = 'active';
this.api = api;
//TODO: this.cosign = true; //esr mode
//TODO: this.energyProvider = 'https://energy.dappetizer.io/esr=...';
}
//return contents of hopper
getHopper() {
return this.hopper;
}
//return signing account
getSigner() {
return this.signer;
}
//return signing permission
getPermission() {
return this.permission;
}
//load an action into the hopper
load(action) {
this.hopper.push(action);
}
//load an action into the front of the hopper
frontload(action) {
this.hopper.unshift(action);
}
//TODO: filter hopper for cosign auth
filter() {
let temp_hopper = this.hopper;
// temp_hopper.forEach(element => {
// });
}
//view the actions loaded in hopper
view() {
console.log(this.hopper);
}
//clear the hopper
clear() {
this.hopper = [];
}
//TODO: push cosigned trx to cosigner
transport() {
}
//cosign a transaction
async cosign() {
const res = await this.api.transact({
actions: this.getHopper()
}, {
broadcast: false,
sign: true,
blocksBehind: 3,
expireSeconds: 30,
});
console.log(res);
}
//sign and broadcast contents of hopper
async fire() {
const res = await this.api.transact({
actions: this.getHopper()
}, {
broadcast: true,
sign: true,
blocksBehind: 3,
expireSeconds: 30,
});
//if trx executed
if (res.processed.receipt.status == 'executed') {
console.log('Transaction Executed:', res.transaction_id);
} else {
//TODO: report error
console.log('Transaction Error');
}
//clear hopper
this.clear();
}
};