2018-10-17 01:56:56 -07:00
|
|
|
import addressGenerator from './addressGenerator'
|
|
|
|
import helpers from './helpers'
|
|
|
|
import { constants } from './constants'
|
2017-12-06 23:02:38 -08:00
|
|
|
|
|
|
|
export default class KeysManager {
|
2018-10-15 07:52:03 -07:00
|
|
|
async init({ web3, netId, addresses }) {
|
2018-10-17 01:56:56 -07:00
|
|
|
const { KEYS_MANAGER_ADDRESS } = addresses
|
|
|
|
console.log('Keys Manager ', KEYS_MANAGER_ADDRESS)
|
2018-01-29 10:02:05 -08:00
|
|
|
|
2018-10-17 01:56:56 -07:00
|
|
|
const KeysManagerAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'KeysManager')
|
2018-01-29 10:02:05 -08:00
|
|
|
|
2018-10-17 01:56:56 -07:00
|
|
|
this.instance = new web3.eth.Contract(KeysManagerAbi, KEYS_MANAGER_ADDRESS)
|
2018-10-11 09:02:59 -07:00
|
|
|
|
2018-10-17 01:56:56 -07:00
|
|
|
const networkName = constants.NETWORKS[netId].NAME.toLowerCase()
|
2019-04-26 04:12:22 -07:00
|
|
|
if (networkName === 'dai') {
|
2018-10-17 01:56:56 -07:00
|
|
|
this.gasPrice = web3.utils.toWei('0', 'gwei')
|
2018-10-11 09:02:59 -07:00
|
|
|
} else {
|
2018-10-17 01:56:56 -07:00
|
|
|
this.gasPrice = web3.utils.toWei('2', 'gwei')
|
2018-10-11 09:02:59 -07:00
|
|
|
}
|
2017-12-06 23:02:38 -08:00
|
|
|
}
|
2018-01-29 10:02:05 -08:00
|
|
|
|
2017-12-06 23:02:38 -08:00
|
|
|
async isInitialKeyValid(initialKey) {
|
2018-02-23 05:31:56 -08:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-10-17 01:56:56 -07:00
|
|
|
const methods = this.instance.methods
|
|
|
|
let getInitialKeyStatus
|
2018-08-10 00:26:59 -07:00
|
|
|
if (methods.getInitialKeyStatus) {
|
2018-10-17 01:56:56 -07:00
|
|
|
getInitialKeyStatus = methods.getInitialKeyStatus
|
2018-07-23 05:55:14 -07:00
|
|
|
} else {
|
2018-10-17 01:56:56 -07:00
|
|
|
getInitialKeyStatus = methods.initialKeys
|
2018-07-23 05:55:14 -07:00
|
|
|
}
|
2018-10-15 07:52:03 -07:00
|
|
|
getInitialKeyStatus(initialKey)
|
|
|
|
.call()
|
|
|
|
.then(function(result) {
|
2018-10-17 01:56:56 -07:00
|
|
|
resolve(result)
|
2018-10-15 07:52:03 -07:00
|
|
|
})
|
|
|
|
.catch(function(e) {
|
2018-10-17 01:56:56 -07:00
|
|
|
reject(false)
|
|
|
|
})
|
|
|
|
})
|
2017-12-06 23:02:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async generateKeys() {
|
2018-10-17 01:56:56 -07:00
|
|
|
return await addressGenerator()
|
2017-12-06 23:02:38 -08:00
|
|
|
}
|
2018-10-04 05:36:03 -07:00
|
|
|
|
2018-10-15 07:52:03 -07:00
|
|
|
createKeys({ mining, voting, payout, sender }) {
|
2018-10-11 09:02:59 -07:00
|
|
|
return this.instance.methods.createKeys(mining, voting, payout).send({
|
2018-10-04 06:05:12 -07:00
|
|
|
from: sender,
|
2018-10-11 09:02:59 -07:00
|
|
|
gasPrice: this.gasPrice
|
2018-10-17 01:56:56 -07:00
|
|
|
})
|
2017-12-06 23:02:38 -08:00
|
|
|
}
|
2018-10-15 07:52:03 -07:00
|
|
|
}
|