Skip to content

Commit b4998b5

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

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export interface TransactionRequest {
203203
/**
204204
* When using ``call`` or ``estimateGas``, this allows a specific
205205
* block to be queried. Many backends do not support this and when
206-
* unsupported errors are silently squelched and ``"latest"`` is used.
206+
* unsupported errors are silently squelched and ``"latest"`` is used.
207207
*/
208208
blockTag?: BlockTag;
209209

@@ -349,7 +349,7 @@ export interface PreparedTransactionRequest {
349349
/**
350350
* When using ``call`` or ``estimateGas``, this allows a specific
351351
* block to be queried. Many backends do not support this and when
352-
* unsupported errors are silently squelched and ``"latest"`` is used.
352+
* unsupported errors are silently squelched and ``"latest"`` is used.
353353
*/
354354
blockTag?: BlockTag;
355355

@@ -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

@@ -896,13 +903,13 @@ export class Log implements LogParams {
896903
*/
897904
toJSON(): any {
898905
const {
899-
address, blockHash, blockNumber, data, index,
906+
address, blockHash, blockNumber, blockTimestamp, data, index,
900907
removed, topics, transactionHash, transactionIndex
901908
} = this;
902909

903910
return {
904911
_type: "log",
905-
address, blockHash, blockNumber, data, index,
912+
address, blockHash, blockNumber, blockTimestamp, data, index,
906913
removed, topics, transactionHash, transactionIndex
907914
};
908915
}
@@ -1134,14 +1141,14 @@ export class TransactionReceipt implements TransactionReceiptParams, Iterable<Lo
11341141
const {
11351142
to, from, contractAddress, hash, index,
11361143
blockHash, blockNumber, logsBloom,
1137-
logs, //byzantium,
1144+
logs, //byzantium,
11381145
status, root
11391146
} = this;
11401147

11411148
return {
11421149
_type: "TransactionReceipt",
11431150
blockHash, blockNumber,
1144-
//byzantium,
1151+
//byzantium,
11451152
contractAddress,
11461153
cumulativeGasUsed: toJson(this.cumulativeGasUsed),
11471154
from,

0 commit comments

Comments
 (0)