cfx_rpc/traits/
filterable.rs

1use crate::helpers::{poll_filter::SyncPollFilter, poll_manager::PollManager};
2use cfx_rpc_eth_types::{EthRpcLogFilter, Log};
3use cfx_types::H256;
4use cfxcore::{ConsensusGraph, SharedConsensusGraph};
5use jsonrpc_core::Result as RpcResult;
6use parking_lot::Mutex;
7use primitives::{filter::LogFilter, EpochNumber};
8use std::collections::{BTreeSet, VecDeque};
9
10pub trait Filterable {
11    /// Current best epoch number.
12    fn best_executed_epoch_number(&self) -> u64;
13
14    /// Get a block hash by block id.
15    fn block_hashes(&self, epoch_num: EpochNumber) -> Option<Vec<H256>>;
16
17    /// pending transaction hashes at the given block (unordered).
18    fn pending_transaction_hashes(&self) -> BTreeSet<H256>;
19
20    /// Get logs that match the given filter.
21    fn logs(&self, filter: LogFilter) -> RpcResult<Vec<Log>>;
22
23    /// Get logs that match the given filter for specific epoch
24    fn logs_for_epoch(
25        &self, filter: &LogFilter, epoch: (u64, Vec<H256>), removed: bool,
26    ) -> RpcResult<Vec<Log>>;
27
28    /// Get a reference to the poll manager.
29    fn polls(&self) -> &Mutex<PollManager<SyncPollFilter<Log>>>;
30
31    /// Get a reference to ConsensusGraph
32    fn consensus_graph(&self) -> &ConsensusGraph;
33
34    /// Get a clone of SharedConsensusGraph
35    fn shared_consensus_graph(&self) -> SharedConsensusGraph;
36
37    /// Get logs limitation
38    fn get_logs_filter_max_limit(&self) -> Option<usize>;
39
40    /// Get epochs since last query
41    fn epochs_since_last_request(
42        &self, last_epoch_number: u64,
43        recent_reported_epochs: &VecDeque<(u64, Vec<H256>)>,
44    ) -> RpcResult<(u64, Vec<(u64, Vec<H256>)>)>;
45
46    fn into_primitive_filter(
47        &self, filter: EthRpcLogFilter,
48    ) -> RpcResult<LogFilter>;
49}