-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdeploy.js
executable file
·68 lines (55 loc) · 1.46 KB
/
deploy.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
const fs = require('fs')
const path = require('path')
const eos = require('./eos')
const source = async (directory, name) => {
const wastPath = path.join(process.cwd(), directory, name.concat('.wasm'))
const abiPath = path.join(process.cwd(), directory, name.concat('.abi'))
const wast = new Promise(resolve => {
fs.readFile(wastPath, (_, r) => resolve(r))
})
const abi = new Promise(resolve => {
fs.readFile(abiPath, (_, r) => resolve(r))
})
return Promise.all([wast, abi])
}
const deploy = async (config) => {
const { directory, name, account, accountCreated, creator, owner, active, stake, bytes } = config
const [ wast, abi ] = await source(directory, name)
if(!wast || !abi)
throw new Error("Source files not found")
await eos.transaction((tx) => {
if (!accountCreated) {
tx.newaccount({
creator,
owner,
active,
name: account
})
tx.buyrambytes({
payer: creator,
receiver: account,
bytes: bytes
})
tx.delegatebw({
from: creator,
receiver: account,
stake_net_quantity: `${stake}.0000 EOS`,
stake_cpu_quantity: `${stake}.0000 EOS`,
transfer: 0
})
}
tx.setcode({
account: account,
code: wast,
vmtype: 0,
vmversion: 0
})
tx.setabi({
account: account,
abi: JSON.parse(abi)
})
}).catch(e => {
console.error(e)
})
}
module.exports = deploy