This repository has been archived by the owner on Mar 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deployTokenRules.js
92 lines (77 loc) · 2.75 KB
/
deployTokenRules.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
'use strict';
/**
* @fileoverview Nodejs Program to deploy TokenRules Contract.
* See perform method for sample code.
*
* Contract: https://github.com/OpenSTFoundation/openst-contracts/blob/v0.9.4/contracts/TokenRules.sol
* @author [email protected] (Kedar Chandrayan)
*/
const PerformerBase = require('./PerformerBase');
class Performer extends PerformerBase {
constructor(program) {
super(program);
let config = this.getSetupConfig();
let openST = this.openST;
//Set the deployer params.
this.deployParams = {
from: config.deployerAddress,
gasPrice: config.gasPrice,
gas: config.gas
};
this.eip20Address = program.eip20Address;
this.organizationAddress = program.orgAddress || config.organizationAddress;
this.validate();
this.log('EIP20 Address:', this.eip20Address);
this.log('Organisation Address:', this.organizationAddress);
}
perform() {
//1. Create a deployer.
let deployer = new this.openST.Deployer(this.deployParams);
//2. Deploy MockToken.
this.log('Deploying TokenRules Contract');
deployer
.deployTokenRules(this.organizationAddress, this.eip20Address)
.then((receipt) => {
this.logReceipt(receipt);
if (receipt.status && receipt.contractAddress) {
this.exitWithoutError('TokenRules Contract Address:', receipt.contractAddress);
} else {
this.exitWithError('Failed to deploy TokenRules. See receipt for details.');
}
})
.catch((reason) => {
this.logError(reason);
this.exitWithError('Failed to deploy contract. See error for details.');
});
}
validate() {
let openST = this.openST;
let web3 = openST.web3();
let utils = web3.utils;
if (!utils.isAddress(this.eip20Address)) {
let error = 'Invalid EIP20 Contract Address. Please provide EIP20 contract address using -e or --eip20-address flag.';
this.exitWithError(error);
return;
}
if (!utils.isAddress(this.organizationAddress)) {
let error = 'Invalid Organisation Address. Please provide Organisation address using -o or --org-address flag.';
this.exitWithError(error);
return;
}
}
}
const program = PerformerBase.getProgram();
program
.option('--eip20-address [eip20Address]', 'Required. EIP20 Token contract address')
.option('--org-address [Organisation Address]', 'defaults to config.organizationAddress. Organisation key address');
program.on('--help', function() {
console.log('');
console.log(' Example:');
console.log('');
console.log(' node deployTokenRules.js --eip20-address 0x7F8d92283Fa96f9F2FE1596e718584F8aCA70264');
console.log('');
console.log('');
});
program.parse(process.argv);
let performer = new Performer(program);
performer.perform();