mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-08 12:28:05 +00:00
Update GQL and getBlock API usage (#210)
* Update getLogs and getBlockWithTransactions usage to add block number arg * Update getFullTransaction usage to add block number arg
This commit is contained in:
parent
52c42f4e84
commit
2517f110ea
@ -656,8 +656,9 @@ export class Indexer implements IndexerInterface {
|
||||
parentHash
|
||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||
assert(blockHash);
|
||||
assert(blockNumber);
|
||||
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, this.parseEventNameAndArgs.bind(this));
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.parseEventNameAndArgs.bind(this));
|
||||
|
||||
const dbTx = await this._db.createTransactionRunner();
|
||||
try {
|
||||
|
@ -893,8 +893,9 @@ export class Indexer implements IndexerInterface {
|
||||
parentHash
|
||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||
assert(blockHash);
|
||||
assert(blockNumber);
|
||||
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, this.parseEventNameAndArgs.bind(this));
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.parseEventNameAndArgs.bind(this));
|
||||
|
||||
const dbTx = await this._db.createTransactionRunner();
|
||||
try {
|
||||
|
@ -442,8 +442,9 @@ export class Indexer implements IndexerInterface {
|
||||
parentHash
|
||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||
assert(blockHash);
|
||||
assert(blockNumber);
|
||||
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, this.parseEventNameAndArgs.bind(this));
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.parseEventNameAndArgs.bind(this));
|
||||
|
||||
const dbTx = await this._db.createTransactionRunner();
|
||||
try {
|
||||
|
@ -890,8 +890,9 @@ export class Indexer implements IndexerInterface {
|
||||
parentHash
|
||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||
assert(blockHash);
|
||||
assert(blockNumber);
|
||||
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, this.parseEventNameAndArgs.bind(this));
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.parseEventNameAndArgs.bind(this));
|
||||
|
||||
const dbTx = await this._db.createTransactionRunner();
|
||||
try {
|
||||
|
@ -138,7 +138,7 @@ export class GraphWatcher {
|
||||
assert(blockData);
|
||||
|
||||
assert(this._indexer && this._indexer.isWatchedContract);
|
||||
const watchedContract = await this._indexer.isWatchedContract(contract);
|
||||
const watchedContract = this._indexer.isWatchedContract(contract);
|
||||
assert(watchedContract);
|
||||
|
||||
// Get dataSource in subgraph yaml based on contract address.
|
||||
@ -174,7 +174,7 @@ export class GraphWatcher {
|
||||
|
||||
const eventFragment = contractInterface.getEvent(eventSignature);
|
||||
|
||||
const tx = await this._getTransactionData(txHash);
|
||||
const tx = await this._getTransactionData(txHash, Number(blockData.blockNumber));
|
||||
|
||||
const data = {
|
||||
block: blockData,
|
||||
@ -409,14 +409,14 @@ export class GraphWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
async _getTransactionData (txHash: string): Promise<Transaction> {
|
||||
async _getTransactionData (txHash: string, blockNumber: number): Promise<Transaction> {
|
||||
let transaction = this._transactionsMap.get(txHash);
|
||||
|
||||
if (transaction) {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
transaction = await getFullTransaction(this._ethClient, txHash);
|
||||
transaction = await getFullTransaction(this._ethClient, txHash, blockNumber);
|
||||
assert(transaction);
|
||||
this._transactionsMap.set(txHash, transaction);
|
||||
|
||||
|
@ -598,8 +598,9 @@ export class Indexer implements IndexerInterface {
|
||||
parentHash
|
||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||
assert(blockHash);
|
||||
assert(blockNumber);
|
||||
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, this.parseEventNameAndArgs.bind(this));
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.parseEventNameAndArgs.bind(this));
|
||||
|
||||
const dbTx = await this._db.createTransactionRunner();
|
||||
try {
|
||||
|
@ -16,6 +16,7 @@ export interface Config extends GraphQLConfig {
|
||||
|
||||
interface Vars {
|
||||
blockHash: string;
|
||||
blockNumber?: string;
|
||||
contract?: string;
|
||||
slot?: string;
|
||||
addresses?: string[];
|
||||
@ -106,15 +107,16 @@ export class EthClient {
|
||||
return result;
|
||||
}
|
||||
|
||||
async getFullTransaction (txHash: string): Promise<any> {
|
||||
console.time(`time:eth-client#getFullTransaction-${txHash}`);
|
||||
async getFullTransaction (txHash: string, blockNumber?: number): Promise<any> {
|
||||
console.time(`time:eth-client#getFullTransaction-${JSON.stringify({ txHash, blockNumber })}`);
|
||||
const result = this._graphqlClient.query(
|
||||
ethQueries.getFullTransaction,
|
||||
{
|
||||
txHash
|
||||
txHash,
|
||||
blockNumber: blockNumber?.toString()
|
||||
}
|
||||
);
|
||||
console.timeEnd(`time:eth-client#getFullTransaction-${txHash}`);
|
||||
console.timeEnd(`time:eth-client#getFullTransaction-${JSON.stringify({ txHash, blockNumber })}`);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ query getStorageAt($blockHash: Bytes32!, $contract: Address!, $slot: Bytes32!) {
|
||||
`;
|
||||
|
||||
export const getLogs = gql`
|
||||
query getLogs($blockHash: Bytes32!, $addresses: [Address!]) {
|
||||
getLogs(blockHash: $blockHash, addresses: $addresses) {
|
||||
query getLogs($blockHash: Bytes32!, $blockNumber: BigInt, $addresses: [Address!]) {
|
||||
getLogs(blockHash: $blockHash, blockNumber: $blockNumber, addresses: $addresses) {
|
||||
account {
|
||||
address
|
||||
}
|
||||
@ -100,8 +100,8 @@ query allEthHeaderCids($blockNumber: BigInt, $blockHash: String) {
|
||||
`;
|
||||
|
||||
export const getFullTransaction = gql`
|
||||
query ethTransactionCidByTxHash($txHash: String!) {
|
||||
ethTransactionCidByTxHash(txHash: $txHash) {
|
||||
query ethTransactionCidByTxHash($txHash: String!, $blockNumber: BigInt) {
|
||||
ethTransactionCidByTxHash(txHash: $txHash, blockNumber: $blockNumber) {
|
||||
cid
|
||||
txHash
|
||||
index
|
||||
|
@ -82,7 +82,7 @@ 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 txData = await indexer.getFullTransaction(eventData.tx.hash, eventData.block.number);
|
||||
const txDescription = getTxDescription(indexer, KIND_PHISHERREGISTRY, txData.input);
|
||||
let txDescriptions = [txDescription];
|
||||
|
||||
|
@ -598,8 +598,8 @@ export class Indexer implements IndexerInterface {
|
||||
}
|
||||
|
||||
// Get full transaction data.
|
||||
async getFullTransaction (txHash: string): Promise<any> {
|
||||
return getFullTransaction(this._ethClient, txHash);
|
||||
async getFullTransaction (txHash: string, blockNumber: number): Promise<any> {
|
||||
return getFullTransaction(this._ethClient, txHash, blockNumber);
|
||||
}
|
||||
|
||||
// Get contract interface for specified contract kind.
|
||||
@ -620,8 +620,9 @@ export class Indexer implements IndexerInterface {
|
||||
parentHash
|
||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||
assert(blockHash);
|
||||
assert(blockNumber);
|
||||
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, this.parseEventNameAndArgs.bind(this));
|
||||
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.parseEventNameAndArgs.bind(this));
|
||||
|
||||
const dbTx = await this._db.createTransactionRunner();
|
||||
try {
|
||||
|
@ -273,7 +273,7 @@ export class Indexer {
|
||||
return [blockProgress, events];
|
||||
}
|
||||
|
||||
async fetchEvents (blockHash: string, parseEventNameAndArgs: (kind: string, logObj: any) => any): Promise<DeepPartial<EventInterface>[]> {
|
||||
async fetchEvents (blockHash: string, blockNumber: number, parseEventNameAndArgs: (kind: string, logObj: any) => any): Promise<DeepPartial<EventInterface>[]> {
|
||||
let logsPromise: Promise<any>;
|
||||
|
||||
if (this._serverConfig.filterLogs) {
|
||||
@ -284,13 +284,14 @@ export class Indexer {
|
||||
|
||||
logsPromise = this._ethClient.getLogs({
|
||||
blockHash,
|
||||
blockNumber: blockNumber.toString(),
|
||||
addresses
|
||||
});
|
||||
} else {
|
||||
logsPromise = this._ethClient.getLogs({ blockHash });
|
||||
logsPromise = this._ethClient.getLogs({ blockHash, blockNumber: blockNumber.toString() });
|
||||
}
|
||||
|
||||
const transactionsPromise = this._ethClient.getBlockWithTransactions({ blockHash });
|
||||
const transactionsPromise = this._ethClient.getBlockWithTransactions({ blockHash, blockNumber });
|
||||
|
||||
const [
|
||||
{ logs },
|
||||
|
@ -220,10 +220,10 @@ export const getFullBlock = async (ethClient: EthClient, ethProvider: providers.
|
||||
};
|
||||
};
|
||||
|
||||
export const getFullTransaction = async (ethClient: EthClient, txHash: string): Promise<any> => {
|
||||
export const getFullTransaction = async (ethClient: EthClient, txHash: string, blockNumber: number): Promise<any> => {
|
||||
const {
|
||||
ethTransactionCidByTxHash: fullTx
|
||||
} = await ethClient.getFullTransaction(txHash);
|
||||
} = await ethClient.getFullTransaction(txHash, blockNumber);
|
||||
|
||||
assert(fullTx.blockByMhKey);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user