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

29 lines
956 B
JavaScript
Raw Normal View History

2017-12-06 23:02:38 -08:00
import Web3 from 'web3';
import addressGenerator from './addressGenerator';
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}){
this.web3_10 = new Web3(web3.currentProvider);
2018-01-30 18:06:34 -08:00
const {KEYS_MANAGER_ADDRESS} = addresses;
console.log('Keys Manager ', KEYS_MANAGER_ADDRESS);
const branch = helpers.getBranch(netId);
let KeysManagerAbi = await helpers.getABI(branch, 'KeysManager')
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
}
2017-12-06 23:02:38 -08:00
async isInitialKeyValid(initialKey) {
return await this.keysInstance.methods.initialKeys(initialKey).call();
}
async generateKeys() {
return await addressGenerator();
}
createKeys({mining, voting, payout, sender}){
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
}
}