Compare commits

..

2 Commits

Author SHA1 Message Date
a293e541d9
Change validateEvents params 2024-11-17 23:23:00 +00:00
8644cd3c82
Add multiQueryFilter function 2024-11-17 22:37:15 +00:00
6 changed files with 26 additions and 63 deletions

9
dist/batch.d.ts vendored
View File

@ -60,7 +60,6 @@ export declare class BatchTransactionService {
export interface BatchEventServiceConstructor { export interface BatchEventServiceConstructor {
provider: Provider; provider: Provider;
contract: BaseContract; contract: BaseContract;
address?: string | string[];
onProgress?: BatchEventOnProgress; onProgress?: BatchEventOnProgress;
concurrencySize?: number; concurrencySize?: number;
blocksPerRequest?: number; blocksPerRequest?: number;
@ -76,6 +75,7 @@ export type BatchEventOnProgress = ({ percentage, type, fromBlock, toBlock, coun
count?: number; count?: number;
}) => void; }) => void;
export interface EventInput { export interface EventInput {
address?: string | string[];
fromBlock: number; fromBlock: number;
toBlock: number; toBlock: number;
type: ContractEventName; type: ContractEventName;
@ -86,15 +86,14 @@ export interface EventInput {
export declare class BatchEventsService { export declare class BatchEventsService {
provider: Provider; provider: Provider;
contract: BaseContract; contract: BaseContract;
address?: string | string[];
onProgress?: BatchEventOnProgress; onProgress?: BatchEventOnProgress;
concurrencySize: number; concurrencySize: number;
blocksPerRequest: number; blocksPerRequest: number;
shouldRetry: boolean; shouldRetry: boolean;
retryMax: number; retryMax: number;
retryOn: number; retryOn: number;
constructor({ provider, contract, address, onProgress, concurrencySize, blocksPerRequest, shouldRetry, retryMax, retryOn, }: BatchEventServiceConstructor); constructor({ provider, contract, onProgress, concurrencySize, blocksPerRequest, shouldRetry, retryMax, retryOn, }: BatchEventServiceConstructor);
getPastEvents({ fromBlock, toBlock, type }: EventInput): Promise<EventLog[]>; getPastEvents({ address, fromBlock, toBlock, type }: EventInput): Promise<EventLog[]>;
createBatchRequest(batchArray: EventInput[]): Promise<EventLog[]>[]; createBatchRequest(batchArray: EventInput[]): Promise<EventLog[]>[];
getBatchEvents({ fromBlock, toBlock, type }: EventInput): Promise<EventLog[]>; getBatchEvents({ address, fromBlock, toBlock, type }: EventInput): Promise<EventLog[]>;
} }

19
dist/index.js vendored
View File

@ -427,7 +427,6 @@ class BatchTransactionService {
class BatchEventsService { class BatchEventsService {
provider; provider;
contract; contract;
address;
onProgress; onProgress;
concurrencySize; concurrencySize;
blocksPerRequest; blocksPerRequest;
@ -437,7 +436,6 @@ class BatchEventsService {
constructor({ constructor({
provider, provider,
contract, contract,
address,
onProgress, onProgress,
concurrencySize = 10, concurrencySize = 10,
blocksPerRequest = 5e3, blocksPerRequest = 5e3,
@ -447,7 +445,6 @@ class BatchEventsService {
}) { }) {
this.provider = provider; this.provider = provider;
this.contract = contract; this.contract = contract;
this.address = address;
this.onProgress = onProgress; this.onProgress = onProgress;
this.concurrencySize = concurrencySize; this.concurrencySize = concurrencySize;
this.blocksPerRequest = blocksPerRequest; this.blocksPerRequest = blocksPerRequest;
@ -455,19 +452,13 @@ class BatchEventsService {
this.retryMax = retryMax; this.retryMax = retryMax;
this.retryOn = retryOn; this.retryOn = retryOn;
} }
async getPastEvents({ fromBlock, toBlock, type }) { async getPastEvents({ address, fromBlock, toBlock, type }) {
let err; let err;
let retries = 0; let retries = 0;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
try { try {
if (this.address) { if (address) {
return await multiQueryFilter( return await multiQueryFilter(address, this.contract, type, fromBlock, toBlock);
this.address,
this.contract,
type,
fromBlock,
toBlock
);
} }
return await this.contract.queryFilter(type, fromBlock, toBlock); return await this.contract.queryFilter(type, fromBlock, toBlock);
} catch (e) { } catch (e) {
@ -488,14 +479,14 @@ class BatchEventsService {
return this.getPastEvents(event); return this.getPastEvents(event);
}); });
} }
async getBatchEvents({ fromBlock, toBlock, type = "*" }) { async getBatchEvents({ address, fromBlock, toBlock, type = "*" }) {
if (!toBlock) { if (!toBlock) {
toBlock = await this.provider.getBlockNumber(); toBlock = await this.provider.getBlockNumber();
} }
const eventsToSync = []; const eventsToSync = [];
for (let i = fromBlock; i < toBlock; i += this.blocksPerRequest) { for (let i = fromBlock; i < toBlock; i += this.blocksPerRequest) {
const j = i + this.blocksPerRequest - 1 > toBlock ? toBlock : i + this.blocksPerRequest - 1; const j = i + this.blocksPerRequest - 1 > toBlock ? toBlock : i + this.blocksPerRequest - 1;
eventsToSync.push({ fromBlock: i, toBlock: j, type }); eventsToSync.push({ address, fromBlock: i, toBlock: j, type });
} }
const events = []; const events = [];
const eventChunk = chunk(eventsToSync, this.concurrencySize); const eventChunk = chunk(eventsToSync, this.concurrencySize);

19
dist/index.mjs vendored
View File

@ -405,7 +405,6 @@ class BatchTransactionService {
class BatchEventsService { class BatchEventsService {
provider; provider;
contract; contract;
address;
onProgress; onProgress;
concurrencySize; concurrencySize;
blocksPerRequest; blocksPerRequest;
@ -415,7 +414,6 @@ class BatchEventsService {
constructor({ constructor({
provider, provider,
contract, contract,
address,
onProgress, onProgress,
concurrencySize = 10, concurrencySize = 10,
blocksPerRequest = 5e3, blocksPerRequest = 5e3,
@ -425,7 +423,6 @@ class BatchEventsService {
}) { }) {
this.provider = provider; this.provider = provider;
this.contract = contract; this.contract = contract;
this.address = address;
this.onProgress = onProgress; this.onProgress = onProgress;
this.concurrencySize = concurrencySize; this.concurrencySize = concurrencySize;
this.blocksPerRequest = blocksPerRequest; this.blocksPerRequest = blocksPerRequest;
@ -433,19 +430,13 @@ class BatchEventsService {
this.retryMax = retryMax; this.retryMax = retryMax;
this.retryOn = retryOn; this.retryOn = retryOn;
} }
async getPastEvents({ fromBlock, toBlock, type }) { async getPastEvents({ address, fromBlock, toBlock, type }) {
let err; let err;
let retries = 0; let retries = 0;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
try { try {
if (this.address) { if (address) {
return await multiQueryFilter( return await multiQueryFilter(address, this.contract, type, fromBlock, toBlock);
this.address,
this.contract,
type,
fromBlock,
toBlock
);
} }
return await this.contract.queryFilter(type, fromBlock, toBlock); return await this.contract.queryFilter(type, fromBlock, toBlock);
} catch (e) { } catch (e) {
@ -466,14 +457,14 @@ class BatchEventsService {
return this.getPastEvents(event); return this.getPastEvents(event);
}); });
} }
async getBatchEvents({ fromBlock, toBlock, type = "*" }) { async getBatchEvents({ address, fromBlock, toBlock, type = "*" }) {
if (!toBlock) { if (!toBlock) {
toBlock = await this.provider.getBlockNumber(); toBlock = await this.provider.getBlockNumber();
} }
const eventsToSync = []; const eventsToSync = [];
for (let i = fromBlock; i < toBlock; i += this.blocksPerRequest) { for (let i = fromBlock; i < toBlock; i += this.blocksPerRequest) {
const j = i + this.blocksPerRequest - 1 > toBlock ? toBlock : i + this.blocksPerRequest - 1; const j = i + this.blocksPerRequest - 1 > toBlock ? toBlock : i + this.blocksPerRequest - 1;
eventsToSync.push({ fromBlock: i, toBlock: j, type }); eventsToSync.push({ address, fromBlock: i, toBlock: j, type });
} }
const events = []; const events = [];
const eventChunk = chunk(eventsToSync, this.concurrencySize); const eventChunk = chunk(eventsToSync, this.concurrencySize);

19
dist/tornado.umd.js vendored
View File

@ -60255,7 +60255,6 @@ class BatchTransactionService {
class BatchEventsService { class BatchEventsService {
provider; provider;
contract; contract;
address;
onProgress; onProgress;
concurrencySize; concurrencySize;
blocksPerRequest; blocksPerRequest;
@ -60265,7 +60264,6 @@ class BatchEventsService {
constructor({ constructor({
provider, provider,
contract, contract,
address,
onProgress, onProgress,
concurrencySize = 10, concurrencySize = 10,
blocksPerRequest = 5e3, blocksPerRequest = 5e3,
@ -60275,7 +60273,6 @@ class BatchEventsService {
}) { }) {
this.provider = provider; this.provider = provider;
this.contract = contract; this.contract = contract;
this.address = address;
this.onProgress = onProgress; this.onProgress = onProgress;
this.concurrencySize = concurrencySize; this.concurrencySize = concurrencySize;
this.blocksPerRequest = blocksPerRequest; this.blocksPerRequest = blocksPerRequest;
@ -60283,19 +60280,13 @@ class BatchEventsService {
this.retryMax = retryMax; this.retryMax = retryMax;
this.retryOn = retryOn; this.retryOn = retryOn;
} }
async getPastEvents({ fromBlock, toBlock, type }) { async getPastEvents({ address, fromBlock, toBlock, type }) {
let err; let err;
let retries = 0; let retries = 0;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
try { try {
if (this.address) { if (address) {
return await multiQueryFilter( return await multiQueryFilter(address, this.contract, type, fromBlock, toBlock);
this.address,
this.contract,
type,
fromBlock,
toBlock
);
} }
return await this.contract.queryFilter(type, fromBlock, toBlock); return await this.contract.queryFilter(type, fromBlock, toBlock);
} catch (e) { } catch (e) {
@ -60316,14 +60307,14 @@ class BatchEventsService {
return this.getPastEvents(event); return this.getPastEvents(event);
}); });
} }
async getBatchEvents({ fromBlock, toBlock, type = "*" }) { async getBatchEvents({ address, fromBlock, toBlock, type = "*" }) {
if (!toBlock) { if (!toBlock) {
toBlock = await this.provider.getBlockNumber(); toBlock = await this.provider.getBlockNumber();
} }
const eventsToSync = []; const eventsToSync = [];
for (let i = fromBlock; i < toBlock; i += this.blocksPerRequest) { for (let i = fromBlock; i < toBlock; i += this.blocksPerRequest) {
const j = i + this.blocksPerRequest - 1 > toBlock ? toBlock : i + this.blocksPerRequest - 1; const j = i + this.blocksPerRequest - 1 > toBlock ? toBlock : i + this.blocksPerRequest - 1;
eventsToSync.push({ fromBlock: i, toBlock: j, type }); eventsToSync.push({ address, fromBlock: i, toBlock: j, type });
} }
const events = []; const events = [];
const eventChunk = (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .chunk */ .iv)(eventsToSync, this.concurrencySize); const eventChunk = (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .chunk */ .iv)(eventsToSync, this.concurrencySize);

File diff suppressed because one or more lines are too long

View File

@ -422,7 +422,6 @@ export class BatchTransactionService {
export interface BatchEventServiceConstructor { export interface BatchEventServiceConstructor {
provider: Provider; provider: Provider;
contract: BaseContract; contract: BaseContract;
address?: string | string[];
onProgress?: BatchEventOnProgress; onProgress?: BatchEventOnProgress;
concurrencySize?: number; concurrencySize?: number;
blocksPerRequest?: number; blocksPerRequest?: number;
@ -447,6 +446,7 @@ export type BatchEventOnProgress = ({
// To enable iteration only numbers are accepted for fromBlock input // To enable iteration only numbers are accepted for fromBlock input
export interface EventInput { export interface EventInput {
address?: string | string[];
fromBlock: number; fromBlock: number;
toBlock: number; toBlock: number;
type: ContractEventName; type: ContractEventName;
@ -458,7 +458,6 @@ export interface EventInput {
export class BatchEventsService { export class BatchEventsService {
provider: Provider; provider: Provider;
contract: BaseContract; contract: BaseContract;
address?: string | string[];
onProgress?: BatchEventOnProgress; onProgress?: BatchEventOnProgress;
concurrencySize: number; concurrencySize: number;
blocksPerRequest: number; blocksPerRequest: number;
@ -468,7 +467,6 @@ export class BatchEventsService {
constructor({ constructor({
provider, provider,
contract, contract,
address,
onProgress, onProgress,
concurrencySize = 10, concurrencySize = 10,
blocksPerRequest = 5000, blocksPerRequest = 5000,
@ -478,7 +476,6 @@ export class BatchEventsService {
}: BatchEventServiceConstructor) { }: BatchEventServiceConstructor) {
this.provider = provider; this.provider = provider;
this.contract = contract; this.contract = contract;
this.address = address;
this.onProgress = onProgress; this.onProgress = onProgress;
this.concurrencySize = concurrencySize; this.concurrencySize = concurrencySize;
this.blocksPerRequest = blocksPerRequest; this.blocksPerRequest = blocksPerRequest;
@ -487,21 +484,15 @@ export class BatchEventsService {
this.retryOn = retryOn; this.retryOn = retryOn;
} }
async getPastEvents({ fromBlock, toBlock, type }: EventInput): Promise<EventLog[]> { async getPastEvents({ address, fromBlock, toBlock, type }: EventInput): Promise<EventLog[]> {
let err; let err;
let retries = 0; let retries = 0;
// eslint-disable-next-line no-unmodified-loop-condition // eslint-disable-next-line no-unmodified-loop-condition
while ((!this.shouldRetry && retries === 0) || (this.shouldRetry && retries < this.retryMax)) { while ((!this.shouldRetry && retries === 0) || (this.shouldRetry && retries < this.retryMax)) {
try { try {
if (this.address) { if (address) {
return (await multiQueryFilter( return (await multiQueryFilter(address, this.contract, type, fromBlock, toBlock)) as EventLog[];
this.address,
this.contract,
type,
fromBlock,
toBlock,
)) as EventLog[];
} }
return (await this.contract.queryFilter(type, fromBlock, toBlock)) as EventLog[]; return (await this.contract.queryFilter(type, fromBlock, toBlock)) as EventLog[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -532,7 +523,7 @@ export class BatchEventsService {
}); });
} }
async getBatchEvents({ fromBlock, toBlock, type = '*' }: EventInput): Promise<EventLog[]> { async getBatchEvents({ address, fromBlock, toBlock, type = '*' }: EventInput): Promise<EventLog[]> {
if (!toBlock) { if (!toBlock) {
toBlock = await this.provider.getBlockNumber(); toBlock = await this.provider.getBlockNumber();
} }
@ -542,7 +533,7 @@ export class BatchEventsService {
for (let i = fromBlock; i < toBlock; i += this.blocksPerRequest) { for (let i = fromBlock; i < toBlock; i += this.blocksPerRequest) {
const j = i + this.blocksPerRequest - 1 > toBlock ? toBlock : i + this.blocksPerRequest - 1; const j = i + this.blocksPerRequest - 1 > toBlock ? toBlock : i + this.blocksPerRequest - 1;
eventsToSync.push({ fromBlock: i, toBlock: j, type }); eventsToSync.push({ address, fromBlock: i, toBlock: j, type });
} }
const events = []; const events = [];