aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/utils/src')
-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;
}