(Update) Backward compatibility with old smart contracts
This commit is contained in:
parent
b5b2452e91
commit
b2920ed578
|
@ -2,11 +2,26 @@ import React from 'react';
|
|||
import { inject, observer } from "mobx-react";
|
||||
import Select from 'react-select';
|
||||
|
||||
@inject("ballotStore")
|
||||
@inject("ballotStore", "contractsStore")
|
||||
@observer
|
||||
export class BallotProxyMetadata extends React.Component {
|
||||
render() {
|
||||
const { ballotStore } = this.props;
|
||||
const { ballotStore, contractsStore } = this.props;
|
||||
let options = [
|
||||
/*0*/ { value: '', label: '' },
|
||||
/*1*/ { value: '1', label: ballotStore.ProxyBallotType[1] }, // KeysManager
|
||||
/*2*/ { value: '2', label: ballotStore.ProxyBallotType[2] }, // VotingToChangeKeys
|
||||
/*3*/ { value: '3', label: ballotStore.ProxyBallotType[3] }, // VotingToChangeMinThreshold
|
||||
/*4*/ { value: '4', label: ballotStore.ProxyBallotType[4] }, // VotingToChangeProxy
|
||||
/*5*/ { value: '5', label: ballotStore.ProxyBallotType[5] }, // BallotsStorage
|
||||
/*6*/ { value: '7', label: ballotStore.ProxyBallotType[7] }, // ValidatorMetadata
|
||||
/*7*/ { value: '8', label: ballotStore.ProxyBallotType[8] }, // ProxyStorage
|
||||
];
|
||||
|
||||
if (!contractsStore.proxyStorage.doesMethodExist('getValidatorMetadata')) {
|
||||
options.splice(6); // keep 0-5 and remove 6-... items if ProxyStorage is old
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
|
@ -24,20 +39,11 @@ export class BallotProxyMetadata extends React.Component {
|
|||
</div>
|
||||
<div className="right">
|
||||
<div className="form-el">
|
||||
<label htmlFor="us-state">Contract Type</label>
|
||||
<Select id="us-state"
|
||||
<label htmlFor="contract-type">Contract Type</label>
|
||||
<Select id="contract-type"
|
||||
value={ballotStore.ballotProxy.contractType}
|
||||
onChange={e => ballotStore.changeBallotMetadata(e, "contractType", "ballotProxy")}
|
||||
options={[
|
||||
{ value: '', label: '' },
|
||||
{ value: '1', label: ballotStore.ProxyBallotType[1] },
|
||||
{ value: '2', label: ballotStore.ProxyBallotType[2] },
|
||||
{ value: '3', label: ballotStore.ProxyBallotType[3] },
|
||||
{ value: '4', label: ballotStore.ProxyBallotType[4] },
|
||||
{ value: '5', label: ballotStore.ProxyBallotType[5] },
|
||||
{ value: '7', label: ballotStore.ProxyBallotType[7] },
|
||||
{ value: '8', label: ballotStore.ProxyBallotType[8] },
|
||||
]}
|
||||
options={options}
|
||||
>
|
||||
</Select>
|
||||
<p className="hint">
|
||||
|
|
|
@ -6,6 +6,7 @@ constants.ABIsSources = {
|
|||
'KeysManager': 'KeysManager.abi.json',
|
||||
'PoaNetworkConsensus': 'PoaNetworkConsensus.abi.json',
|
||||
'BallotStorage': 'BallotsStorage.abi.json',
|
||||
'ProxyStorage': 'ProxyStorage.abi.json',
|
||||
'ValidatorMetadata': 'ValidatorMetadata.abi.json',
|
||||
'VotingToChangeKeys': 'VotingToChangeKeys.abi.json',
|
||||
'VotingToChangeMinThreshold': 'VotingToChangeMinThreshold.abi.json',
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import Web3 from 'web3';
|
||||
import { networkAddresses } from './addresses';
|
||||
import helpers from "./helpers";
|
||||
|
||||
export default class ProxyStorage {
|
||||
async init({web3, netId}){
|
||||
const {PROXY_ADDRESS} = networkAddresses(netId);
|
||||
console.log('Proxy Storage address', PROXY_ADDRESS);
|
||||
let web3_10 = new Web3(web3.currentProvider);
|
||||
const branch = helpers.getBranch(netId);
|
||||
|
||||
let proxyStorageAbi = await helpers.getABI(branch, 'ProxyStorage')
|
||||
|
||||
this.proxyStorageInstance = new web3_10.eth.Contract(proxyStorageAbi, PROXY_ADDRESS);
|
||||
}
|
||||
|
||||
doesMethodExist(methodName) {
|
||||
return this.proxyStorageInstance && this.proxyStorageInstance.methods[methodName];
|
||||
}
|
||||
}
|
|
@ -18,7 +18,13 @@ export default class VotingToChangeKeys {
|
|||
|
||||
//setters
|
||||
createBallot({startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, sender, memo}) {
|
||||
return this.votingToChangeKeysInstance.methods.createBallot(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo).send({from: sender, gasPrice: this.gasPrice});
|
||||
let method;
|
||||
if (this.votingToChangeKeysInstance.methods.createBallot) {
|
||||
method = this.votingToChangeKeysInstance.methods.createBallot;
|
||||
} else {
|
||||
method = this.votingToChangeKeysInstance.methods.createVotingForKeys;
|
||||
}
|
||||
return method(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo).send({from: sender, gasPrice: this.gasPrice});
|
||||
}
|
||||
|
||||
createBallotToAddNewValidator({startTime, endTime, affectedKey, newVotingKey, newPayoutKey, sender, memo}) {
|
||||
|
|
|
@ -18,7 +18,13 @@ export default class VotingToChangeMinThreshold {
|
|||
|
||||
//setters
|
||||
createBallot({startTime, endTime, proposedValue, sender, memo}) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.createBallot(startTime, endTime, proposedValue, memo).send({from: sender, gasPrice: this.gasPrice})
|
||||
let method;
|
||||
if (this.votingToChangeMinThresholdInstance.methods.createBallot) {
|
||||
method = this.votingToChangeMinThresholdInstance.methods.createBallot;
|
||||
} else {
|
||||
method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold;
|
||||
}
|
||||
return method(startTime, endTime, proposedValue, memo).send({from: sender, gasPrice: this.gasPrice})
|
||||
}
|
||||
|
||||
vote(_id, choice, sender) {
|
||||
|
|
|
@ -18,7 +18,13 @@ export default class VotingToChangeProxy {
|
|||
|
||||
//setters
|
||||
createBallot({startTime, endTime, proposedValue, contractType, sender, memo}) {
|
||||
return this.votingToChangeProxyInstance.methods.createBallot(startTime, endTime, proposedValue, contractType, memo).send({from: sender, gasPrice: this.gasPrice})
|
||||
let method;
|
||||
if (this.votingToChangeProxyInstance.methods.createBallot) {
|
||||
method = this.votingToChangeProxyInstance.methods.createBallot;
|
||||
} else {
|
||||
method = this.votingToChangeProxyInstance.methods.createBallotToChangeProxyAddress;
|
||||
}
|
||||
return method(startTime, endTime, proposedValue, contractType, memo).send({from: sender, gasPrice: this.gasPrice})
|
||||
}
|
||||
|
||||
vote(_id, choice, sender) {
|
||||
|
|
11
src/index.js
11
src/index.js
|
@ -41,12 +41,21 @@ class AppMainRouter extends Component {
|
|||
|
||||
let setPoaConsensus = contractsStore.setPoaConsensus(web3Config);
|
||||
let setBallotsStorage = contractsStore.setBallotsStorage(web3Config);
|
||||
let setProxyStorage = contractsStore.setProxyStorage(web3Config);
|
||||
let setVotingToChangeKeys = contractsStore.setVotingToChangeKeys(web3Config);
|
||||
let setVotingToChangeMinThreshold = contractsStore.setVotingToChangeMinThreshold(web3Config);
|
||||
let setVotingToChangeProxy = contractsStore.setVotingToChangeProxy(web3Config);
|
||||
let setValidatorMetadata = contractsStore.setValidatorMetadata(web3Config);
|
||||
|
||||
await Promise.all([setPoaConsensus, setBallotsStorage, setVotingToChangeKeys, setVotingToChangeMinThreshold, setVotingToChangeProxy, setValidatorMetadata])
|
||||
await Promise.all([
|
||||
setPoaConsensus,
|
||||
setBallotsStorage,
|
||||
setProxyStorage,
|
||||
setVotingToChangeKeys,
|
||||
setVotingToChangeMinThreshold,
|
||||
setVotingToChangeProxy,
|
||||
setValidatorMetadata
|
||||
]);
|
||||
|
||||
await contractsStore.setMiningKey(web3Config);
|
||||
await contractsStore.setVotingKey(web3Config);
|
||||
|
|
|
@ -3,6 +3,7 @@ import React from 'react';
|
|||
|
||||
import PoaConsensus from '../contracts/PoaConsensus.contract'
|
||||
import BallotsStorage from '../contracts/BallotsStorage.contract'
|
||||
import ProxyStorage from '../contracts/ProxyStorage.contract'
|
||||
import VotingToChangeKeys from '../contracts/VotingToChangeKeys.contract'
|
||||
import VotingToChangeMinThreshold from '../contracts/VotingToChangeMinThreshold.contract'
|
||||
import VotingToChangeProxy from '../contracts/VotingToChangeProxy.contract'
|
||||
|
@ -20,6 +21,7 @@ import "babel-polyfill";
|
|||
class ContractsStore {
|
||||
@observable poaConsensus;
|
||||
@observable ballotsStorage;
|
||||
@observable proxyStorage;
|
||||
@observable votingToChangeKeys;
|
||||
@observable votingToChangeMinThreshold;
|
||||
@observable votingToChangeProxy;
|
||||
|
@ -85,6 +87,15 @@ class ContractsStore {
|
|||
});
|
||||
}
|
||||
|
||||
@action("Set ProxyStorage contract")
|
||||
setProxyStorage = async (web3Config) => {
|
||||
this.proxyStorage = new ProxyStorage();
|
||||
await this.proxyStorage.init({
|
||||
web3: web3Config.web3Instance,
|
||||
netId: web3Config.netId
|
||||
});
|
||||
}
|
||||
|
||||
@action("Set VotingToChangeKeys contract")
|
||||
setVotingToChangeKeys = async (web3Config) => {
|
||||
this.votingToChangeKeys = new VotingToChangeKeys();
|
||||
|
|
Loading…
Reference in New Issue