-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcyber.js
More file actions
73 lines (65 loc) · 1.63 KB
/
Copy pathcyber.js
File metadata and controls
73 lines (65 loc) · 1.63 KB
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
import { base64ToBinary } from 'cyberwayjs/dist/eosjs-numeric';
import Basic from './basic';
export default class Cyber extends Basic {
_contractAccount = 'cyber';
_contractActions = ['newaccount', 'updateauth', 'setcode', 'setabi'];
createAccount(actor, { name, activePubkey, ownerPubkey }, options) {
return this.newaccount(
actor,
{
creator: this._contractAccount,
name,
owner: {
threshold: 1,
keys: [{ key: ownerPubkey, weight: 1 }],
accounts: [],
waits: [],
},
active: {
threshold: 1,
keys: [{ key: activePubkey, weight: 1 }],
accounts: [],
waits: [],
},
},
options
);
}
async deployContract(actor, { wasm, abi }, options) {
const [setcodeAction] = await this.setcode(
actor,
{
account: actor.accountName,
vmtype: 0,
vmversion: 0,
code: wasm,
},
{ broadcast: false }
);
const [setabiAction] = await this.setabi(
actor,
{
account: actor.accountName,
abi,
},
{ broadcast: false }
);
return this.transact(
{
actions: [setcodeAction, setabiAction],
},
{ ...options, broadcast: true }
);
}
async cloneContract(actor, { fromContract }, options) {
const { abi, wasm } = await this.api.rpc.get_raw_code_and_abi(fromContract);
return this.deployContract(
actor,
{
wasm: Buffer.from(base64ToBinary(wasm)).toString('hex'),
abi: Buffer.from(base64ToBinary(abi)).toString('hex'),
},
options
);
}
}