Update getLogs API usage (#195)

* Update client query to get logs

* Update calls to get logs for contracts
This commit is contained in:
prathamesh0 2022-10-05 15:15:00 +05:30 committed by GitHub
parent 18861eaf79
commit 978f0bb456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 68 deletions

View File

@ -760,22 +760,16 @@ export class Indexer implements IPLDIndexerInterface {
console.time('time:indexer#_fetchAndSaveEvents-fetch-logs');
if (this._serverConfig.filterLogs) {
const watchedContracts = this._baseIndexer.getWatchedContracts();
const addresses = watchedContracts.map((watchedContract): string => {
return watchedContract.address;
});
// TODO: Query logs by multiple contracts.
const contractlogsPromises = watchedContracts.map((watchedContract): Promise<any> => this._ethClient.getLogs({
const logsResult = await this._ethClient.getLogs({
blockHash,
contract: watchedContract.address
}));
addresses
});
const contractlogs = await Promise.all(contractlogsPromises);
// Flatten logs by contract and sort by index.
logs = contractlogs.map(data => {
return data.logs;
}).flat()
.sort((a, b) => {
return a.index - b.index;
});
logs = logsResult.logs;
} else {
({ logs } = await this._ethClient.getLogs({ blockHash }));
}

View File

@ -1014,22 +1014,16 @@ export class Indexer implements IPLDIndexerInterface {
console.time('time:indexer#_fetchAndSaveEvents-fetch-logs');
if (this._serverConfig.filterLogs) {
const watchedContracts = this._baseIndexer.getWatchedContracts();
const addresses = watchedContracts.map((watchedContract): string => {
return watchedContract.address;
});
// TODO: Query logs by multiple contracts.
const contractlogsPromises = watchedContracts.map((watchedContract): Promise<any> => this._ethClient.getLogs({
const logsResult = await this._ethClient.getLogs({
blockHash,
contract: watchedContract.address
}));
addresses
});
const contractlogs = await Promise.all(contractlogsPromises);
// Flatten logs by contract and sort by index.
logs = contractlogs.map(data => {
return data.logs;
}).flat()
.sort((a, b) => {
return a.index - b.index;
});
logs = logsResult.logs;
} else {
({ logs } = await this._ethClient.getLogs({ blockHash }));
}

View File

@ -992,22 +992,16 @@ export class Indexer implements IPLDIndexerInterface {
console.time('time:indexer#_fetchAndSaveEvents-fetch-logs');
if (this._serverConfig.filterLogs) {
const watchedContracts = this._baseIndexer.getWatchedContracts();
const addresses = watchedContracts.map((watchedContract): string => {
return watchedContract.address;
});
// TODO: Query logs by multiple contracts.
const contractlogsPromises = watchedContracts.map((watchedContract): Promise<any> => this._ethClient.getLogs({
const logsResult = await this._ethClient.getLogs({
blockHash,
contract: watchedContract.address
}));
addresses
});
const contractlogs = await Promise.all(contractlogsPromises);
// Flatten logs by contract and sort by index.
logs = contractlogs.map(data => {
return data.logs;
}).flat()
.sort((a, b) => {
return a.index - b.index;
});
logs = logsResult.logs;
} else {
({ logs } = await this._ethClient.getLogs({ blockHash }));
}

View File

@ -714,22 +714,16 @@ export class Indexer implements IPLDIndexerInterface {
console.time('time:indexer#_fetchAndSaveEvents-fetch-logs');
if (this._serverConfig.filterLogs) {
const watchedContracts = this._baseIndexer.getWatchedContracts();
const addresses = watchedContracts.map((watchedContract): string => {
return watchedContract.address;
});
// TODO: Query logs by multiple contracts.
const contractlogsPromises = watchedContracts.map((watchedContract): Promise<any> => this._ethClient.getLogs({
const logsResult = await this._ethClient.getLogs({
blockHash,
contract: watchedContract.address
}));
addresses
});
const contractlogs = await Promise.all(contractlogsPromises);
// Flatten logs by contract and sort by index.
logs = contractlogs.map(data => {
return data.logs;
}).flat()
.sort((a, b) => {
return a.index - b.index;
});
logs = logsResult.logs;
} else {
({ logs } = await this._ethClient.getLogs({ blockHash }));
}

View File

@ -18,6 +18,7 @@ interface Vars {
blockHash: string;
contract?: string;
slot?: string;
addresses?: string[];
}
export class EthClient {

View File

@ -15,8 +15,8 @@ query getStorageAt($blockHash: Bytes32!, $contract: Address!, $slot: Bytes32!) {
`;
export const getLogs = gql`
query getLogs($blockHash: Bytes32!, $contract: Address) {
getLogs(blockHash: $blockHash, contract: $contract) {
query getLogs($blockHash: Bytes32!, $addresses: [Address!]) {
getLogs(blockHash: $blockHash, addresses: $addresses) {
account {
address
}

View File

@ -85,7 +85,7 @@ export class Indexer {
const contract = this._config.watch.lighthouse;
const [{ logs }, { block }] = await Promise.all([
this._ethClient.getLogs({ blockHash, contract }),
this._ethClient.getLogs({ blockHash, addresses: [contract] }),
this._ethClient.getBlockByHash(blockHash)
]);

View File

@ -736,22 +736,16 @@ export class Indexer implements IPLDIndexerInterface {
console.time('time:indexer#_fetchAndSaveEvents-fetch-logs');
if (this._serverConfig.filterLogs) {
const watchedContracts = this._baseIndexer.getWatchedContracts();
const addresses = watchedContracts.map((watchedContract): string => {
return watchedContract.address;
});
// TODO: Query logs by multiple contracts.
const contractlogsPromises = watchedContracts.map((watchedContract): Promise<any> => this._ethClient.getLogs({
const logsResult = await this._ethClient.getLogs({
blockHash,
contract: watchedContract.address
}));
addresses
});
const contractlogs = await Promise.all(contractlogsPromises);
// Flatten logs by contract and sort by index.
logs = contractlogs.map(data => {
return data.logs;
}).flat()
.sort((a, b) => {
return a.index - b.index;
});
logs = logsResult.logs;
} else {
({ logs } = await this._ethClient.getLogs({ blockHash }));
}