aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-20 02:34:04 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commit880540f4b8fd8dd7a7f1a93cf7fbcdc17e1fbb13 (patch)
tree908bdc1b8b71704899ec88da9849bf67b12730a7 /packages/utils/src
parent8a8b904a292063d1adb3df0a84023610a3985f7f (diff)
downloaddexon-sol-tools-880540f4b8fd8dd7a7f1a93cf7fbcdc17e1fbb13.tar
dexon-sol-tools-880540f4b8fd8dd7a7f1a93cf7fbcdc17e1fbb13.tar.gz
dexon-sol-tools-880540f4b8fd8dd7a7f1a93cf7fbcdc17e1fbb13.tar.bz2
dexon-sol-tools-880540f4b8fd8dd7a7f1a93cf7fbcdc17e1fbb13.tar.lz
dexon-sol-tools-880540f4b8fd8dd7a7f1a93cf7fbcdc17e1fbb13.tar.xz
dexon-sol-tools-880540f4b8fd8dd7a7f1a93cf7fbcdc17e1fbb13.tar.zst
dexon-sol-tools-880540f4b8fd8dd7a7f1a93cf7fbcdc17e1fbb13.zip
Fixed issue with decoding negative ints with width < 256
Diffstat (limited to 'packages/utils/src')
-rw-r--r--packages/utils/src/abi_encoder/data_type.ts4
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types.ts5
2 files changed, 5 insertions, 4 deletions
diff --git a/packages/utils/src/abi_encoder/data_type.ts b/packages/utils/src/abi_encoder/data_type.ts
index f5a8087ea..15de12a2f 100644
--- a/packages/utils/src/abi_encoder/data_type.ts
+++ b/packages/utils/src/abi_encoder/data_type.ts
@@ -41,7 +41,8 @@ export abstract class DataType {
}
public decode(calldata: string, rules?: DecodingRules): any {
- const rawCalldata = new RawCalldata(calldata);
+ const rawCalldata = new RawCalldata(calldata, false);
+ console.log(`HERE DUDE ${JSON.stringify(rawCalldata)}`);
const rules_ = rules ? rules : DataType.DEFAULT_DECODING_RULES;
const value = this.generateValue(rawCalldata, rules_);
return value;
@@ -277,6 +278,7 @@ export abstract class MemberDataType extends DataType {
value = [];
_.each(members, (member: DataType, idx: number) => {
let memberValue = member.generateValue(calldata, rules);
+ console.log(`MEMBER VALUE: ${memberValue}`);
(value as any[]).push(memberValue);
});
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types.ts b/packages/utils/src/abi_encoder/evm_data_types.ts
index d024a9bfa..bfb2808da 100644
--- a/packages/utils/src/abi_encoder/evm_data_types.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types.ts
@@ -154,9 +154,8 @@ abstract class Number extends PayloadDataType {
if (this instanceof Int) {
// Check if we're negative
const binBase = 2;
- const paddedValueBin = value.toString(binBase);
- const valueBin = paddedValueBin.slice(paddedValueBin.length - this.width);
- if (valueBin[0].startsWith('1')) {
+ const valueBin = value.toString(2);
+ if (valueBin.length === 256 && valueBin[0].startsWith('1')) {
// Negative
// Step 1/3: Invert binary value
let invertedValueBin = '';