diff options
Diffstat (limited to 'packages/utils')
-rw-r--r-- | packages/utils/src/abi_encoder/evm_data_types/method.ts | 21 |
1 files changed, 11 insertions, 10 deletions
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 c0cf80c74..c852a0fdf 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/method.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts @@ -44,16 +44,17 @@ export class MethodDataType extends AbstractSetDataType { return returnValues; } - public decodeReturnValuesAsArray(returnData: string, rules?: DecodingRules): any[] { - const returnValues = this.decodeReturnValues(returnData, rules); - const returnValuesAsArray = _.isObject(returnValues) ? _.values(returnValues) : [returnValues]; - return returnValuesAsArray; - } - - public decodeReturnValuesAsArrayOrNull(returnData: string, rules?: DecodingRules): any { - const returnValuesAsArray = this.decodeReturnValuesAsArray(returnData, rules); - const returnValue = _.isEmpty(returnValuesAsArray) ? [] : returnValuesAsArray; - return returnValue; + public strictDecodeReturnValue<T>(returndata: string, rules?: DecodingRules): T { + const returnValues = this._returnDataType.decode(returndata, rules); + const returnValuesAsArray: any = _.isObject(returnValues) ? _.values(returnValues) : [returnValues]; + switch (returnValuesAsArray.length) { + case 0: + return undefined as any; + case 1: + return returnValuesAsArray[0]; + default: + return returnValuesAsArray; + } } public getSignatureType(): string { |