-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor.js
executable file
·79 lines (64 loc) · 2.13 KB
/
executor.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
/*
Executor for Light Token.
Heavily Based on Aion Web3 API Example
Author: Cosimo Iaia <[email protected]>
Date: 29/04/2018
This file is distribuited under the terms of GNU General Public v3
*/
const path = require('path');
const core = require('./core.js');
const tokens = require('./token.js');
const config = require('./config.js');
const fs = require('fs');
const log = require('./core.js').log;
const unlock = async () => {
let unlocked = false;
try {
await core.unlockAccount(config.userAddress, config.password, 314159);
} catch (e) {
// do nothing here
}
return unlocked;
}
module.exports.execute = async (statement) => {
if (statement.token === tokens.DEPLOY) {
await unlock();
const source = fs.readFileSync(path.resolve(__dirname, 'token.sol'), "utf-8");
const compiled = await core.compile(source);
const tokenInstance = await core.deploy(compiled, config.userAddress);
log("token deployed at: " + tokenInstance.address);
log("please set the contractAddress field in your config to this address");
}
//{contract, address, value, userAddress}
if (statement.token === tokens.MINT) {
await unlock();
const tokenInstance = core.createAt(config.contractAddress);
const response = await core.mint({
contract: tokenInstance,
address: statement.address,
value: statement.value,
userAddress: config.userAddress
});
log("transaction sent: " + response);
}
if (statement.token === tokens.TRANSFER) {
await unlock();
const tokenInstance = core.createAt(config.contractAddress);
//{contract, to, value, userAddress}
const response = await core.transfer({
contract: tokenInstance,
to: statement.address,
value: statement.value,
userAddress: config.userAddress
});
}
if (statement.token === tokens.BALANCE) {
const tokenInstance = core.createAt(config.contractAddress);
log(JSON.stringify(tokenInstance));
const balance = await core.getBalance({
contract: tokenInstance,
address: statement.address
});
log("address: " + statement.address + " has balance: " + balance);
}
}