From 11e430cf2535a87de39a3cd6da6455b0df548970 Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:37:25 +0100 Subject: [PATCH 1/3] feat(rpc): add blockTimestamp to Log --- crates/rpc-types/src/eth/log.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/rpc-types/src/eth/log.rs b/crates/rpc-types/src/eth/log.rs index 59ad7500486..6726b8de9d4 100644 --- a/crates/rpc-types/src/eth/log.rs +++ b/crates/rpc-types/src/eth/log.rs @@ -14,6 +14,9 @@ pub struct Log { /// Number of the block the transaction that emitted this log was mined in #[serde(with = "alloy_serde::u64_hex_opt")] pub block_number: Option, + /// The timestamp of the block. + #[serde(skip_serializing_if = "Option::is_none", with = "alloy_serde::u64_hex_opt", default)] + pub block_timestamp: Option, /// Transaction Hash pub transaction_hash: Option, /// Index of the Transaction in the block @@ -59,6 +62,7 @@ impl Log { 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, @@ -80,6 +84,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, @@ -130,6 +135,7 @@ mod tests { }, block_hash: Some(B256::with_last_byte(0x69)), block_number: Some(0x69), + block_timestamp: Some(0x69), transaction_hash: Some(B256::with_last_byte(0x69)), transaction_index: Some(0x69), log_index: Some(0x69), @@ -138,7 +144,7 @@ mod tests { let serialized = serde_json::to_string(&log).unwrap(); assert_eq!( serialized, - r#"{"address":"0x0000000000000000000000000000000000000069","topics":["0x0000000000000000000000000000000000000000000000000000000000000069"],"data":"0x69","blockHash":"0x0000000000000000000000000000000000000000000000000000000000000069","blockNumber":"0x69","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000069","transactionIndex":"0x69","logIndex":"0x69","removed":false}"# + 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(); From 231d063d856c3308af4afa587baf4434f0b022d8 Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Sun, 31 Mar 2024 00:50:17 +0100 Subject: [PATCH 2/3] fix: add links to blockTimestamp field --- crates/rpc-types/src/eth/log.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/rpc-types/src/eth/log.rs b/crates/rpc-types/src/eth/log.rs index 6726b8de9d4..23eeaba3368 100644 --- a/crates/rpc-types/src/eth/log.rs +++ b/crates/rpc-types/src/eth/log.rs @@ -14,7 +14,9 @@ pub struct Log { /// Number of the block the transaction that emitted this log was mined in #[serde(with = "alloy_serde::u64_hex_opt")] pub block_number: Option, - /// The timestamp of the block. + /// 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, /// Transaction Hash From 9f3577bfdd1d9a37341eab082760c441202b6f93 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 31 Mar 2024 13:22:35 +0200 Subject: [PATCH 3/3] add test --- crates/rpc-types/src/eth/log.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/rpc-types/src/eth/log.rs b/crates/rpc-types/src/eth/log.rs index 23eeaba3368..be294bdcade 100644 --- a/crates/rpc-types/src/eth/log.rs +++ b/crates/rpc-types/src/eth/log.rs @@ -15,8 +15,8 @@ pub struct Log { #[serde(with = "alloy_serde::u64_hex_opt")] pub block_number: Option, /// 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, /// Transaction Hash @@ -127,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( @@ -137,13 +137,23 @@ mod tests { }, block_hash: Some(B256::with_last_byte(0x69)), block_number: Some(0x69), - block_timestamp: Some(0x69), + block_timestamp: None, transaction_hash: Some(B256::with_last_byte(0x69)), transaction_index: Some(0x69), log_index: Some(0x69), removed: false, }; let serialized = serde_json::to_string(&log).unwrap(); + assert_eq!( + serialized, + r#"{"address":"0x0000000000000000000000000000000000000069","topics":["0x0000000000000000000000000000000000000000000000000000000000000069"],"data":"0x69","blockHash":"0x0000000000000000000000000000000000000000000000000000000000000069","blockNumber":"0x69","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000069","transactionIndex":"0x69","logIndex":"0x69","removed":false}"# + ); + + 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}"#