diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-12-20 06:30:23 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2019-01-15 02:49:44 +0800 |
commit | 7991de9ed0b5f1e8a38097d902eae09cc6b5cf11 (patch) | |
tree | 3aaaa01876f4639d0165f75b65c2e55f4e7b4368 /packages/utils/src/abi_encoder/evm_data_type_factory.ts | |
parent | e9a82905e35041d36c4c9be75e11c0399ee96b89 (diff) | |
download | dexon-0x-contracts-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar dexon-0x-contracts-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.gz dexon-0x-contracts-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.bz2 dexon-0x-contracts-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.lz dexon-0x-contracts-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.xz dexon-0x-contracts-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.zst dexon-0x-contracts-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.zip |
Generalized `create` for signature / dataItems. Cleaner.
Diffstat (limited to 'packages/utils/src/abi_encoder/evm_data_type_factory.ts')
-rw-r--r-- | packages/utils/src/abi_encoder/evm_data_type_factory.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/utils/src/abi_encoder/evm_data_type_factory.ts b/packages/utils/src/abi_encoder/evm_data_type_factory.ts index 4cc124e0a..5ff7366d6 100644 --- a/packages/utils/src/abi_encoder/evm_data_type_factory.ts +++ b/packages/utils/src/abi_encoder/evm_data_type_factory.ts @@ -2,6 +2,8 @@ import { DataItem, MethodAbi } from 'ethereum-types'; import * as _ from 'lodash'; +import { generateDataItemsFromSignature } from './utils/signatureParser'; + import { DataType } from './abstract_data_types/data_type'; import { DataTypeFactory } from './abstract_data_types/interfaces'; import { AddressDataType } from './evm_data_types/address'; @@ -129,4 +131,25 @@ export class EvmDataTypeFactory implements DataTypeFactory { private constructor() {} } + +// Convenience function +export function create(input: DataItem | DataItem[] | string): DataType { + // Handle different types of input + let dataItems: DataItem[] = []; + if (typeof(input) === 'string') { + dataItems = generateDataItemsFromSignature(input); + } else if(input instanceof Array) { + dataItems = input as DataItem[]; + } else { + dataItems = [input as DataItem]; + } + // Create single data item from input + let dataItem: DataItem = dataItems.length === 1 ? dataItems[0] : { + name: '', + type: 'tuple', + components: dataItems + }; + // Create data type + return EvmDataTypeFactory.getInstance().create(dataItem); +} /* tslint:enable no-construct */ |