/* * 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:EventStorageContract"); export class EventStorageContract extends BaseContract { // tslint:disable:member-ordering public static async singletonTrusted(ethApi: EthApi): Promise { if (!artifacts.EventStorage.networks) { debug("Trying to get singleton from contract without any singleton data"); return undefined; } const networkId = (await currentNetwork(ethApi)).toString(); const networkData = artifacts.EventStorage.networks[networkId]; if (!networkData) { debug("Failed to find network data for network ID " + networkId + ". Supported networks: " + Object.keys(artifacts.EventStorage.networks)); return undefined; } return EventStorageContract.atUntrusted(ethApi, networkData.address); } public static atUntrusted(ethApi: EthApi, address: EthAddress): EventStorageContract { const contract = ethApi.getContractClass(artifacts.EventStorage.abi, address); return new EventStorageContract(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, options: SendOptions): Promise { if (!options.gas) { options.gas = await EventStorageContract.deployTrusted .estimateGasAsync( ethApi, ); } if (!options.gasPrice) { options.gasPrice = (await ethApi.getGasPrice()).toString(); } const clazz = ethApi.getContractClass(artifacts.EventStorage.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.EventStorage.bytecode, arguments: []}).send(options); return tx.once("transactionHash", resolve) }) }, async estimateGasAsync( ethApi: EthApi, ): Promise { const clazz = ethApi.getContractClass(artifacts.EventStorage.abi); const contractData = clazz.deploy({ data: artifacts.EventStorage.bytecode, arguments: [] }).encodeABI(); return ethApi.estimateGas({data: contractData}); }, }; // tslint:disable:variable-name public store = { async sendTransactionAsync( data: string, txData?: TransactionConfig, ): Promise { const self = this as EventStorageContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`store(data: string, )`); debug("store: txOptions:", txOptions); debug("store: Sending with:", data, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.store(data, ).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("store: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( data: string, txData?: TransactionConfig, ): Promise { const self = this as EventStorageContract; const estimateGas = self.instance.methods.store(data, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("store: Gas estimation:", estimate); return estimate; } catch (e) { debug("store: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( data: string, txData?: TransactionConfig, ): Promise { const self = this as EventStorageContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.store.estimateGasAsync( data, options, ); } options.data = self.instance.methods.store(data, ).encodeABI(); return options; }, }; public StringStoredStream = streamifyEvent (this.instance, "StringStored"); // 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 EventStorage { export enum Events { StringStored = "StringStored", } // tslint:disable:class-name export namespace Args { export interface StringStored { dataHash: string; data: string; } } // tslint:enable:class-name export namespace Logs { export type StringStored = DecodedLogEntry; export type All = Logs.StringStored; } export namespace LogEvents { export type StringStored = DecodedLogEntryEvent; export type All = LogEvents.StringStored; } export type Receipt = DecodedTransactionReceipt; export type EventReceipt = DecodedTransactionReceipt; } // tslint:enable:no-namespace