@0x/base-contract: Properly encode BigNumber indexed filter values in getTopicsForIndexedArgs().

This commit is contained in:
Lawrence Forman
2019-09-18 22:44:28 -04:00
committed by Lawrence Forman
parent d33080cf08
commit 54ac1c284b
2 changed files with 10 additions and 1 deletions

View File

@@ -17,6 +17,10 @@
{
"note": "Make the Promise returned by `awaitTransactionSuccessAsync` compatible with base Promise type",
"pr": 1885
},
{
"note": "Properly encode `BigNumber` indexed filter values in `getTopicsForIndexedArgs()`",
"pr": 2155
}
]
},

View File

@@ -1,3 +1,4 @@
import { BigNumber } from '@0x/utils';
import { BlockRange, ContractAbi, EventAbi, FilterObject, LogEntry } from 'ethereum-types';
import * as ethUtil from 'ethereumjs-util';
import * as jsSHA3 from 'js-sha3';
@@ -51,7 +52,11 @@ export const filterUtils = {
// Null is a wildcard topic in a JSON-RPC call
topics.push(null);
} else {
const value = indexFilterValues[eventInput.name] as string;
let value = indexFilterValues[eventInput.name] as any;
if (BigNumber.isBigNumber(value)) {
// tslint:disable-next-line custom-no-magic-numbers
value = ethUtil.fromSigned(value.toString(10) as any);
}
const buffer = ethUtil.toBuffer(value);
const paddedBuffer = ethUtil.setLengthLeft(buffer, TOPIC_LENGTH);
const topic = ethUtil.bufferToHex(paddedBuffer);