aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-26 07:32:13 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:11 +0800
commitdc7092e1eb11ff9844efe02e367ef37592f38c55 (patch)
treed0031a5731ee0d01b5190a400236e2c86e90ae86 /packages
parentc638151b73289fc936bb7d4323711d1954cc4fcb (diff)
downloaddexon-sol-tools-dc7092e1eb11ff9844efe02e367ef37592f38c55.tar
dexon-sol-tools-dc7092e1eb11ff9844efe02e367ef37592f38c55.tar.gz
dexon-sol-tools-dc7092e1eb11ff9844efe02e367ef37592f38c55.tar.bz2
dexon-sol-tools-dc7092e1eb11ff9844efe02e367ef37592f38c55.tar.lz
dexon-sol-tools-dc7092e1eb11ff9844efe02e367ef37592f38c55.tar.xz
dexon-sol-tools-dc7092e1eb11ff9844efe02e367ef37592f38c55.tar.zst
dexon-sol-tools-dc7092e1eb11ff9844efe02e367ef37592f38c55.zip
Removed mapDataItemToDataType from Factory. Now its just ::create()
Diffstat (limited to 'packages')
-rw-r--r--packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts1
-rw-r--r--packages/utils/src/abi_encoder/evm_data_type_factory.ts42
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/array.ts2
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/method.ts22
4 files changed, 25 insertions, 42 deletions
diff --git a/packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts b/packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts
index 9e2a94522..bd4d2effd 100644
--- a/packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts
+++ b/packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts
@@ -6,7 +6,6 @@ import { DataType } from './data_type';
export interface DataTypeFactory {
create: (dataItem: DataItem, parentDataType?: DataType) => DataType;
- mapDataItemToDataType: (dataItem: DataItem) => DataType;
}
export interface DataTypeStaticInterface {
diff --git a/packages/utils/src/abi_encoder/evm_data_type_factory.ts b/packages/utils/src/abi_encoder/evm_data_type_factory.ts
index 5d37acad9..bfe457367 100644
--- a/packages/utils/src/abi_encoder/evm_data_type_factory.ts
+++ b/packages/utils/src/abi_encoder/evm_data_type_factory.ts
@@ -82,42 +82,36 @@ export class EvmDataTypeFactory implements DataTypeFactory {
return EvmDataTypeFactory._instance;
}
- public mapDataItemToDataType(dataItem: DataItem): DataType {
+ public create(dataItem: DataItem, parentDataType?: DataType): DataType {
+ // Create data type
+ let dataType: undefined | DataType;
if (Array.matchType(dataItem.type)) {
- return new Array(dataItem);
+ dataType = new Array(dataItem);
} else if (Address.matchType(dataItem.type)) {
- return new Address(dataItem);
+ dataType = new Address(dataItem);
} else if (Bool.matchType(dataItem.type)) {
- return new Bool(dataItem);
+ dataType = new Bool(dataItem);
} else if (Int.matchType(dataItem.type)) {
- return new Int(dataItem);
+ dataType = new Int(dataItem);
} else if (UInt.matchType(dataItem.type)) {
- return new UInt(dataItem);
+ dataType = new UInt(dataItem);
} else if (StaticBytes.matchType(dataItem.type)) {
- return new StaticBytes(dataItem);
+ dataType = new StaticBytes(dataItem);
} else if (Tuple.matchType(dataItem.type)) {
- return new Tuple(dataItem);
+ dataType = new Tuple(dataItem);
} else if (DynamicBytes.matchType(dataItem.type)) {
- return new DynamicBytes(dataItem);
+ dataType = new DynamicBytes(dataItem);
} else if (String.matchType(dataItem.type)) {
- return new String(dataItem);
+ dataType = new String(dataItem);
}
// @TODO: Implement Fixed/UFixed types
- throw new Error(`Unrecognized data type: '${dataItem.type}'`);
- }
-
- public create(dataItem: DataItem, parentDataType?: DataType): DataType {
- const dataType = this.mapDataItemToDataType(dataItem);
- if (dataType.isStatic()) {
- return dataType;
- }
-
- if (parentDataType === undefined) {
- // @Todo -- will this work for return values?
- throw new Error(`Trying to create a pointer`);
+ if (!dataType) {
+ throw new Error(`Unrecognized data type: '${dataItem.type}'`);
+ } else if (parentDataType && !dataType.isStatic()) {
+ const pointerToDataType = new Pointer(dataType, parentDataType);
+ return pointerToDataType;
}
- const pointer = new Pointer(dataType, parentDataType);
- return pointer;
+ return dataType;
}
private constructor() {}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/array.ts b/packages/utils/src/abi_encoder/evm_data_types/array.ts
index 9963b6f32..dd8184fd0 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/array.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/array.ts
@@ -44,7 +44,7 @@ export class Array extends MemberDataType {
if (components !== undefined) {
dataItem.components = components;
}
- const elementDataType = this.getFactory().mapDataItemToDataType(dataItem);
+ const elementDataType = this.getFactory().create(dataItem);
const type = elementDataType.getSignature();
if (this._arrayLength === undefined) {
return `${type}[]`;
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 50d676b4a..671b80890 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/method.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts
@@ -7,7 +7,6 @@ import { RawCalldata } from '../calldata';
import * as Constants from '../utils/constants';
import { DecodingRules, EncodingRules } from '../utils/rules';
-import { StaticBytes } from './static_bytes';
import { Tuple } from './tuple';
export class Method extends MemberDataType {
@@ -16,19 +15,14 @@ export class Method extends MemberDataType {
private readonly _methodSignature: string;
private readonly _methodSelector: string;
- private readonly _returnDataTypes: DataType[];
- private readonly _returnDataItem: DataItem;
+ private readonly _returnDataType: DataType;
public constructor(abi: MethodAbi, dataTypeFactory: DataTypeFactory) {
super({ type: 'method', name: abi.name, components: abi.inputs }, dataTypeFactory);
this._methodSignature = this._computeSignature();
this.selector = this._methodSelector = this._computeSelector();
- this._returnDataTypes = [];
- this._returnDataItem = { type: 'tuple', name: abi.name, components: abi.outputs };
- const dummy = new StaticBytes({ type: 'byte', name: 'DUMMY' }, dataTypeFactory); // @TODO TMP
- _.each(abi.outputs, (dataItem: DataItem) => {
- this._returnDataTypes.push(this.getFactory().create(dataItem, dummy));
- });
+ const returnDataItem: DataItem = { type: 'tuple', name: abi.name, components: abi.outputs };
+ this._returnDataType = new Tuple(returnDataItem, this.getFactory());
}
public encode(value: any, rules?: EncodingRules): string {
@@ -48,18 +42,14 @@ export class Method extends MemberDataType {
}
public encodeReturnValues(value: any, rules?: EncodingRules): string {
- const returnDataType = new Tuple(this._returnDataItem, this.getFactory());
- const returndata = returnDataType.encode(value, rules);
- return returndata;
+ const returnData = this._returnDataType.encode(value, rules);
+ return returnData;
}
public decodeReturnValues(returndata: string, rules?: DecodingRules): any {
- const returnValues: any[] = [];
const rules_: DecodingRules = rules ? rules : { structsAsObjects: false };
const rawReturnData = new RawCalldata(returndata, false);
- _.each(this._returnDataTypes, (dataType: DataType) => {
- returnValues.push(dataType.generateValue(rawReturnData, rules_));
- });
+ const returnValues = this._returnDataType.generateValue(rawReturnData, rules_);
return returnValues;
}