2017-12-06 23:02:38 -08:00
|
|
|
import Web3 from 'web3';
|
|
|
|
import addressGenerator from './addressGenerator';
|
2018-01-29 10:02:05 -08:00
|
|
|
import helpers from "./helpers";
|
2017-12-06 23:02:38 -08:00
|
|
|
|
|
|
|
export default class KeysManager {
|
2018-01-30 18:06:34 -08:00
|
|
|
async init({web3, netId, addresses}){
|
2018-01-29 10:02:05 -08:00
|
|
|
this.web3_10 = new Web3(web3.currentProvider);
|
2018-01-30 18:06:34 -08:00
|
|
|
const {KEYS_MANAGER_ADDRESS} = addresses;
|
2018-01-04 16:46:11 -08:00
|
|
|
console.log('Keys Manager ', KEYS_MANAGER_ADDRESS);
|
2018-01-29 10:02:05 -08:00
|
|
|
const branch = helpers.getBranch(netId);
|
|
|
|
|
2018-08-10 00:26:59 -07:00
|
|
|
const KeysManagerAbi = await helpers.getABI(branch, 'KeysManager')
|
2018-01-29 10:02:05 -08:00
|
|
|
|
2018-01-29 10:40:43 -08:00
|
|
|
this.keysInstance = new this.web3_10.eth.Contract(KeysManagerAbi, KEYS_MANAGER_ADDRESS);
|
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-08-10 00:26:59 -07:00
|
|
|
const methods = this.keysInstance.methods
|
2018-07-23 05:55:14 -07:00
|
|
|
let getInitialKeyStatus
|
2018-08-10 00:26:59 -07:00
|
|
|
if (methods.getInitialKeyStatus) {
|
|
|
|
getInitialKeyStatus = methods.getInitialKeyStatus
|
2018-07-23 05:55:14 -07:00
|
|
|
} else {
|
2018-08-10 00:26:59 -07:00
|
|
|
getInitialKeyStatus = methods.initialKeys
|
2018-07-23 05:55:14 -07:00
|
|
|
}
|
|
|
|
getInitialKeyStatus(initialKey).call().then(function(result){
|
2018-02-23 05:31:56 -08:00
|
|
|
resolve(result);
|
|
|
|
}).catch(function(e) {
|
|
|
|
reject(false);
|
|
|
|
});
|
|
|
|
})
|
2017-12-06 23:02:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async generateKeys() {
|
|
|
|
return await addressGenerator();
|
|
|
|
}
|
|
|
|
createKeys({mining, voting, payout, sender}){
|
2018-01-05 12:14:52 -08:00
|
|
|
const gasPrice = this.web3_10.utils.toWei('2', 'gwei')
|
|
|
|
return this.keysInstance.methods.createKeys(mining, voting, payout).send({from: sender, gasPrice})
|
2017-12-06 23:02:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|