diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-26 07:50:49 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:11 +0800 |
commit | 173fc1dcefa266704dd80de6335c03b73b7d8702 (patch) | |
tree | 27673a644ca755004fa462d7defa943d59fa45d7 /packages/utils/src/abi_encoder/abstract_data_types/data_type.ts | |
parent | dd8bb6d08b6e837304a76e9707b79e070f951e4e (diff) | |
download | dexon-0x-contracts-173fc1dcefa266704dd80de6335c03b73b7d8702.tar dexon-0x-contracts-173fc1dcefa266704dd80de6335c03b73b7d8702.tar.gz dexon-0x-contracts-173fc1dcefa266704dd80de6335c03b73b7d8702.tar.bz2 dexon-0x-contracts-173fc1dcefa266704dd80de6335c03b73b7d8702.tar.lz dexon-0x-contracts-173fc1dcefa266704dd80de6335c03b73b7d8702.tar.xz dexon-0x-contracts-173fc1dcefa266704dd80de6335c03b73b7d8702.tar.zst dexon-0x-contracts-173fc1dcefa266704dd80de6335c03b73b7d8702.zip |
Moved encoder selector check into DataType
Diffstat (limited to 'packages/utils/src/abi_encoder/abstract_data_types/data_type.ts')
-rw-r--r-- | packages/utils/src/abi_encoder/abstract_data_types/data_type.ts | 8 |
1 files changed, 7 insertions, 1 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 dd166b19c..450080353 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 @@ -36,7 +36,13 @@ export abstract class DataType { return calldataHex; } - public decode(calldata: string, rules?: DecodingRules, hasSelector: boolean = false): any { + public decode(calldata: string, rules?: DecodingRules, selector?: string): any { + if (selector && !calldata.startsWith(selector)) { + throw new Error( + `Tried to decode calldata, but it was missing the function selector. Expected '${selector}'.`, + ); + } + const hasSelector = selector ? true : false; const rawCalldata = new RawCalldata(calldata, hasSelector); const rules_ = rules ? rules : Constants.DEFAULT_DECODING_RULES; const value = this.generateValue(rawCalldata, rules_); |