Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getTopicsForIndexedArgs(abi: EventAbi, indexFilterValues: IndexedFilterValues): Array {
const topics: Array = [];
for (const eventInput of abi.inputs) {
if (!eventInput.indexed) {
continue;
}
if (indexFilterValues[eventInput.name] === undefined) {
// Null is a wildcard topic in a JSON-RPC call
topics.push(null);
} else {
// tslint:disable: no-unnecessary-type-assertion
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);
}
// tslint:enable: no-unnecessary-type-assertion
const buffer = ethUtil.toBuffer(value);
const paddedBuffer = ethUtil.setLengthLeft(buffer, TOPIC_LENGTH);
const topic = ethUtil.bufferToHex(paddedBuffer);
topics.push(topic);
}
}
return topics;
},
matchesFilter(log: LogEntry, filter: FilterObject): boolean {
protected static _bigNumberToString(_type: string, value: any): any {
return BigNumber.isBigNumber(value) ? value.toString() : value;
}
protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi {
isBigNumber(variableName: string, value: BigNumber): void {
const isBigNumber = BigNumber.isBigNumber(value);
assert.assert(isBigNumber, assert.typeAssertionMessage(variableName, 'BigNumber', value));
},
isNumberLike(variableName: string, value: BigNumber | number): void {
_.each(args, (arg, i) => {
const isNumber = _.isFinite(arg);
if (isNumber) {
argTypes.push('uint8');
} else if (BigNumber.isBigNumber(arg)) {
argTypes.push('uint256');
const base = 10;
args[i] = new BN(arg.toString(base), base);
} else if (ethUtil.isValidAddress(arg)) {
argTypes.push('address');
} else if (_.isString(arg)) {
argTypes.push('string');
} else if (_.isBuffer(arg) || _.isTypedArray(arg)) {
argTypes.push('bytes');
} else if (_.isBoolean(arg)) {
argTypes.push('bool');
} else {
throw new Error(`Unable to guess arg type: ${arg}`);
}
});
const hash = hashFunction(argTypes, args);
isNumberOrBigNumber(variableName: string, value: any): void {
if (_.isFinite(value)) {
return;
} else {
assert.assert(
BigNumber.isBigNumber(value),
assert.typeAssertionMessage(variableName, 'number or BigNumber', value),
);
}
},
isBoolean(variableName: string, value: boolean): void {
isNumberLike(variableName: string, value: BigNumber | number): void {
const isBigNumber = BigNumber.isBigNumber(value);
const isNumber = typeof value === 'number';
assert.assert(isBigNumber || isNumber, assert.typeAssertionMessage(variableName, 'BigNumber | number', value));
},
isValidBaseUnitAmount(variableName: string, value: BigNumber): void {