Skip to content
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

feat(rpc): add blockTimestamp to Log #429

Merged
merged 3 commits into from
Apr 1, 2024
Merged
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
20 changes: 19 additions & 1 deletion crates/rpc-types/src/eth/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ pub struct Log<T = LogData> {
/// Number of the block the transaction that emitted this log was mined in
#[serde(with = "alloy_serde::u64_hex_opt")]
pub block_number: Option<u64>,
/// The timestamp of the block as proposed in:
/// <https://ethereum-magicians.org/t/proposal-for-adding-blocktimestamp-to-logs-object-returned-by-eth-getlogs-and-related-requests>
/// <https://github.com/ethereum/execution-apis/issues/295>
#[serde(skip_serializing_if = "Option::is_none", with = "alloy_serde::u64_hex_opt", default)]
pub block_timestamp: Option<u64>,
/// Transaction Hash
pub transaction_hash: Option<B256>,
/// Index of the Transaction in the block
Expand Down Expand Up @@ -59,6 +64,7 @@ impl Log<LogData> {
inner: decoded,
block_hash: self.block_hash,
block_number: self.block_number,
block_timestamp: self.block_timestamp,
transaction_hash: self.transaction_hash,
transaction_index: self.transaction_index,
log_index: self.log_index,
Expand All @@ -80,6 +86,7 @@ where
},
block_hash: self.block_hash,
block_number: self.block_number,
block_timestamp: self.block_timestamp,
transaction_hash: self.transaction_hash,
transaction_index: self.transaction_index,
log_index: self.log_index,
Expand Down Expand Up @@ -120,7 +127,7 @@ mod tests {

#[test]
fn serde_log() {
let log = Log {
let mut log = Log {
inner: alloy_primitives::Log {
address: Address::with_last_byte(0x69),
data: alloy_primitives::LogData::new_unchecked(
Expand All @@ -130,6 +137,7 @@ mod tests {
},
block_hash: Some(B256::with_last_byte(0x69)),
block_number: Some(0x69),
block_timestamp: None,
transaction_hash: Some(B256::with_last_byte(0x69)),
transaction_index: Some(0x69),
log_index: Some(0x69),
Expand All @@ -143,5 +151,15 @@ mod tests {

let deserialized: Log = serde_json::from_str(&serialized).unwrap();
assert_eq!(log, deserialized);

log.block_timestamp = Some(0x69);
let serialized = serde_json::to_string(&log).unwrap();
assert_eq!(
serialized,
r#"{"address":"0x0000000000000000000000000000000000000069","topics":["0x0000000000000000000000000000000000000000000000000000000000000069"],"data":"0x69","blockHash":"0x0000000000000000000000000000000000000000000000000000000000000069","blockNumber":"0x69","blockTimestamp":"0x69","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000069","transactionIndex":"0x69","logIndex":"0x69","removed":false}"#
);

let deserialized: Log = serde_json::from_str(&serialized).unwrap();
assert_eq!(log, deserialized);
}
}
Loading