From 5aaf4a173f89ba80aa56e7e5b6a8280bc287ab9f Mon Sep 17 00:00:00 2001 From: krikera Date: Sat, 28 Jun 2025 14:31:00 +0530 Subject: [PATCH] Extend Log type with optional timestamp property --- src.ts/providers/format.ts | 2 ++ src.ts/providers/formatting.ts | 7 +++++++ src.ts/providers/provider.ts | 12 ++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src.ts/providers/format.ts b/src.ts/providers/format.ts index 40720d1ef8..d1dbe9a100 100644 --- a/src.ts/providers/format.ts +++ b/src.ts/providers/format.ts @@ -101,6 +101,7 @@ const _formatLog = object({ topics: arrayOf(formatHash), transactionHash: formatHash, transactionIndex: getNumber, + timestamp: allowNull(getNumber), }, { index: [ "logIndex" ] }); @@ -156,6 +157,7 @@ const _formatReceiptLog = object({ data: formatData, index: getNumber, blockHash: formatHash, + timestamp: allowNull(getNumber), }, { index: [ "logIndex" ] }); diff --git a/src.ts/providers/formatting.ts b/src.ts/providers/formatting.ts index d5bd09da69..1a0ed9b288 100644 --- a/src.ts/providers/formatting.ts +++ b/src.ts/providers/formatting.ts @@ -173,6 +173,13 @@ export interface LogParams { * The transaction index of this log. */ transactionIndex: number; + + /** + * The timestamp of the block that included this log (optional). + * This is supported by newer versions of Geth as per updated + * eth_getLogs specification. + */ + timestamp?: number; } diff --git a/src.ts/providers/provider.ts b/src.ts/providers/provider.ts index 1e1e64bba4..5dc5e6f902 100644 --- a/src.ts/providers/provider.ts +++ b/src.ts/providers/provider.ts @@ -857,6 +857,13 @@ export class Log implements LogParams { */ readonly transactionIndex!: number; + /** + * The timestamp of the block that included this log (optional). + * This is supported by newer versions of Geth as per updated + * eth_getLogs specification. + */ + readonly timestamp?: number; + /** * @_ignore: */ @@ -878,6 +885,7 @@ export class Log implements LogParams { index: log.index, transactionIndex: log.transactionIndex, + timestamp: log.timestamp, }); } @@ -887,13 +895,13 @@ export class Log implements LogParams { toJSON(): any { const { address, blockHash, blockNumber, data, index, - removed, topics, transactionHash, transactionIndex + removed, topics, transactionHash, transactionIndex, timestamp } = this; return { _type: "log", address, blockHash, blockNumber, data, index, - removed, topics, transactionHash, transactionIndex + removed, topics, transactionHash, transactionIndex, timestamp }; }