poa-dapps-keys-generation/src/utils/keysManager.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

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 }) {
const { KEYS_MANAGER_ADDRESS } = addresses
console.log('Keys Manager ', KEYS_MANAGER_ADDRESS)
const KeysManagerAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'KeysManager')
this.instance = new web3.eth.Contract(KeysManagerAbi, KEYS_MANAGER_ADDRESS)
const networkName = constants.NETWORKS[netId].NAME.toLowerCase()
if (networkName === 'dai-test' || networkName === 'dai') {
this.gasPrice = web3.utils.toWei('0', 'gwei')
} else {
this.gasPrice = web3.utils.toWei('2', 'gwei')
}
2017-12-06 23:02:38 -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) => {
const methods = this.instance.methods
let getInitialKeyStatus
if (methods.getInitialKeyStatus) {
getInitialKeyStatus = methods.getInitialKeyStatus
} else {
getInitialKeyStatus = methods.initialKeys
}
2018-10-15 07:52:03 -07:00
getInitialKeyStatus(initialKey)
.call()
.then(function(result) {
resolve(result)
2018-10-15 07:52:03 -07:00
})
.catch(function(e) {
reject(false)
})
})
2017-12-06 23:02:38 -08:00
}
async generateKeys() {
return await addressGenerator()
2017-12-06 23:02:38 -08:00
}
2018-10-15 07:52:03 -07:00
createKeys({ mining, voting, payout, sender }) {
return this.instance.methods.createKeys(mining, voting, payout).send({
from: sender,
gasPrice: this.gasPrice
})
2017-12-06 23:02:38 -08:00
}
2018-10-15 07:52:03 -07:00
}