Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 746f481

Browse files
committed
fix: 🐛 make getLogsAsync have sensible defaults
1 parent a3836d5 commit 746f481

21 files changed

+66
-151
lines changed

src/contract_wrappers/contract_wrapper.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-underscore-dangle */
22
import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream';
33
import _ from 'lodash';
4+
import { schemas } from '@0x/json-schemas';
45
import {
56
BaseContract,
67
Web3Wrapper,
@@ -64,12 +65,9 @@ export default abstract class ContractWrapper {
6465
*/
6566
public unsubscribeAll = (): void => {
6667
const filterTokens = _.keys(this._filterCallbacks);
67-
_.each(
68-
filterTokens,
69-
(filterToken): void => {
70-
this.unsubscribeInternal(filterToken);
71-
},
72-
);
68+
_.each(filterTokens, (filterToken): void => {
69+
this.unsubscribeInternal(filterToken);
70+
});
7371
};
7472

7573
private _blockAndLogStreamerIfExists: BlockAndLogStreamer<Block, Log> | undefined;
@@ -138,11 +136,18 @@ export default abstract class ContractWrapper {
138136
protected async getLogsAsyncInternal<ArgsType extends ContractEventArgs>(
139137
address: string,
140138
eventName: ContractEvents,
141-
blockRange: BlockRange,
142-
indexFilterValues: IndexedFilterValues,
143139
abi: ContractAbi,
140+
blockRange?: BlockRange,
141+
indexFilterValues?: IndexedFilterValues,
144142
): Promise<LogWithDecodedArgs<ArgsType>[]> {
145-
const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi, blockRange);
143+
const _blockRange = blockRange || {
144+
fromBlock: BlockParamLiteral.Earliest,
145+
toBlock: BlockParamLiteral.Latest,
146+
};
147+
const _indexFilterValues = indexFilterValues || {};
148+
assert.doesConformToSchema('blockRange', _blockRange, schemas.blockRangeSchema);
149+
assert.doesConformToSchema('indexFilterValues', _indexFilterValues, schemas.indexFilterValuesSchema);
150+
const filter = filterUtils.getFilter(address, eventName, _indexFilterValues, abi, _blockRange);
146151
const logs = await this.web3Wrapper.getLogsAsync(filter);
147152
const logsWithDecodedArguments = _.map(logs, this.tryToDecodeLogOrNoopInternal.bind(this));
148153
return logsWithDecodedArguments as LogWithDecodedArgs<ArgsType>[];
@@ -158,19 +163,16 @@ export default abstract class ContractWrapper {
158163

159164
private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, rawLog: Log): void {
160165
const log: LogEntry = marshaller.unmarshalLog(rawLog as RawLogEntry);
161-
_.forEach(
162-
this._filters,
163-
(filter: FilterObject, filterToken: string): void => {
164-
if (filterUtils.matchesFilter(log, filter)) {
165-
const decodedLog = this.tryToDecodeLogOrNoopInternal(log) as LogWithDecodedArgs<ArgsType>;
166-
const logEvent = {
167-
log: decodedLog,
168-
isRemoved,
169-
};
170-
this._filterCallbacks[filterToken](null, logEvent);
171-
}
172-
},
173-
);
166+
_.forEach(this._filters, (filter: FilterObject, filterToken: string): void => {
167+
if (filterUtils.matchesFilter(log, filter)) {
168+
const decodedLog = this.tryToDecodeLogOrNoopInternal(log) as LogWithDecodedArgs<ArgsType>;
169+
const logEvent = {
170+
log: decodedLog,
171+
isRemoved,
172+
};
173+
this._filterCallbacks[filterToken](null, logEvent);
174+
}
175+
});
174176
}
175177

176178
private _startBlockAndLogStream(isVerbose: boolean): void {

src/contract_wrappers/modules/checkpoint/erc20_dividend_checkpoint_wrapper.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,10 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
328328
params: GetLogsAsyncParams,
329329
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
330330
assert.doesBelongToStringEnum('eventName', params.eventName, ERC20DividendCheckpointEvents);
331-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
332-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
333331
const normalizedContractAddress = (await this.contract).address.toLowerCase();
334332
const logs = await this.getLogsAsyncInternal<ArgsType>(
335333
normalizedContractAddress,
336334
params.eventName,
337-
params.blockRange,
338-
params.indexFilterValues,
339335
ERC20DividendCheckpoint.abi,
340336
);
341337
return logs;

src/contract_wrappers/modules/checkpoint/ether_dividend_checkpoint_wrapper.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,10 @@ export default class EtherDividendCheckpointWrapper extends DividendCheckpointWr
388388
params: GetLogsAsyncParams,
389389
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
390390
assert.doesBelongToStringEnum('eventName', params.eventName, EtherDividendCheckpointEvents);
391-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
392-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
393391
const normalizedContractAddress = (await this.contract).address.toLowerCase();
394392
const logs = await this.getLogsAsyncInternal<ArgsType>(
395393
normalizedContractAddress,
396394
params.eventName,
397-
params.blockRange,
398-
params.indexFilterValues,
399395
EtherDividendCheckpoint.abi,
400396
);
401397
return logs;

src/contract_wrappers/modules/module_factory_wrapper.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,10 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
353353
params: GetLogsAsyncParams,
354354
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
355355
assert.doesBelongToStringEnum('eventName', params.eventName, ModuleFactoryEvents);
356-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
357-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
358356
const normalizedContractAddress = (await this.contract).address.toLowerCase();
359357
const logs = await this.getLogsAsyncInternal<ArgsType>(
360358
normalizedContractAddress,
361359
params.eventName,
362-
params.blockRange,
363-
params.indexFilterValues,
364360
ModuleFactory.abi,
365361
);
366362
return logs;

src/contract_wrappers/modules/permission_manager/general_permission_manager_wrapper.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,13 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
237237
return value[0];
238238
}); // [module1: [[module1, perm1], [module1, perm2]], ...]
239239
const typedResult: PermissionsPerModule[] = [];
240-
_.forEach(
241-
groupedResult,
242-
(value, key): void => {
243-
const permissionsPerModule: PermissionsPerModule = {
244-
module: key,
245-
permissions: value.map(pair => parsePermBytes32Value(pair[1] as string)),
246-
};
247-
typedResult.push(permissionsPerModule);
248-
},
249-
);
240+
_.forEach(groupedResult, (value, key): void => {
241+
const permissionsPerModule: PermissionsPerModule = {
242+
module: key,
243+
permissions: value.map(pair => parsePermBytes32Value(pair[1] as string)),
244+
};
245+
typedResult.push(permissionsPerModule);
246+
});
250247
return typedResult;
251248
};
252249

@@ -288,14 +285,10 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
288285
params: GetLogsAsyncParams,
289286
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
290287
assert.doesBelongToStringEnum('eventName', params.eventName, GeneralPermissionManagerEvents);
291-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
292-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
293288
const normalizedContractAddress = (await this.contract).address.toLowerCase();
294289
const logs = await this.getLogsAsyncInternal<ArgsType>(
295290
normalizedContractAddress,
296291
params.eventName,
297-
params.blockRange,
298-
params.indexFilterValues,
299292
GeneralPermissionManager.abi,
300293
);
301294
return logs;

src/contract_wrappers/modules/sto/capped_sto_wrapper.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,8 @@ export default class CappedSTOWrapper extends STOWrapper {
300300
params: GetLogsAsyncParams,
301301
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
302302
assert.doesBelongToStringEnum('eventName', params.eventName, CappedSTOEvents);
303-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
304-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
305303
const normalizedContractAddress = (await this.contract).address.toLowerCase();
306-
const logs = await this.getLogsAsyncInternal<ArgsType>(
307-
normalizedContractAddress,
308-
params.eventName,
309-
params.blockRange,
310-
params.indexFilterValues,
311-
CappedSTO.abi,
312-
);
304+
const logs = await this.getLogsAsyncInternal<ArgsType>(normalizedContractAddress, params.eventName, CappedSTO.abi);
313305
return logs;
314306
};
315307
}

