Skip to content

Commit c879c40

Browse files
committed
add timeStamp to log object
1 parent 01bd77f commit c879c40

File tree

11 files changed

+49
-20
lines changed

11 files changed

+49
-20
lines changed

changelogs/JSONRPC.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# JSON-RPC CHANGELOG
22

3+
## v3.0.2
4+
5+
1. eSpace `log` object add `blockTimestamp` field.
6+
37
## v3.0.0
48

59
Below RPC add support for EIP-7702 tx:

crates/cfxcore/core/src/consensus/consensus_graph/rpc_api/trace_provider.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ impl ConsensusGraph {
5656

5757
fn filter_block_receipts<'a>(
5858
&self, filter: &'a LogFilter, epoch_number: u64, block_hash: H256,
59-
mut receipts: Vec<Receipt>, mut tx_hashes: Vec<H256>,
59+
block_timestamp: Option<u64>, mut receipts: Vec<Receipt>,
60+
mut tx_hashes: Vec<H256>,
6061
) -> impl Iterator<Item = LocalizedLogEntry> + 'a {
6162
// sanity check
6263
if receipts.len() != tx_hashes.len() {
@@ -97,6 +98,7 @@ impl ConsensusGraph {
9798
entry: log,
9899
block_hash,
99100
epoch_number,
101+
block_timestamp,
100102
transaction_hash,
101103
// iterating in reverse order
102104
transaction_index: receipts_len - index - 1,
@@ -166,6 +168,7 @@ impl ConsensusGraph {
166168
&filter,
167169
epoch,
168170
block_hash,
171+
Some(block.block_header.timestamp()),
169172
receipts,
170173
block.transaction_hashes(/* space filter */ None),
171174
)))
@@ -225,6 +228,7 @@ impl ConsensusGraph {
225228
&filter,
226229
epoch,
227230
pivot_hash,
231+
Some(pb.pivot_header.timestamp()),
228232
pb.receipts,
229233
pb.transactions.iter().map(|t| t.hash()).collect(),
230234
)))

crates/cfxcore/core/src/light_protocol/query_service.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,9 @@ impl QueryService {
684684
/// NOTE: `log.transaction_hash` is not known at this point,
685685
/// so this field has to be filled later on.
686686
fn filter_receipt_logs(
687-
epoch: u64, block_hash: H256, transaction_index: usize,
688-
num_logs_remaining: &mut usize, mut logs: Vec<LogEntry>,
689-
filter: LogFilter,
687+
epoch: u64, block_hash: H256, block_timestamp: Option<u64>,
688+
transaction_index: usize, num_logs_remaining: &mut usize,
689+
mut logs: Vec<LogEntry>, filter: LogFilter,
690690
) -> impl Iterator<Item = LocalizedLogEntry> {
691691
let num_logs = logs.len();
692692

@@ -702,6 +702,7 @@ impl QueryService {
702702
.map(move |(ii, entry)| LocalizedLogEntry {
703703
block_hash,
704704
epoch_number: epoch,
705+
block_timestamp,
705706
entry,
706707
log_index: log_base_index - ii - 1,
707708
transaction_hash: KECCAK_EMPTY_BLOOM, // will fill in later
@@ -731,6 +732,7 @@ impl QueryService {
731732
Self::filter_receipt_logs(
732733
epoch,
733734
hash,
735+
None,
734736
num_receipts - ii - 1,
735737
&mut remaining,
736738
logs,

crates/client/src/rpc/impls/cfx/cfx_filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ fn retrieve_epoch_logs(
630630
entry,
631631
block_hash,
632632
epoch_number,
633+
block_timestamp: Some(block.block_header.timestamp()),
633634
transaction_hash: tx.hash,
634635
transaction_index: txid,
635636
log_index,

crates/client/src/rpc/impls/cfx/pubsub.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ impl ChainNotificationHandler {
489489
entry,
490490
block_hash,
491491
epoch_number,
492+
block_timestamp: Some(block.block_header.timestamp()),
492493
transaction_hash: tx.hash,
493494
transaction_index: txid,
494495
log_index,

crates/primitives/src/log_entry.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ pub struct LocalizedLogEntry {
105105
pub block_hash: H256,
106106
/// Epoch number.
107107
pub epoch_number: BlockNumber,
108+
/// Timestamp of the block in which this log was created.
109+
pub block_timestamp: Option<u64>,
108110
/// Hash of transaction in which this log was created.
109111
pub transaction_hash: H256,
110112
/// Index of transaction within block.

crates/rpc/rpc-eth-impl/src/eth.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use cfx_rpc_eth_types::{
1313
AccessListResult, AccountOverride, AccountPendingTransactions, Block,
1414
BlockNumber as BlockId, BlockOverrides, Bundle, Error, EthCallResponse,
1515
EthRpcLogFilter, EthRpcLogFilter as Filter, EvmOverrides, FeeHistory,
16-
Header, Log, Receipt, RpcStateOverride, SimulatePayload, SimulatedBlock,
17-
StateContext, SyncInfo, SyncStatus, Transaction, TransactionRequest,
16+
Header, Log, LogData, Receipt, RpcStateOverride, SimulatePayload,
17+
SimulatedBlock, StateContext, SyncInfo, SyncStatus, Transaction,
18+
TransactionRequest,
1819
};
1920
use cfx_rpc_primitives::{Bytes, Index, U64 as HexU64};
2021
use cfx_rpc_utils::{
@@ -355,13 +356,16 @@ impl EthApi {
355356
.cloned()
356357
.enumerate()
357358
.map(|(idx, log)| Log {
358-
address: log.address,
359-
topics: log.topics,
360-
data: Bytes(log.data),
359+
inner: LogData {
360+
address: log.address,
361+
topics: log.topics,
362+
data: log.data.into(),
363+
},
361364
block_hash,
362365
block_number: block_height,
363366
transaction_hash,
364367
transaction_index,
368+
block_timestamp: Some(b.pivot_header.timestamp().into()),
365369
log_index: Some((*prior_log_index + idx).into()),
366370
transaction_log_index: Some(idx.into()),
367371
removed: false,

crates/rpc/rpc-eth-impl/src/helpers/eth_filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl EthFilterHelper {
161161
entry,
162162
block_hash: pivot,
163163
epoch_number,
164+
block_timestamp: Some(pb.pivot_header.timestamp()),
164165
transaction_hash: tx.hash,
165166
transaction_index: txid,
166167
log_index,

crates/rpc/rpc-eth-impl/src/pubsub.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ impl ChainDataProvider {
519519
entry,
520520
block_hash: pivot,
521521
epoch_number,
522+
block_timestamp: Some(pb.pivot_header.timestamp()),
522523
transaction_hash: tx.hash,
523524
transaction_index: txid,
524525
log_index,

crates/rpc/rpc-eth-types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub use errors::Error;
2828
pub use eth_pubsub::*;
2929
pub use fee_history::FeeHistory;
3030
pub use filter::*;
31-
pub use log::Log;
31+
pub use log::*;
3232
pub use receipt::Receipt;
3333
pub use simulate::*;
3434
pub use state::{

0 commit comments

Comments
 (0)