aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2019-01-12 08:13:52 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-01-15 02:49:44 +0800
commitb0817854e81512ad95cca4d842a671304ae3b94a (patch)
treea0061749b4877a6b020b3db2cec62a277d26d875 /packages/utils
parent1907ecc02edc8fb362485800b58946913387fa7d (diff)
downloaddexon-sol-tools-b0817854e81512ad95cca4d842a671304ae3b94a.tar
dexon-sol-tools-b0817854e81512ad95cca4d842a671304ae3b94a.tar.gz
dexon-sol-tools-b0817854e81512ad95cca4d842a671304ae3b94a.tar.bz2
dexon-sol-tools-b0817854e81512ad95cca4d842a671304ae3b94a.tar.lz
dexon-sol-tools-b0817854e81512ad95cca4d842a671304ae3b94a.tar.xz
dexon-sol-tools-b0817854e81512ad95cca4d842a671304ae3b94a.tar.zst
dexon-sol-tools-b0817854e81512ad95cca4d842a671304ae3b94a.zip
strict decoding of return values using generics
Diffstat (limited to 'packages/utils')
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/method.ts21
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 {