src/contract_wrappers/modules/sto/usd_tiered_sto_wrapper.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,14 +943,10 @@ export default class USDTieredSTOWrapper extends STOWrapper {
943943
params: GetLogsAsyncParams,
944944
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
945945
assert.doesBelongToStringEnum('eventName', params.eventName, USDTieredSTOEvents);
946-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
947-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
948946
const normalizedContractAddress = (await this.contract).address.toLowerCase();
949947
const logs = await this.getLogsAsyncInternal<ArgsType>(
950948
normalizedContractAddress,
951949
params.eventName,
952-
params.blockRange,
953-
params.indexFilterValues,
954950
USDTieredSTO.abi,
955951
);
956952
return logs;

src/contract_wrappers/modules/transfer_manager/count_transfer_manager_wrapper.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,10 @@ export default class CountTransferManagerWrapper extends ModuleWrapper {
201201
params: GetLogsAsyncParams,
202202
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
203203
assert.doesBelongToStringEnum('eventName', params.eventName, CountTransferManagerEvents);
204-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
205-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
206204
const normalizedContractAddress = (await this.contract).address.toLowerCase();
207205
const logs = await this.getLogsAsyncInternal<ArgsType>(
208206
normalizedContractAddress,
209207
params.eventName,
210-
params.blockRange,
211-
params.indexFilterValues,
212208
CountTransferManager.abi,
213209
);
214210
return logs;

src/contract_wrappers/modules/transfer_manager/general_transfer_manager_wrapper.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,14 +784,10 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
784784
params: GetLogsAsyncParams,
785785
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
786786
assert.doesBelongToStringEnum('eventName', params.eventName, GeneralTransferManagerEvents);
787-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
788-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
789787
const normalizedContractAddress = (await this.contract).address.toLowerCase();
790788
const logs = await this.getLogsAsyncInternal<ArgsType>(
791789
normalizedContractAddress,
792790
params.eventName,
793-
params.blockRange,
794-
params.indexFilterValues,
795791
GeneralTransferManager.abi,
796792
);
797793
return logs;

src/contract_wrappers/modules/transfer_manager/manual_approval_transfer_manager_wrapper.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,10 @@ export default class ManualApprovalTransferManagerWrapper extends ModuleWrapper
498498
params: GetLogsAsyncParams,
499499
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
500500
assert.doesBelongToStringEnum('eventName', params.eventName, ManualApprovalTransferManagerEvents);
501-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
502-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
503501
const normalizedContractAddress = (await this.contract).address.toLowerCase();
504502
const logs = await this.getLogsAsyncInternal<ArgsType>(
505503
normalizedContractAddress,
506504
params.eventName,
507-
params.blockRange,
508-
params.indexFilterValues,
509505
ManualApprovalTransferManager.abi,
510506
);
511507
return logs;

0 commit comments

Comments
 (0)