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