Skip to content

Extend Log type with optional timestamp property #5012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src.ts/providers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const _formatLog = object({
topics: arrayOf(formatHash),
transactionHash: formatHash,
transactionIndex: getNumber,
timestamp: allowNull(getNumber),
}, {
index: [ "logIndex" ]
});
Expand Down Expand Up @@ -156,6 +157,7 @@ const _formatReceiptLog = object({
data: formatData,
index: getNumber,
blockHash: formatHash,
timestamp: allowNull(getNumber),
}, {
index: [ "logIndex" ]
});
Expand Down
7 changes: 7 additions & 0 deletions src.ts/providers/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
12 changes: 10 additions & 2 deletions src.ts/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*/
Expand All @@ -878,6 +885,7 @@ export class Log implements LogParams {

index: log.index,
transactionIndex: log.transactionIndex,
timestamp: log.timestamp,
});
}

Expand All @@ -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
};
}

Expand Down