diff options
Diffstat (limited to 'packages/utils')
4 files changed, 22 insertions, 20 deletions
diff --git a/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts b/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts index 5bd6aae03..dc897d810 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts @@ -51,6 +51,12 @@ export abstract class DataType { return value; } + public decodeAsArray(returndata: string, rules?: DecodingRules): any { + const value = this.decode(returndata, rules); + const valuesAsArray = _.isObject(value) ? _.values(value) : [value]; + return valuesAsArray; + } + public getSignature(detailed?: boolean): string { if (_.isEmpty(this._dataItem.name) || !detailed) return this.getSignatureType(); const name = this.getDataItem().name; 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 5ff7366d6..fdd4f0fde 100644 --- a/packages/utils/src/abi_encoder/evm_data_type_factory.ts +++ b/packages/utils/src/abi_encoder/evm_data_type_factory.ts @@ -135,21 +135,23 @@ export class EvmDataTypeFactory implements DataTypeFactory { // 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[]; + const isSignature = typeof(input) === 'string'; + const isTupleSignature = isSignature && (input as string).startsWith('('); + const parseAsTuple = isTupleSignature || _.isArray(input); + // Create input `dataItem` + let dataItem: DataItem; + if(parseAsTuple) { + const dataItems = isSignature ? generateDataItemsFromSignature(input as string) : input as DataItem[]; + dataItem = { + name: '', + type: 'tuple', + components: dataItems + }; } else { - dataItems = [input as DataItem]; + dataItem = isSignature ? generateDataItemsFromSignature(input as string)[0] : 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); + const dataType = EvmDataTypeFactory.getInstance().create(dataItem); + return dataType; } /* tslint:enable no-construct */ diff --git a/packages/utils/src/abi_encoder/evm_data_types/method.ts b/packages/utils/src/abi_encoder/evm_data_types/method.ts index 212e2ca6b..44456cd0a 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/method.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts @@ -35,12 +35,6 @@ export class MethodDataType extends AbstractSetDataType { return value; } - public decodeAsArray(returndata: string, rules?: DecodingRules): any { - const value = this.decode(returndata, rules); - const valuesAsArray = _.isObject(value) ? _.values(value) : [value]; - return valuesAsArray; - } - public encodeReturnValues(value: any, rules?: EncodingRules): string { const returnData = this._returnDataType.encode(value, rules); return returnData; diff --git a/packages/utils/src/abi_encoder/index.ts b/packages/utils/src/abi_encoder/index.ts index f7f1ceedc..cfacfe075 100644 --- a/packages/utils/src/abi_encoder/index.ts +++ b/packages/utils/src/abi_encoder/index.ts @@ -13,4 +13,4 @@ export { UInt, create, } from './evm_data_type_factory'; -//export { fromSignature } from './utils/signatureParser'; +export { DataType } from './abstract_data_types/data_type'; |