aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/abi_encoder
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-26 07:50:49 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:11 +0800
commit173fc1dcefa266704dd80de6335c03b73b7d8702 (patch)
tree27673a644ca755004fa462d7defa943d59fa45d7 /packages/utils/src/abi_encoder
parentdd8bb6d08b6e837304a76e9707b79e070f951e4e (diff)
downloaddexon-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')
-rw-r--r--packages/utils/src/abi_encoder/abstract_data_types/data_type.ts8
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/method.ts16
2 files changed, 10 insertions, 14 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_);
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 2faffd44e..f2e417485 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/method.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts
@@ -3,7 +3,6 @@ import * as ethUtil from 'ethereumjs-util';
import * as _ from 'lodash';
import { DataType, DataTypeFactory, MemberDataType } from '../abstract_data_types';
-import { RawCalldata } from '../calldata';
import * as Constants from '../utils/constants';
import { DecodingRules, EncodingRules } from '../utils/rules';
@@ -29,13 +28,7 @@ export class Method extends MemberDataType {
}
public decode(calldata: string, rules?: DecodingRules): any[] | object {
- if (!calldata.startsWith(this._methodSelector)) {
- throw new Error(
- `Tried to decode calldata, but it was missing the function selector. Expected '${this._methodSelector}'.`,
- );
- }
- const hasSelector = true;
- const value = super.decode(calldata, rules, hasSelector);
+ const value = super.decode(calldata, rules, this._methodSelector);
return value;
}
@@ -44,11 +37,8 @@ export class Method extends MemberDataType {
return returnData;
}
- public decodeReturnValues(returndata: string, rules_?: DecodingRules): any {
- const rules: DecodingRules = rules_ ? rules_ : Constants.DEFAULT_DECODING_RULES;
- const returnDataHasSelector = false;
- const rawReturnData = new RawCalldata(returndata, returnDataHasSelector);
- const returnValues = this._returnDataType.generateValue(rawReturnData, rules);
+ public decodeReturnValues(returndata: string, rules?: DecodingRules): any {
+ const returnValues = this._returnDataType.decode(returndata, rules);
return returnValues;
}