forked from ConsenSysMesh/uport-js-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
53 lines (44 loc) · 1.75 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
const Contract = require('truffle-contract')
const uportIdentity = require('uport-identity')
const registryArtifact = require('uport-registry')
const identityManagerArtifact = uportIdentity.IdentityManager.v1
const EthJS = require('ethjs-query');
const HttpProvider = require('ethjs-provider-http');
const SignerProvider = require('ethjs-provider-signer');
const sign = require('ethjs-signer').sign;
const Registry = Contract(registryArtifact)
const IdentityManager = Contract(identityManagerArtifact)
const deploy = (network, {from, gas, gasPrice, IdentityManagerArgs = {}} = {}, privKey) => {
let provider
if (privKey) {
provider = new SignerProvider(network, {
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, privKey))
});
} else {
provider = network || typeof(network) === 'string' ? new HttpProvider(network) : network
}
Registry.setProvider(provider)
IdentityManager.setProvider(provider)
const eth = new EthJS(provider)
const userTimeLock = IdentityManagerArgs.userTimeLock || 50
const adminTimeLock = IdentityManagerArgs.adminTimeLock || 200
const adminRate = IdentityManagerArgs.adminRate || 50
gas = gas || 3000000
let resObj = {}
let address
return eth.coinbase().then(res => {
from = from || res
return gasPrice ? gasPrice : eth.gasPrice()
}).then(res => {
gasPrice = res
const fakePrevVersion = 0 // Registry contract constructor expects a previous version
return Registry.new(fakePrevVersion, {from, gas})
}).then(instance => {
resObj.Registry = instance.address
return IdentityManager.new(userTimeLock, adminTimeLock, adminRate, {from, gas})
}).then(instance => {
resObj.IdentityManager = instance.address
return resObj
}).catch(console.log)
}
module.exports = deploy