skar_net_types/
lib.rs

1use std::collections::BTreeSet;
2
3use arrayvec::ArrayVec;
4use serde::{Deserialize, Serialize};
5use skar_format::{Address, FixedSizeData, Hash, LogArgument};
6
7pub type Sighash = FixedSizeData<4>;
8
9pub mod skar_net_types_capnp {
10    include!(concat!(env!("OUT_DIR"), "/skar_net_types_capnp.rs"));
11}
12
13#[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq)]
14pub struct LogSelection {
15    /// Address of the contract, any logs that has any of these addresses will be returned.
16    /// Empty means match all.
17    #[serde(default)]
18    pub address: Vec<Address>,
19    /// Topics to match, each member of the top level array is another array, if the nth topic matches any
20    ///  topic specified in topics[n] the log will be returned. Empty means match all.
21    #[serde(default)]
22    pub topics: ArrayVec<Vec<LogArgument>, 4>,
23}
24
25#[derive(Default, Serialize, Deserialize, Clone, Debug)]
26pub struct TransactionSelection {
27    /// Address the transaction should originate from. If transaction.from matches any of these, the transaction
28    ///  will be returned. Keep in mind that this has an and relationship with to filter, so each transaction should
29    ///  match both of them. Empty means match all.
30    #[serde(default)]
31    pub from: Vec<Address>,
32    /// Address the transaction should go to. If transaction.to matches any of these, the transaction will
33    ///  be returned. Keep in mind that this has an and relationship with from filter, so each transaction should
34    ///  match both of them. Empty means match all.
35    #[serde(default)]
36    pub to: Vec<Address>,
37    /// If first 4 bytes of transaction input matches any of these, transaction will be returned. Empty means match all.
38    #[serde(default)]
39    pub sighash: Vec<Sighash>,
40    /// If transaction.status matches this value, the transaction will be returned.
41    pub status: Option<u8>,
42    /// If transaction.type matches any of these values, the transaction will be returned
43    #[serde(rename = "type")]
44    #[serde(default)]
45    pub kind: Vec<u8>,
46    // If transaction.contract_address matches any of these values, the transaction will be returned.
47    #[serde(default)]
48    pub contract_address: Vec<Address>,
49}
50
51#[derive(Default, Serialize, Deserialize, Clone, Debug)]
52pub struct TraceSelection {
53    #[serde(default)]
54    pub from: Vec<Address>,
55    #[serde(default)]
56    pub to: Vec<Address>,
57    #[serde(default)]
58    pub call_type: Vec<String>,
59    #[serde(default)]
60    pub reward_type: Vec<String>,
61    #[serde(default)]
62    #[serde(rename = "type")]
63    pub kind: Vec<String>,
64    #[serde(default)]
65    pub sighash: Vec<Sighash>,
66}
67
68#[derive(Default, Serialize, Deserialize, Clone, Debug)]
69pub struct Query {
70    /// The block to start the query from
71    pub from_block: u64,
72    /// The block to end the query at. If not specified, the query will go until the
73    ///  end of data. Exclusive, the returned range will be [from_block..to_block).
74    ///
75    /// The query will return before it reaches this target block if it hits the time limit
76    ///  configured on the server. The user should continue their query by putting the
77    ///  next_block field in the response into from_block field of their next query. This implements
78    ///  pagination.
79    pub to_block: Option<u64>,
80    /// List of log selections, these have an OR relationship between them, so the query will return logs
81    /// that match any of these selections.
82    #[serde(default)]
83    pub logs: Vec<LogSelection>,
84    /// List of transaction selections, the query will return transactions that match any of these selections and
85    ///  it will return transactions that are related to the returned logs.
86    #[serde(default)]
87    pub transactions: Vec<TransactionSelection>,
88    /// List of trace selections, the query will return traces that match any of these selections and
89    ///  it will re turn traces that are related to the returned logs.
90    #[serde(default)]
91    pub traces: Vec<TraceSelection>,
92    /// Weather to include all blocks regardless of if they are related to a returned transaction or log. Normally
93    ///  the server will return only the blocks that are related to the transaction or logs in the response. But if this
94    ///  is set to true, the server will return data for all blocks in the requested range [from_block, to_block).
95    #[serde(default)]
96    pub include_all_blocks: bool,
97    /// Field selection. The user can select which fields they are interested in, requesting less fields will improve
98    ///  query execution time and reduce the payload size so the user should always use a minimal number of fields.
99    #[serde(default)]
100    pub field_selection: FieldSelection,
101    /// Maximum number of blocks that should be returned, the server might return more blocks than this number but
102    ///  it won't overshoot by too much.
103    #[serde(default)]
104    pub max_num_blocks: Option<usize>,
105    /// Maximum number of transactions that should be returned, the server might return more transactions than this number but
106    ///  it won't overshoot by too much.
107    #[serde(default)]
108    pub max_num_transactions: Option<usize>,
109    /// Maximum number of logs that should be returned, the server might return more logs than this number but
110    ///  it won't overshoot by too much.
111    #[serde(default)]
112    pub max_num_logs: Option<usize>,
113    /// Maximum number of traces that should be returned, the server might return more traces than this number but
114    ///  it won't overshoot by too much.
115    #[serde(default)]
116    pub max_num_traces: Option<usize>,
117}
118
119#[derive(Default, Serialize, Deserialize, Clone, Debug)]
120pub struct FieldSelection {
121    #[serde(default)]
122    pub block: BTreeSet<String>,
123    #[serde(default)]
124    pub transaction: BTreeSet<String>,
125    #[serde(default)]
126    pub log: BTreeSet<String>,
127    #[serde(default)]
128    pub trace: BTreeSet<String>,
129}
130
131#[derive(Clone, Copy, Deserialize, Serialize, Debug)]
132pub struct ArchiveHeight {
133    pub height: Option<u64>,
134}
135
136/// Guard for detecting rollbacks
137#[derive(Debug, Clone, Serialize)]
138pub struct RollbackGuard {
139    /// Block number of last block scanned in memory
140    pub block_number: u64,
141    /// Block timestamp of last block scanned in memory
142    pub timestamp: i64,
143    /// Block hash of last block scanned in memory
144    pub hash: Hash,
145    /// Block number of first block scanned in memory
146    pub first_block_number: u64,
147    /// Parent hash of first block scanned in memory
148    pub first_parent_hash: Hash,
149}