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
|
parentHash
|
||||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||||
assert(blockHash);
|
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();
|
const dbTx = await this._db.createTransactionRunner();
|
||||||
try {
|
try {
|
||||||
|
@ -893,8 +893,9 @@ export class Indexer implements IndexerInterface {
|
|||||||
parentHash
|
parentHash
|
||||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||||
assert(blockHash);
|
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();
|
const dbTx = await this._db.createTransactionRunner();
|
||||||
try {
|
try {
|
||||||
|
@ -442,8 +442,9 @@ export class Indexer implements IndexerInterface {
|
|||||||
parentHash
|
parentHash
|
||||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||||
assert(blockHash);
|
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();
|
const dbTx = await this._db.createTransactionRunner();
|
||||||
try {
|
try {
|
||||||
|
@ -890,8 +890,9 @@ export class Indexer implements IndexerInterface {
|
|||||||
parentHash
|
parentHash
|
||||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||||
assert(blockHash);
|
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();
|
const dbTx = await this._db.createTransactionRunner();
|
||||||
try {
|
try {
|
||||||
|
@ -138,7 +138,7 @@ export class GraphWatcher {
|
|||||||
assert(blockData);
|
assert(blockData);
|
||||||
|
|
||||||
assert(this._indexer && this._indexer.isWatchedContract);
|
assert(this._indexer && this._indexer.isWatchedContract);
|
||||||
const watchedContract = await this._indexer.isWatchedContract(contract);
|
const watchedContract = this._indexer.isWatchedContract(contract);
|
||||||
assert(watchedContract);
|
assert(watchedContract);
|
||||||
|
|
||||||
// Get dataSource in subgraph yaml based on contract address.
|
// Get dataSource in subgraph yaml based on contract address.
|
||||||
@ -174,7 +174,7 @@ export class GraphWatcher {
|
|||||||
|
|
||||||
const eventFragment = contractInterface.getEvent(eventSignature);
|
const eventFragment = contractInterface.getEvent(eventSignature);
|
||||||
|
|
||||||
const tx = await this._getTransactionData(txHash);
|
const tx = await this._getTransactionData(txHash, Number(blockData.blockNumber));
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
block: blockData,
|
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);
|
let transaction = this._transactionsMap.get(txHash);
|
||||||
|
|
||||||
if (transaction) {
|
if (transaction) {
|
||||||
return transaction;
|
return transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction = await getFullTransaction(this._ethClient, txHash);
|
transaction = await getFullTransaction(this._ethClient, txHash, blockNumber);
|
||||||
assert(transaction);
|
assert(transaction);
|
||||||
this._transactionsMap.set(txHash, transaction);
|
this._transactionsMap.set(txHash, transaction);
|
||||||
|
|
||||||
|
@ -598,8 +598,9 @@ export class Indexer implements IndexerInterface {
|
|||||||
parentHash
|
parentHash
|
||||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||||
assert(blockHash);
|
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();
|
const dbTx = await this._db.createTransactionRunner();
|
||||||
try {
|
try {
|
||||||
|
@ -16,6 +16,7 @@ export interface Config extends GraphQLConfig {
|
|||||||
|
|
||||||
interface Vars {
|
interface Vars {
|
||||||
blockHash: string;
|
blockHash: string;
|
||||||
|
blockNumber?: string;
|
||||||
contract?: string;
|
contract?: string;
|
||||||
slot?: string;
|
slot?: string;
|
||||||
addresses?: string[];
|
addresses?: string[];
|
||||||
@ -106,15 +107,16 @@ export class EthClient {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFullTransaction (txHash: string): Promise<any> {
|
async getFullTransaction (txHash: string, blockNumber?: number): Promise<any> {
|
||||||
console.time(`time:eth-client#getFullTransaction-${txHash}`);
|
console.time(`time:eth-client#getFullTransaction-${JSON.stringify({ txHash, blockNumber })}`);
|
||||||
const result = this._graphqlClient.query(
|
const result = this._graphqlClient.query(
|
||||||
ethQueries.getFullTransaction,
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ query getStorageAt($blockHash: Bytes32!, $contract: Address!, $slot: Bytes32!) {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const getLogs = gql`
|
export const getLogs = gql`
|
||||||
query getLogs($blockHash: Bytes32!, $addresses: [Address!]) {
|
query getLogs($blockHash: Bytes32!, $blockNumber: BigInt, $addresses: [Address!]) {
|
||||||
getLogs(blockHash: $blockHash, addresses: $addresses) {
|
getLogs(blockHash: $blockHash, blockNumber: $blockNumber, addresses: $addresses) {
|
||||||
account {
|
account {
|
||||||
address
|
address
|
||||||
}
|
}
|
||||||
@ -100,8 +100,8 @@ query allEthHeaderCids($blockNumber: BigInt, $blockHash: String) {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const getFullTransaction = gql`
|
export const getFullTransaction = gql`
|
||||||
query ethTransactionCidByTxHash($txHash: String!) {
|
query ethTransactionCidByTxHash($txHash: String!, $blockNumber: BigInt) {
|
||||||
ethTransactionCidByTxHash(txHash: $txHash) {
|
ethTransactionCidByTxHash(txHash: $txHash, blockNumber: $blockNumber) {
|
||||||
cid
|
cid
|
||||||
txHash
|
txHash
|
||||||
index
|
index
|
||||||
|
@ -82,7 +82,7 @@ export async function handleEvent (indexer: Indexer, eventData: ResultEvent): Pr
|
|||||||
|
|
||||||
// Perform indexing for PhisherStatusUpdated and MemberStatusUpdated.
|
// Perform indexing for PhisherStatusUpdated and MemberStatusUpdated.
|
||||||
if (['PhisherStatusUpdatedEvent', 'MemberStatusUpdatedEvent'].includes(eventData.event.__typename)) {
|
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);
|
const txDescription = getTxDescription(indexer, KIND_PHISHERREGISTRY, txData.input);
|
||||||
let txDescriptions = [txDescription];
|
let txDescriptions = [txDescription];
|
||||||
|
|
||||||
|
@ -598,8 +598,8 @@ export class Indexer implements IndexerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get full transaction data.
|
// Get full transaction data.
|
||||||
async getFullTransaction (txHash: string): Promise<any> {
|
async getFullTransaction (txHash: string, blockNumber: number): Promise<any> {
|
||||||
return getFullTransaction(this._ethClient, txHash);
|
return getFullTransaction(this._ethClient, txHash, blockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get contract interface for specified contract kind.
|
// Get contract interface for specified contract kind.
|
||||||
@ -620,8 +620,9 @@ export class Indexer implements IndexerInterface {
|
|||||||
parentHash
|
parentHash
|
||||||
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
}: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
|
||||||
assert(blockHash);
|
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();
|
const dbTx = await this._db.createTransactionRunner();
|
||||||
try {
|
try {
|
||||||
|
@ -273,7 +273,7 @@ export class Indexer {
|
|||||||
return [blockProgress, events];
|
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>;
|
let logsPromise: Promise<any>;
|
||||||
|
|
||||||
if (this._serverConfig.filterLogs) {
|
if (this._serverConfig.filterLogs) {
|
||||||
@ -284,13 +284,14 @@ export class Indexer {
|
|||||||
|
|
||||||
logsPromise = this._ethClient.getLogs({
|
logsPromise = this._ethClient.getLogs({
|
||||||
blockHash,
|
blockHash,
|
||||||
|
blockNumber: blockNumber.toString(),
|
||||||
addresses
|
addresses
|
||||||
});
|
});
|
||||||
} else {
|
} 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 [
|
const [
|
||||||
{ logs },
|
{ 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 {
|
const {
|
||||||
ethTransactionCidByTxHash: fullTx
|
ethTransactionCidByTxHash: fullTx
|
||||||
} = await ethClient.getFullTransaction(txHash);
|
} = await ethClient.getFullTransaction(txHash, blockNumber);
|
||||||
|
|
||||||
assert(fullTx.blockByMhKey);
|
assert(fullTx.blockByMhKey);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user