mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-22 19:19:05 +00:00
Update getLogs
API usage (#195)
* Update client query to get logs * Update calls to get logs for contracts
This commit is contained in:
parent
18861eaf79
commit
978f0bb456
@ -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 }));
|
||||
}
|
||||
|
@ -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 }));
|
||||
}
|
||||
|
@ -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 }));
|
||||
}
|
||||
|
@ -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 }));
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ interface Vars {
|
||||
blockHash: string;
|
||||
contract?: string;
|
||||
slot?: string;
|
||||
addresses?: string[];
|
||||
}
|
||||
|
||||
export class EthClient {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
]);
|
||||
|
||||
|
@ -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 }));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user