Add option for no check in max events block range (#142)

This commit is contained in:
nikugogoi 2022-07-13 14:40:42 +05:30 committed by GitHub
parent 3cee10607e
commit 129b9e71f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 16 deletions

View File

@ -83,16 +83,16 @@ export async function handleEvent (indexer: Indexer, eventData: ResultEvent): Pr
// Perform indexing for PhisherStatusUpdated and MemberStatusUpdated.
if (['PhisherStatusUpdatedEvent', 'MemberStatusUpdatedEvent'].includes(eventData.event.__typename)) {
const txData = await indexer.getFullTransaction(eventData.tx.hash);
const tx = getTx(indexer, KIND_PHISHERREGISTRY, txData.input);
let txs = [tx];
const txDescription = getTxDescription(indexer, KIND_PHISHERREGISTRY, txData.input);
let txDescriptions = [txDescription];
if (tx.signature === INVOKE_SIGNATURE) {
if (txDescription.signature === INVOKE_SIGNATURE) {
// Parse transactions from batches if it is an invoke method in Delegatable contract.
txs = tx.args.signedInvocations
txDescriptions = txDescription.args.signedInvocations
.reduce((txs: utils.TransactionDescription[], signedInvocation: any) => {
// Get transactions from signed invocations batch.
const batchTxs = signedInvocation.invocations.batch.map((invocation: any) => {
return getTx(indexer, KIND_PHISHERREGISTRY, invocation.transaction.data);
return getTxDescription(indexer, KIND_PHISHERREGISTRY, invocation.transaction.data);
});
txs.push(...batchTxs);
@ -102,19 +102,19 @@ export async function handleEvent (indexer: Indexer, eventData: ResultEvent): Pr
}
// Filter transactions for claimIfMember and claimIsPhisher methods.
txs = txs.filter((tx: utils.TransactionDescription) => {
txDescriptions = txDescriptions.filter((tx: utils.TransactionDescription) => {
return [CLAIM_IF_MEMBER_SIGNATURE, CLAIM_IF_PHISHER_SIGNATURE].includes(tx.signature);
});
for (const tx of txs) {
switch (tx.signature) {
for (const txDescription of txDescriptions) {
switch (txDescription.signature) {
case CLAIM_IF_MEMBER_SIGNATURE:
// Update isMember entry for the identifier in database.
await indexer.isMember(eventData.block.hash, eventData.contract, tx.args.identifier, true);
await indexer.isMember(eventData.block.hash, eventData.contract, txDescription.args.identifier, true);
break;
case CLAIM_IF_PHISHER_SIGNATURE:
// Update isPhisher entry for the identifier in database.
await indexer.isPhisher(eventData.block.hash, eventData.contract, tx.args.identifier, true);
await indexer.isPhisher(eventData.block.hash, eventData.contract, txDescription.args.identifier, true);
break;
}
}
@ -122,7 +122,7 @@ export async function handleEvent (indexer: Indexer, eventData: ResultEvent): Pr
}
// Get transaction details from input data.
const getTx = (indexer: Indexer, contractKind: string, data: string): utils.TransactionDescription => {
const getTxDescription = (indexer: Indexer, contractKind: string, data: string): utils.TransactionDescription => {
const contractInterface = indexer.getContractInterface(contractKind);
assert(contractInterface);
return contractInterface.parseTransaction({ data });

View File

@ -50,6 +50,8 @@ const MEMBERSTATUSUPDATED_EVENT = 'MemberStatusUpdated';
const OWNERSHIPTRANSFERRED_EVENT = 'OwnershipTransferred';
const PHISHERSTATUSUPDATED_EVENT = 'PhisherStatusUpdated';
const MAX_EVENTS_BLOCK_RANGE = -1;
export type ResultEvent = {
block: {
cid: string;
@ -711,7 +713,7 @@ export class Indexer implements IPLDIndexerInterface {
}
async getEventsInRange (fromBlockNumber: number, toBlockNumber: number): Promise<Array<Event>> {
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber);
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber, MAX_EVENTS_BLOCK_RANGE);
}
async getSyncStatus (): Promise<SyncStatus | undefined> {

View File

@ -15,7 +15,7 @@ import { UNKNOWN_EVENT_NAME, JOB_KIND_CONTRACT, QUEUE_EVENT_PROCESSING } from '.
import { JobQueue } from './job-queue';
import { Where, QueryOptions } from './database';
const MAX_EVENTS_BLOCK_RANGE = 1000;
const DEFAULT_MAX_EVENTS_BLOCK_RANGE = 1000;
const log = debug('vulcanize:indexer');
@ -292,13 +292,13 @@ export class Indexer {
return this._db.getProcessedBlockCountForRange(fromBlockNumber, toBlockNumber);
}
async getEventsInRange (fromBlockNumber: number, toBlockNumber: number): Promise<Array<EventInterface>> {
async getEventsInRange (fromBlockNumber: number, toBlockNumber: number, maxBlockRange: number = DEFAULT_MAX_EVENTS_BLOCK_RANGE): Promise<Array<EventInterface>> {
if (toBlockNumber <= fromBlockNumber) {
throw new Error('toBlockNumber should be greater than fromBlockNumber');
}
if ((toBlockNumber - fromBlockNumber) > MAX_EVENTS_BLOCK_RANGE) {
throw new Error(`Max range (${MAX_EVENTS_BLOCK_RANGE}) exceeded`);
if (maxBlockRange > -1 && (toBlockNumber - fromBlockNumber) > maxBlockRange) {
throw new Error(`Max range (${maxBlockRange}) exceeded`);
}
return this._db.getEventsInRange(fromBlockNumber, toBlockNumber);