[Blockchain Watcher] (FIX) Add logs for evm source events (#1316)

* Add chain in EvmLog entity

* Add new log for evm source events

---------

Co-authored-by: julian merlo <julianmerlo@julians-MacBook-Pro.local>
This commit is contained in:
Julian 2024-04-17 17:09:33 -03:00 committed by GitHub
parent b34beb63df
commit 10df6821c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 28 additions and 10 deletions

View File

@ -54,13 +54,13 @@ export class PollWormchain extends RunPollingJob {
}
protected async get(): Promise<any[]> {
const latestBlockHeight = await this.blockRepo.getBlockHeight();
this.latestBlockHeight = await this.blockRepo.getBlockHeight();
if (!latestBlockHeight) {
throw new Error(`Could not obtain latest block height: ${latestBlockHeight}`);
if (!this.latestBlockHeight) {
throw new Error(`Could not obtain latest block height: ${this.latestBlockHeight}`);
}
const range = this.getBlockRange(latestBlockHeight);
const range = this.getBlockRange(this.latestBlockHeight);
const records = await this.getWormchain.execute(range, {
addresses: this.cfg.addresses,

View File

@ -17,6 +17,7 @@ export type EvmLog = {
topics: string[];
logIndex: number;
chainId: number;
chain: string;
};
export type EvmTransaction = {

View File

@ -1,5 +1,8 @@
import { BigNumber } from "ethers";
import { EvmLog, LogFoundEvent, LogMessagePublished } from "../../../domain/entities";
import { BigNumber } from "ethers";
import winston from "winston";
let logger: winston.Logger = winston.child({ module: "evmLogMessagePublishedMapper" });
export const evmLogMessagePublishedMapper = (
log: EvmLog,
@ -9,18 +12,27 @@ export const evmLogMessagePublishedMapper = (
throw new Error(`Block time is missing for log ${log.logIndex} in tx ${log.transactionHash}`);
}
const chainId = log.chainId;
const txHash = log.transactionHash;
const sender = parsedArgs[0];
const sequence = (parsedArgs[1] as BigNumber).toNumber();
logger.info(
`[${log.chain}] Source event info: [tx: ${txHash}][emitterChain: ${chainId}][sender: ${sender}}][sequence: ${sequence}]`
);
return {
name: "log-message-published",
address: log.address,
chainId: log.chainId,
txHash: log.transactionHash,
chainId: chainId,
txHash: txHash,
blockHeight: log.blockNumber,
blockTime: log.blockTime,
attributes: {
sender: parsedArgs[0], // log.topics[1]
sequence: (parsedArgs[1] as BigNumber).toNumber(),
payload: parsedArgs[3],
sender: sender, // log.topics[1]
sequence: sequence,
nonce: parsedArgs[2],
payload: parsedArgs[3],
consistencyLevel: parsedArgs[4],
},
};

View File

@ -187,6 +187,7 @@ export class EvmJsonRPCBlockRepository implements EvmBlockRepository {
blockNumber: BigInt(log.blockNumber),
transactionIndex: log.transactionIndex.toString(),
chainId: chainCfg.chainId,
chain,
}))
: [];
}

View File

@ -385,6 +385,7 @@ const givenEvmBlockRepository = (
topics: [],
logIndex: 0,
chainId: 2,
chain: "ethereum",
});
}
}

View File

@ -111,6 +111,7 @@ const givenEvmLogs = (length: number, matchingFilterOnes: number) => {
: [],
logIndex: 0,
chainId: 2,
chain: "ethereum",
});
}
};

View File

@ -121,6 +121,7 @@ const givenEvmBlockRepository = (height?: bigint, blocksAhead?: bigint) => {
topics: [],
logIndex: 0,
chainId: 2,
chain: "ethereum",
});
blocksResponse[`0x0${index}`] = {
timestamp: 0,

View File

@ -42,6 +42,7 @@ describe("evmLogMessagePublished", () => {
topics: [topic, "0x0000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585"],
logIndex: 0,
chainId: 2,
chain: "ethereum",
},
]);