diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2019-01-12 08:13:52 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2019-01-15 02:49:44 +0800 |
commit | b0817854e81512ad95cca4d842a671304ae3b94a (patch) | |
tree | a0061749b4877a6b020b3db2cec62a277d26d875 /packages/utils/src/abi_encoder | |
parent | 1907ecc02edc8fb362485800b58946913387fa7d (diff) | |
download | dexon-0x-contracts-b0817854e81512ad95cca4d842a671304ae3b94a.tar dexon-0x-contracts-b0817854e81512ad95cca4d842a671304ae3b94a.tar.gz dexon-0x-contracts-b0817854e81512ad95cca4d842a671304ae3b94a.tar.bz2 dexon-0x-contracts-b0817854e81512ad95cca4d842a671304ae3b94a.tar.lz dexon-0x-contracts-b0817854e81512ad95cca4d842a671304ae3b94a.tar.xz dexon-0x-contracts-b0817854e81512ad95cca4d842a671304ae3b94a.tar.zst dexon-0x-contracts-b0817854e81512ad95cca4d842a671304ae3b94a.zip |
strict decoding of return values using generics
Diffstat (limited to 'packages/utils/src/abi_encoder')
-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 { |