Skip to content

Commit 090fad2

Browse files
committed
feat: add blockTimestamp to logs
Added to JSON-RPC in ethereum/execution-apis#639
1 parent b746c3c commit 090fad2

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src.ts/providers/format.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const _formatLog = object({
9595
address: getAddress,
9696
blockHash: formatHash,
9797
blockNumber: getNumber,
98+
blockTimestamp: allowNull(getNumber, undefined),
9899
data: formatData,
99100
index: getNumber,
100101
removed: allowNull(formatBoolean, false),
@@ -150,6 +151,7 @@ export function formatBlock(value: any): BlockParams {
150151
const _formatReceiptLog = object({
151152
transactionIndex: getNumber,
152153
blockNumber: getNumber,
154+
blockTimestamp: allowNull(getNumber, undefined),
153155
transactionHash: formatHash,
154156
address: getAddress,
155157
topics: arrayOf(formatHash),

src.ts/providers/formatting.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ export interface LogParams {
143143
*/
144144
blockNumber: number;
145145

146+
/**
147+
* The timestamp of the block that included the transaction for this
148+
* log.
149+
*/
150+
blockTimestamp?: number;
151+
146152
/**
147153
* Whether this log was removed due to the transaction it was included
148154
* in being removed dur to an orphaned block.
@@ -414,5 +420,3 @@ export interface TransactionResponseParams {
414420
*/
415421
authorizationList: null | Array<Authorization>;
416422
};
417-
418-

src.ts/providers/provider.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,12 @@ export class Log implements LogParams {
829829
*/
830830
readonly blockNumber!: number;
831831

832+
/**
833+
* The timestamp of the block that included the transaction for this
834+
* log.
835+
*/
836+
readonly blockTimestamp?: number;
837+
832838
/**
833839
* If the **Log** represents a block that was removed due to an orphaned
834840
* block, this will be true.
@@ -878,6 +884,7 @@ export class Log implements LogParams {
878884
transactionHash: log.transactionHash,
879885
blockHash: log.blockHash,
880886
blockNumber: log.blockNumber,
887+
blockTimestamp: log.blockTimestamp,
881888

882889
removed: log.removed,
883890

@@ -900,11 +907,17 @@ export class Log implements LogParams {
900907
removed, topics, transactionHash, transactionIndex
901908
} = this;
902909

903-
return {
910+
const result: any = {
904911
_type: "log",
905912
address, blockHash, blockNumber, data, index,
906913
removed, topics, transactionHash, transactionIndex
907914
};
915+
916+
if (this.blockTimestamp != null) {
917+
result.blockTimestamp = this.blockTimestamp;
918+
}
919+
920+
return result;
908921
}
909922

910923
/**

0 commit comments

Comments
 (0)