/* * This file is auto-generated using abi-gen. Any changes will be reverted */ // Needed for the promisifed events, some contracts don't have events // tslint:disable:no-unused-variable import { DecodedLogEntryEvent, DecodedLogEntry, DecodedTransactionReceipt } from "@joincivil/typescript-types"; // tslint:enable:no-unused-variable import "rxjs/add/operator/distinctUntilChanged"; import {Contract} from "web3-eth-contract"; import {TransactionConfig, TransactionConfig as SendOptions} from "web3-core"; import { bindNestedAll, isDefined, CivilErrors } from "@joincivil/utils"; import * as Debug from "debug"; import { EthAddress, TxHash } from "@joincivil/typescript-types"; import { streamifyEvent } from "../../../contracts/utils/contracts"; import { EthApi, currentNetwork } from "@joincivil/ethapi"; import { BaseContract } from "../../basecontract"; import { artifacts } from "../artifacts"; // hack(dankins): abi-gen things these are bignumber.js, but they are actually returned as strings // https://github.com/0xProject/0x-monorepo/blob/development/packages/abi-gen/src/utils.ts#L64 type BigNumber = string; const debug = Debug("civil:contracts:GovernmentContract"); export class GovernmentContract extends BaseContract { // tslint:disable:member-ordering public static async singletonTrusted(ethApi: EthApi): Promise { if (!artifacts.Government.networks) { debug("Trying to get singleton from contract without any singleton data"); return undefined; } const networkId = (await currentNetwork(ethApi)).toString(); const networkData = artifacts.Government.networks[networkId]; if (!networkData) { debug("Failed to find network data for network ID " + networkId + ". Supported networks: " + Object.keys(artifacts.Government.networks)); return undefined; } return GovernmentContract.atUntrusted(ethApi, networkData.address); } public static atUntrusted(ethApi: EthApi, address: EthAddress): GovernmentContract { const contract = ethApi.getContractClass(artifacts.Government.abi, address); return new GovernmentContract(contract, ethApi); } // TODO(ritave): This code won't work with smart-contracts with library links // see [ch429] in Clubhouse public static deployTrusted = { async sendTransactionAsync( ethApi: EthApi, appellateAddr: string, governmentControllerAddr: string, plcrAddr: string, appealFeeAmount: BigNumber, requestAppealLength: BigNumber, judgeAppealLength: BigNumber, appealSupermajorityPercentage: BigNumber, appealChallengeVoteDispensationPct: BigNumber, pDeposit: BigNumber, pCommitStageLength: BigNumber, pRevealStageLength: BigNumber, constHash: string, constURI: string, options: SendOptions): Promise { if (!options.gas) { options.gas = await GovernmentContract.deployTrusted .estimateGasAsync( ethApi, appellateAddr, governmentControllerAddr, plcrAddr, appealFeeAmount, requestAppealLength, judgeAppealLength, appealSupermajorityPercentage, appealChallengeVoteDispensationPct, pDeposit, pCommitStageLength, pRevealStageLength, constHash, constURI, ); } if (!options.gasPrice) { options.gasPrice = (await ethApi.getGasPrice()).toString(); } const clazz = ethApi.getContractClass(artifacts.Government.abi); return new Promise( (resolve, reject) => { /* There's a bug in Metamask, this callback should be called twice, first when the transaction * gets into mempool, and second when it's mined. But it's called only once, so we have to resolve * the contract on our own */ const tx = clazz.deploy({data: artifacts.Government.bytecode, arguments: [appellateAddr, governmentControllerAddr, plcrAddr, appealFeeAmount, requestAppealLength, judgeAppealLength, appealSupermajorityPercentage, appealChallengeVoteDispensationPct, pDeposit, pCommitStageLength, pRevealStageLength, constHash, constURI, ]}).send(options); return tx.once("transactionHash", resolve) }) }, async estimateGasAsync( ethApi: EthApi, appellateAddr: string, governmentControllerAddr: string, plcrAddr: string, appealFeeAmount: BigNumber, requestAppealLength: BigNumber, judgeAppealLength: BigNumber, appealSupermajorityPercentage: BigNumber, appealChallengeVoteDispensationPct: BigNumber, pDeposit: BigNumber, pCommitStageLength: BigNumber, pRevealStageLength: BigNumber, constHash: string, constURI: string, ): Promise { const clazz = ethApi.getContractClass(artifacts.Government.abi); const contractData = clazz.deploy({ data: artifacts.Government.bytecode, arguments: [appellateAddr, governmentControllerAddr, plcrAddr, appealFeeAmount, requestAppealLength, judgeAppealLength, appealSupermajorityPercentage, appealChallengeVoteDispensationPct, pDeposit, pCommitStageLength, pRevealStageLength, constHash, constURI, ] }).encodeABI(); return ethApi.estimateGas({data: contractData}); }, }; // tslint:disable:variable-name public PROCESSBY = { async callAsync( ): Promise { const self = this as GovernmentContract; return self.instance.methods.PROCESSBY().call(); } } public proposals = { async callAsync( index_0: string, ): Promise< [BigNumber, string, BigNumber, BigNumber]> { const self = this as GovernmentContract; return self.instance.methods.proposals(index_0, ).call(); } } public constitutionURI = { async callAsync( ): Promise { const self = this as GovernmentContract; return self.instance.methods.constitutionURI().call(); } } public constitutionHash = { async callAsync( ): Promise { const self = this as GovernmentContract; return self.instance.methods.constitutionHash().call(); } } public appellate = { async callAsync( ): Promise { const self = this as GovernmentContract; return self.instance.methods.appellate().call(); } } public params = { async callAsync( index_0: string, ): Promise { const self = this as GovernmentContract; return self.instance.methods.params(index_0, ).call(); } } public governmentController = { async callAsync( ): Promise { const self = this as GovernmentContract; return self.instance.methods.governmentController().call(); } } public voting = { async callAsync( ): Promise { const self = this as GovernmentContract; return self.instance.methods.voting().call(); } } public getAppellate = { async callAsync( ): Promise { const self = this as GovernmentContract; return self.instance.methods.getAppellate().call(); } } public getGovernmentController = { async callAsync( ): Promise { const self = this as GovernmentContract; return self.instance.methods.getGovernmentController().call(); } } public get = { async callAsync( name: string, ): Promise { const self = this as GovernmentContract; return self.instance.methods.get(name, ).call(); } } public proposeReparameterization = { async sendTransactionAsync( _name: string, _value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`proposeReparameterization(_name: string, _value: BigNumber, )`); debug("proposeReparameterization: txOptions:", txOptions); debug("proposeReparameterization: Sending with:", _name, _value, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.proposeReparameterization(_name, _value, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("proposeReparameterization: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _name: string, _value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const estimateGas = self.instance.methods.proposeReparameterization(_name, _value, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("proposeReparameterization: Gas estimation:", estimate); return estimate; } catch (e) { debug("proposeReparameterization: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _name: string, _value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.proposeReparameterization.estimateGasAsync( _name, _value, options, ); } options.data = self.instance.methods.proposeReparameterization(_name, _value, ).encodeABI(); return options; }, }; public setNewConstitution = { async sendTransactionAsync( _newConstHash: string, _newConstURI: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`setNewConstitution(_newConstHash: string, _newConstURI: string, )`); debug("setNewConstitution: txOptions:", txOptions); debug("setNewConstitution: Sending with:", _newConstHash, _newConstURI, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.setNewConstitution(_newConstHash, _newConstURI, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("setNewConstitution: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _newConstHash: string, _newConstURI: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const estimateGas = self.instance.methods.setNewConstitution(_newConstHash, _newConstURI, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("setNewConstitution: Gas estimation:", estimate); return estimate; } catch (e) { debug("setNewConstitution: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _newConstHash: string, _newConstURI: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.setNewConstitution.estimateGasAsync( _newConstHash, _newConstURI, options, ); } options.data = self.instance.methods.setNewConstitution(_newConstHash, _newConstURI, ).encodeABI(); return options; }, }; public processProposal = { async sendTransactionAsync( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`processProposal(_propID: string, )`); debug("processProposal: txOptions:", txOptions); debug("processProposal: Sending with:", _propID, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.processProposal(_propID, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("processProposal: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const estimateGas = self.instance.methods.processProposal(_propID, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("processProposal: Gas estimation:", estimate); return estimate; } catch (e) { debug("processProposal: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.processProposal.estimateGasAsync( _propID, options, ); } options.data = self.instance.methods.processProposal(_propID, ).encodeABI(); return options; }, }; public propExists = { async callAsync( _propID: string, ): Promise { const self = this as GovernmentContract; return self.instance.methods.propExists(_propID, ).call(); } } public propCanBeResolved = { async callAsync( _propID: string, ): Promise { const self = this as GovernmentContract; return self.instance.methods.propCanBeResolved(_propID, ).call(); } } public setAppellate = { async sendTransactionAsync( newAppellate: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`setAppellate(newAppellate: string, )`); debug("setAppellate: txOptions:", txOptions); debug("setAppellate: Sending with:", newAppellate, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.setAppellate(newAppellate, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("setAppellate: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( newAppellate: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const estimateGas = self.instance.methods.setAppellate(newAppellate, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("setAppellate: Gas estimation:", estimate); return estimate; } catch (e) { debug("setAppellate: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( newAppellate: string, txData?: TransactionConfig, ): Promise { const self = this as GovernmentContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.setAppellate.estimateGasAsync( newAppellate, options, ); } options.data = self.instance.methods.setAppellate(newAppellate, ).encodeABI(); return options; }, }; public _AppellateSetStream = streamifyEvent (this.instance, "_AppellateSet"); public _ParameterSetStream = streamifyEvent (this.instance, "_ParameterSet"); public _GovtReparameterizationProposalStream = streamifyEvent (this.instance, "_GovtReparameterizationProposal"); public _ProposalPassedStream = streamifyEvent (this.instance, "_ProposalPassed"); public _ProposalExpiredStream = streamifyEvent (this.instance, "_ProposalExpired"); public _ProposalFailedStream = streamifyEvent (this.instance, "_ProposalFailed"); public _NewConstSetStream = streamifyEvent (this.instance, "_NewConstSet"); // tslint:enable:variable-name private constructor(instance: Contract, ethApi: EthApi) { super(instance, ethApi); // Call methods access this instance while being in a sub-object, we're rebinding what // "this" means for everything in this class, this also requires "noImplicitThis" to be false bindNestedAll(this, ["constructor", "instance", "defaults", "ethApi"]); } // tslint:enable:member-ordering } // tslint:disable:no-namespace export namespace Government { export enum Events { _AppellateSet = "_AppellateSet", _ParameterSet = "_ParameterSet", _GovtReparameterizationProposal = "_GovtReparameterizationProposal", _ProposalPassed = "_ProposalPassed", _ProposalExpired = "_ProposalExpired", _ProposalFailed = "_ProposalFailed", _NewConstSet = "_NewConstSet", } // tslint:disable:class-name export namespace Args { export interface _AppellateSet { newAppellate: string; } export interface _ParameterSet { name: string; value: BigNumber; } export interface _GovtReparameterizationProposal { name: string; value: BigNumber; propID: string; pollID: BigNumber; } export interface _ProposalPassed { propId: string; pollID: BigNumber; } export interface _ProposalExpired { propId: string; pollID: BigNumber; } export interface _ProposalFailed { propId: string; pollID: BigNumber; } export interface _NewConstSet { proposedHash: string; proposedURI: string; } } // tslint:enable:class-name export namespace Logs { export type _AppellateSet = DecodedLogEntry; export type _ParameterSet = DecodedLogEntry; export type _GovtReparameterizationProposal = DecodedLogEntry; export type _ProposalPassed = DecodedLogEntry; export type _ProposalExpired = DecodedLogEntry; export type _ProposalFailed = DecodedLogEntry; export type _NewConstSet = DecodedLogEntry; export type All = Logs._AppellateSet | Logs._ParameterSet | Logs._GovtReparameterizationProposal | Logs._ProposalPassed | Logs._ProposalExpired | Logs._ProposalFailed | Logs._NewConstSet; } export namespace LogEvents { export type _AppellateSet = DecodedLogEntryEvent; export type _ParameterSet = DecodedLogEntryEvent; export type _GovtReparameterizationProposal = DecodedLogEntryEvent; export type _ProposalPassed = DecodedLogEntryEvent; export type _ProposalExpired = DecodedLogEntryEvent; export type _ProposalFailed = DecodedLogEntryEvent; export type _NewConstSet = DecodedLogEntryEvent; export type All = LogEvents._AppellateSet | LogEvents._ParameterSet | LogEvents._GovtReparameterizationProposal | LogEvents._ProposalPassed | LogEvents._ProposalExpired | LogEvents._ProposalFailed | LogEvents._NewConstSet; } export type Receipt = DecodedTransactionReceipt; export type EventReceipt = DecodedTransactionReceipt; } // tslint:enable:no-namespace