diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-04-02 19:57:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 19:57:44 +0800 |
commit | d95b1e2db499d0264a1020be1ec453c5136b5a3b (patch) | |
tree | b26623424303ff4d5ba17080b53ef40d037a1426 /packages/base-contract/src/utils.ts | |
parent | 695b697cdf6c73bb4b5f920869ce128f9a9e7523 (diff) | |
parent | c1d6c7ff66079731df405e25c4b2aa83c86fffb9 (diff) | |
download | dexon-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/utils.ts')
-rw-r--r-- | packages/base-contract/src/utils.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/base-contract/src/utils.ts b/packages/base-contract/src/utils.ts new file mode 100644 index 000000000..4b86bb1ad --- /dev/null +++ b/packages/base-contract/src/utils.ts @@ -0,0 +1,25 @@ +import { DataItem } from '@0xproject/types'; +import * as _ from 'lodash'; + +// tslint:disable-next-line:completed-docs +export function formatABIDataItem(abi: DataItem, value: any, formatter: (type: string, value: any) => any): any { + const trailingArrayRegex = /\[\d*\]$/; + if (abi.type.match(trailingArrayRegex)) { + const arrayItemType = abi.type.replace(trailingArrayRegex, ''); + return _.map(value, val => { + const arrayItemAbi = { + ...abi, + type: arrayItemType, + }; + return formatABIDataItem(arrayItemAbi, val, formatter); + }); + } else if (abi.type === 'tuple') { + const formattedTuple: { [componentName: string]: DataItem } = {}; + _.forEach(abi.components, componentABI => { + formattedTuple[componentABI.name] = formatABIDataItem(componentABI, value[componentABI.name], formatter); + }); + return formattedTuple; + } else { + return formatter(abi.type, value); + } +} |