Merge pull request #63 from vbaranov/core

(Update) chain-spec repo as endpoint for contracts addresses and ABIs
This commit is contained in:
Roman Storm 2018-01-29 21:38:54 -08:00 committed by GitHub
commit 3bd1251b60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 151 additions and 787 deletions

View File

@ -9,6 +9,7 @@ import { error } from 'util';
import addressGenerator from './addressGenerator'
import JSzip from 'jszip';
import FileSaver from 'file-saver';
import { constants } from './constants';
function generateElement(msg){
let errorNode = document.createElement("div");
@ -44,9 +45,10 @@ class App extends Component {
isDisabledBtn: false
}
this.keysManager = null;
getWeb3().then((web3Config) => {
getWeb3().then(async (web3Config) => {
this.setState({web3Config})
this.keysManager = new KeysManager({
this.keysManager = new KeysManager()
await this.keysManager.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
});
@ -75,7 +77,6 @@ class App extends Component {
const mining = await addressGenerator();
const voting = await addressGenerator();
const payout = await addressGenerator();
const netIdName = this.state.web3Config.netIdName;
this.setState({
mining,
voting,
@ -114,7 +115,6 @@ class App extends Component {
icon: 'error',
title: 'Error',
content: generateElement(invalidKeyMsg)
})
return;
}
@ -130,15 +130,20 @@ class App extends Component {
console.log(receipt);
this.setState({loading: false})
swal("Congratulations!", "Your keys are generated!", "success");
await this.generateZip({mining, voting, payout});
await this.generateZip({mining, voting, payout, netIdName: this.state.web3Config.netIdName});
}).catch((error) => {
console.error(error.message);
this.setState({loading: false, keysGenerated: false})
var content = document.createElement("div");
let msg;
if (error.message.includes(constants.userDeniedTransactionPattern))
msg = `Error: User ${constants.userDeniedTransactionPattern}`
else
msg = error.message
content.innerHTML = `<div>
Something went wrong!<br/><br/>
Please contact Master Of Ceremony<br/><br/>
${error.message}
${msg}
</div>`;
swal({
icon: 'error',

View File

View File

@ -1,18 +1,44 @@
const CORE_ADDRESSES = {
KEYS_MANAGER_ADDRESS: "0xfc90125492e58dbfe80c0bfb6a2a759c4f703ca8",
import { messages } from "./messages";
import swal from 'sweetalert';
import helpers from "./helpers";
// const local = {
// "KEYS_MANAGER_ADDRESS": "0x3ef32bb244016ad9af8c8f45398511e7e551b581"
//}
let SOKOL_ADDRESSES = {};
let CORE_ADDRESSES = {};
function getContractsAddresses(branch) {
let addr = helpers.addressesURL(branch);
fetch(helpers.addressesURL(branch)).then(function(response) {
return response.json();
}).then(function(contracts) {
switch (branch) {
case 'core':
CORE_ADDRESSES = contracts;
break;
case 'sokol':
SOKOL_ADDRESSES = contracts;
break;
default:
CORE_ADDRESSES = contracts;
break;
}
}).catch(function(err) {
helpers.wrongRepoAlert(addr);
});
}
const SOKOL_ADDRESSES = {
KEYS_MANAGER_ADDRESS: "0x1aa02bd52fe418ac70263351282f66f1dacf898c",
}
getContractsAddresses('core');
getContractsAddresses('sokol');
module.exports = (netId) => {
switch (netId){
case '77':
return SOKOL_ADDRESSES
case '99':
return CORE_ADDRESSES
default:
return CORE_ADDRESSES
}
}
export default (netId) => {
switch (netId) {
case '77':
return SOKOL_ADDRESSES
case '99':
return CORE_ADDRESSES
default:
return CORE_ADDRESSES
}
}

11
src/constants.js Normal file
View File

@ -0,0 +1,11 @@
let constants = {};
constants.organization = 'poanetwork';
constants.repoName = 'poa-chain-spec';
constants.addressesSourceFile = 'contracts.json';
constants.ABIsSources = {
'KeysManager': 'KeysManager.abi.json'
};
constants.userDeniedTransactionPattern = 'User denied transaction';
module.exports = {
constants
}

71
src/helpers.js Normal file
View File

@ -0,0 +1,71 @@
import { constants } from "./constants";
import { messages } from "./messages";
import swal from 'sweetalert';
var toAscii = function(hex) {
var str = '',
i = 0,
l = hex.length;
if (hex.substring(0, 2) === '0x') {
i = 2;
}
for (; i < l; i+=2) {
var code = parseInt(hex.substr(i, 2), 16);
if (code === 0) continue; // this is added
str += String.fromCharCode(code);
}
return str;
};
function addressesURL(branch) {
const URL = `https://raw.githubusercontent.com/${constants.organization}/${constants.repoName}/${branch}/${constants.addressesSourceFile}`;
return URL;
}
function ABIURL(branch, contract) {
const URL = `https://raw.githubusercontent.com/${constants.organization}/${constants.repoName}/${branch}/abis/${constants.ABIsSources[contract]}`;
return URL;
}
function getABI(branch, contract) {
let addr = ABIURL(branch, contract);
return fetch(addr).then(function(response) {
return response.json();
})
}
function wrongRepoAlert(addr) {
var content = document.createElement("div");
content.innerHTML = `<div>
Something went wrong!<br/><br/>
${messages.wrongRepo(addr)}
</div>`;
swal({
icon: 'error',
title: 'Error',
content: content
});
}
function getBranch(netId) {
switch (netId) {
case '77':
return 'sokol'
case '99':
return 'core'
default:
return 'core'
}
}
let helpers = {
toAscii,
addressesURL,
ABIURL,
getABI,
wrongRepoAlert,
getBranch
}
export default helpers

View File

@ -1,16 +1,20 @@
import KeysManagerAbi from './keysManagerAbi.json'
import Web3 from 'web3';
import addressGenerator from './addressGenerator';
import networkAddresses from './addresses'
import networkAddresses from './addresses';
import helpers from "./helpers";
export default class KeysManager {
constructor({web3, netId}){
let web3_10 = new Web3(web3.currentProvider);
async init({web3, netId}){
this.web3_10 = new Web3(web3.currentProvider);
const {KEYS_MANAGER_ADDRESS} = networkAddresses(netId);
console.log('Keys Manager ', KEYS_MANAGER_ADDRESS);
this.web3_10 = web3_10;
this.keysInstance = new web3_10.eth.Contract(KeysManagerAbi, KEYS_MANAGER_ADDRESS);
const branch = helpers.getBranch(netId);
let KeysManagerAbi = await helpers.getABI(branch, 'KeysManager')
this.keysInstance = new this.web3_10.eth.Contract(KeysManagerAbi, KEYS_MANAGER_ADDRESS);
}
async isInitialKeyValid(initialKey) {
return await this.keysInstance.methods.initialKeys(initialKey).call();
}

View File

@ -1,760 +0,0 @@
[
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "successfulValidatorClone",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_miningKey",
"type": "address"
}
],
"name": "removePayoutKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_miningKey",
"type": "address"
}
],
"name": "removeVotingKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_miningKey",
"type": "address"
}
],
"name": "getVotingByMining",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_votingKey",
"type": "address"
}
],
"name": "getMiningKeyByVoting",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "address"
}
],
"name": "addMiningKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "poaNetworkConsensus",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "miningKeyHistory",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getVotingToChangeKeys",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getTime",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "validatorKeys",
"outputs": [
{
"name": "votingKey",
"type": "address"
},
{
"name": "payoutKey",
"type": "address"
},
{
"name": "isMiningActive",
"type": "bool"
},
{
"name": "isVotingActive",
"type": "bool"
},
{
"name": "isPayoutActive",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "previousKeysManager",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_votingKey",
"type": "address"
}
],
"name": "isVotingActive",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "address"
},
{
"name": "_miningKey",
"type": "address"
}
],
"name": "addPayoutKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "initialKeys",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "address"
},
{
"name": "_miningKey",
"type": "address"
}
],
"name": "swapPayoutKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_miningKey",
"type": "address"
}
],
"name": "getPayoutByMining",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "address"
}
],
"name": "removeMiningKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "maxLimitValidators",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_miningKey",
"type": "address"
}
],
"name": "migrateMiningKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_initialKey",
"type": "address"
}
],
"name": "initiateKeys",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "address"
},
{
"name": "_miningKey",
"type": "address"
}
],
"name": "addVotingKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_initialKey",
"type": "address"
}
],
"name": "migrateInitialKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_key",
"type": "address"
}
],
"name": "isMiningActive",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "contractVersion",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_miningKey",
"type": "address"
}
],
"name": "getMiningKeyHistory",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "proxyStorage",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_initialKey",
"type": "address"
}
],
"name": "getInitialKey",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_miningKey",
"type": "address"
},
{
"name": "_votingKey",
"type": "address"
},
{
"name": "_payoutKey",
"type": "address"
}
],
"name": "createKeys",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "initialKeysCount",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "address"
},
{
"name": "_miningKey",
"type": "address"
}
],
"name": "swapVotingKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "address"
},
{
"name": "_oldMiningKey",
"type": "address"
}
],
"name": "swapMiningKey",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "maxNumberOfInitialKeys",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "miningKeyByVoting",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "masterOfCeremony",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_miningKey",
"type": "address"
}
],
"name": "isPayoutActive",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_proxyStorage",
"type": "address"
},
{
"name": "_poaConsensus",
"type": "address"
},
{
"name": "_masterOfCeremony",
"type": "address"
},
{
"name": "_previousKeysManager",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "key",
"type": "address"
},
{
"indexed": true,
"name": "miningKey",
"type": "address"
},
{
"indexed": false,
"name": "action",
"type": "string"
}
],
"name": "PayoutKeyChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "key",
"type": "address"
},
{
"indexed": true,
"name": "miningKey",
"type": "address"
},
{
"indexed": false,
"name": "action",
"type": "string"
}
],
"name": "VotingKeyChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "key",
"type": "address"
},
{
"indexed": false,
"name": "action",
"type": "string"
}
],
"name": "MiningKeyChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "miningKey",
"type": "address"
},
{
"indexed": true,
"name": "votingKey",
"type": "address"
},
{
"indexed": true,
"name": "payoutKey",
"type": "address"
}
],
"name": "ValidatorInitialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "initialKey",
"type": "address"
},
{
"indexed": false,
"name": "time",
"type": "uint256"
},
{
"indexed": false,
"name": "initialKeysCount",
"type": "uint256"
}
],
"name": "InitialKeyCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "name",
"type": "string"
},
{
"indexed": false,
"name": "key",
"type": "address"
}
],
"name": "Migrated",
"type": "event"
}
]

7
src/messages.js Normal file
View File

@ -0,0 +1,7 @@
let messages = {};
messages.wrongRepo = function(repo) {
return `There is no contracts.json in configured repo ${repo}`;
};
module.exports = {
messages
};