aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-19 13:44:26 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-01-15 02:49:29 +0800
commit2f1454e90e5fd7d85c4deb3a8c674043e8a14564 (patch)
tree65ce021b55cf9e384e808bba94b2979d9c73f170 /packages/utils/src
parentb89f9869492e369370bcef593d69e59172f13da4 (diff)
downloaddexon-sol-tools-2f1454e90e5fd7d85c4deb3a8c674043e8a14564.tar
dexon-sol-tools-2f1454e90e5fd7d85c4deb3a8c674043e8a14564.tar.gz
dexon-sol-tools-2f1454e90e5fd7d85c4deb3a8c674043e8a14564.tar.bz2
dexon-sol-tools-2f1454e90e5fd7d85c4deb3a8c674043e8a14564.tar.lz
dexon-sol-tools-2f1454e90e5fd7d85c4deb3a8c674043e8a14564.tar.xz
dexon-sol-tools-2f1454e90e5fd7d85c4deb3a8c674043e8a14564.tar.zst
dexon-sol-tools-2f1454e90e5fd7d85c4deb3a8c674043e8a14564.zip
Working for almost every test
Diffstat (limited to 'packages/utils/src')
-rw-r--r--packages/utils/src/abi_encoder/abstract_data_types/types/set.ts16
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/int.ts5
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/method.ts7
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/uint.ts5
4 files changed, 28 insertions, 5 deletions
diff --git a/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts b/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts
index f97f0bac3..73e9cf778 100644
--- a/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts
+++ b/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts
@@ -138,7 +138,7 @@ export abstract class AbstractSetDataType extends DataType {
_.forEach(this._memberIndexByName, (memberIndex: number, memberName: string) => {
if (!(memberName in obj)) {
throw new Error(
- `Could not assign tuple to object: missing field '${memberName}' in object ${obj}`,
+ `Could not assign tuple to object: missing key '${memberName}' in object ${JSON.stringify(obj)}`,
);
}
const memberValue: any = duplicateObj[memberName];
@@ -180,17 +180,27 @@ export abstract class AbstractSetDataType extends DataType {
// Create one member for each component of `dataItem`
const members: DataType[] = [];
const memberIndexByName: MemberIndexByName = {};
+ const memberNames: string[] = [];
_.each(dataItem.components, (memberItem: DataItem) => {
+ // If a component with `name` already exists then
+ // rename to `name_nameIdx` to avoid naming conflicts.
+ let memberName = memberItem.name;
+ let nameIdx = 0;
+ while (_.includes(memberNames, memberName) || _.isEmpty(memberName)) {
+ nameIdx++;
+ memberName = `${memberItem.name}_${nameIdx}`;
+ }
+ memberNames.push(memberName);
const childDataItem: DataItem = {
type: memberItem.type,
- name: `${dataItem.name}.${memberItem.name}`,
+ name: `${dataItem.name}.${memberName}`
};
const components = memberItem.components;
if (!_.isUndefined(components)) {
childDataItem.components = components;
}
const child = this.getFactory().create(childDataItem, this);
- memberIndexByName[memberItem.name] = members.length;
+ memberIndexByName[memberName] = members.length;
members.push(child);
});
return [members, memberIndexByName];
diff --git a/packages/utils/src/abi_encoder/evm_data_types/int.ts b/packages/utils/src/abi_encoder/evm_data_types/int.ts
index f1dcf5ea1..c9f734799 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/int.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/int.ts
@@ -47,9 +47,12 @@ export class IntDataType extends AbstractBlobDataType {
return encodedValue;
}
- public decodeValue(calldata: RawCalldata): BigNumber {
+ public decodeValue(calldata: RawCalldata): BigNumber|number {
const valueBuf = calldata.popWord();
const value = EncoderMath.safeDecodeNumericValue(valueBuf, this._minValue, this._maxValue);
+ if (this._width === 8) {
+ return value.toNumber();
+ }
return value;
}
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 b1cd1377f..c777902e8 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/method.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts
@@ -8,6 +8,7 @@ import { AbstractSetDataType } from '../abstract_data_types/types/set';
import { constants } from '../utils/constants';
import { DecodingRules, EncodingRules } from '../utils/rules';
+import { ArrayDataType } from './array';
import { TupleDataType } from './tuple';
export class MethodDataType extends AbstractSetDataType {
@@ -44,6 +45,12 @@ 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 getSignature(): string {
return this._methodSignature;
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/uint.ts b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
index 5180f0cf3..06cde4eea 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
@@ -46,9 +46,12 @@ export class UIntDataType extends AbstractBlobDataType {
return encodedValue;
}
- public decodeValue(calldata: RawCalldata): BigNumber {
+ public decodeValue(calldata: RawCalldata): BigNumber|number {
const valueBuf = calldata.popWord();
const value = EncoderMath.safeDecodeNumericValue(valueBuf, UIntDataType._MIN_VALUE, this._maxValue);
+ if (this._width === 8) {
+ return value.toNumber();
+ }
return value;
}