aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base-contract/src/index.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-04-02 19:57:44 +0800
committerGitHub <noreply@github.com>2018-04-02 19:57:44 +0800
commitd95b1e2db499d0264a1020be1ec453c5136b5a3b (patch)
treeb26623424303ff4d5ba17080b53ef40d037a1426 /packages/base-contract/src/index.ts
parent695b697cdf6c73bb4b5f920869ce128f9a9e7523 (diff)
parentc1d6c7ff66079731df405e25c4b2aa83c86fffb9 (diff)
downloaddexon-sol-tools-d95b1e2db499d0264a1020be1ec453c5136b5a3b.tar
dexon-sol-tools-d95b1e2db499d0264a1020be1ec453c5136b5a3b.tar.gz
dexon-sol-tools-d95b1e2db499d0264a1020be1ec453c5136b5a3b.tar.bz2
dexon-sol-tools-d95b1e2db499d0264a1020be1ec453c5136b5a3b.tar.lz
dexon-sol-tools-d95b1e2db499d0264a1020be1ec453c5136b5a3b.tar.xz
dexon-sol-tools-d95b1e2db499d0264a1020be1ec453c5136b5a3b.tar.zst
dexon-sol-tools-d95b1e2db499d0264a1020be1ec453c5136b5a3b.zip
Merge pull request #485 from 0xProject/feature/metacoin
Add metacoin example project
Diffstat (limited to 'packages/base-contract/src/index.ts')
-rw-r--r--packages/base-contract/src/index.ts29
1 files changed, 10 insertions, 19 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts
index 961da8842..c8cbd7886 100644
--- a/packages/base-contract/src/index.ts
+++ b/packages/base-contract/src/index.ts
@@ -1,40 +1,31 @@
import { ContractAbi, DataItem, TxData, TxDataPayable } from '@0xproject/types';
+import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as ethersContracts from 'ethers-contracts';
import * as _ from 'lodash';
+import { formatABIDataItem } from './utils';
+
export class BaseContract {
protected _ethersInterface: ethersContracts.Interface;
protected _web3Wrapper: Web3Wrapper;
public abi: ContractAbi;
public address: string;
- protected static _transformABIData(
+ protected static _formatABIDataItemList(
abis: DataItem[],
values: any[],
- transformation: (type: string, value: any) => any,
+ formatter: (type: string, value: any) => any,
): any {
- return _.map(values, (value: any, i: number) =>
- BaseContract._transformTypedData(abis[i].type, value, transformation),
- );
+ return _.map(values, (value: any, i: number) => formatABIDataItem(abis[i], value, formatter));
}
protected static _lowercaseAddress(type: string, value: string): string {
return type === 'address' ? value.toLowerCase() : value;
}
- protected static _bigNumberToString(type: string, value: string): string {
- return _.isObject(value) && (value as any).isBigNumber ? value.toString() : value;
+ protected static _bigNumberToString(type: string, value: any): any {
+ return _.isObject(value) && value.isBigNumber ? value.toString() : value;
}
- private static _transformTypedData(
- type: string,
- values: any,
- transformation: (type: string, value: any) => any,
- ): any {
- const trailingArrayRegex = /\[\d*\]$/;
- if (type.match(trailingArrayRegex)) {
- const arrayItemType = type.replace(trailingArrayRegex, '');
- return _.map(values, value => this._transformTypedData(arrayItemType, value, transformation));
- } else {
- return transformation(type, values);
- }
+ protected static _bnToBigNumber(type: string, value: any): any {
+ return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value;
}
protected async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
txData: T,