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