diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-08 04:11:09 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-10 23:46:57 +0800 |
commit | 3d58b38e4e8565e7ee10e4d6c9f57cd745957ab4 (patch) | |
tree | 5cff4a892b4094b972b59f119cb2998088fcea76 /packages/base-contract/src/index.ts | |
parent | c64ad1af28ef116e210aafb3ea6ad2138361cd7c (diff) | |
download | dexon-0x-contracts-3d58b38e4e8565e7ee10e4d6c9f57cd745957ab4.tar.gz dexon-0x-contracts-3d58b38e4e8565e7ee10e4d6c9f57cd745957ab4.tar.zst dexon-0x-contracts-3d58b38e4e8565e7ee10e4d6c9f57cd745957ab4.zip |
Remove deployer from metacoin and contract tests
Diffstat (limited to 'packages/base-contract/src/index.ts')
-rw-r--r-- | packages/base-contract/src/index.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index e95b18db6..c362a882b 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -1,6 +1,7 @@ import { AbiDefinition, AbiType, + ConstructorAbi, ContractAbi, DataItem, MethodAbi, @@ -37,9 +38,40 @@ export class BaseContract { protected static _bigNumberToString(type: string, value: any): any { return _.isObject(value) && value.isBigNumber ? value.toString() : value; } + protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi { + const constructorAbiIfExists = _.find( + abi, + (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Constructor, + ) as ConstructorAbi | undefined; + if (!_.isUndefined(constructorAbiIfExists)) { + return constructorAbiIfExists; + } else { + return { + type: AbiType.Constructor, + stateMutability: 'nonpayable', + payable: false, + inputs: [], + }; + } + } protected static _bnToBigNumber(type: string, value: any): any { return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value; } + protected static async _applyDefaultsToDeployTxDataAsync<T extends Partial<TxData | TxDataPayable>>( + txData: T, + defaults: Partial<TxData>, + estimateGasAsync?: (txData: T) => Promise<number>, + ): Promise<TxData> { + const txDataWithDefaults: TxData = { + ...defaults, + ...(txData as any), + }; + if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { + const estimatedGas = await estimateGasAsync(txData); + txDataWithDefaults.gas = estimatedGas; + } + return txDataWithDefaults; + } protected async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>( txData: T, estimateGasAsync?: (txData: T) => Promise<number>, |