skar_format/types/
mod.rs

1use arrayvec::ArrayVec;
2use serde::{Deserialize, Serialize};
3
4mod data;
5mod fixed_size_data;
6mod hex;
7mod quantity;
8mod transaction_status;
9mod transaction_type;
10mod uint;
11mod util;
12
13pub use data::Data;
14pub use fixed_size_data::FixedSizeData;
15pub use hex::Hex;
16pub use quantity::Quantity;
17pub use transaction_status::TransactionStatus;
18pub use transaction_type::TransactionType;
19
20/// Evm block header object
21///
22/// See ethereum rpc spec for the meaning of fields
23#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct BlockHeader {
26    pub number: BlockNumber,
27    pub hash: Hash,
28    pub parent_hash: Hash,
29    pub nonce: Option<Nonce>,
30    #[serde(default)]
31    pub sha3_uncles: Hash,
32    pub logs_bloom: BloomFilter,
33    pub transactions_root: Hash,
34    pub state_root: Hash,
35    pub receipts_root: Hash,
36    pub miner: Address,
37    pub difficulty: Option<Quantity>,
38    pub total_difficulty: Option<Quantity>,
39    pub extra_data: Data,
40    pub size: Quantity,
41    pub gas_limit: Quantity,
42    pub gas_used: Quantity,
43    pub timestamp: Quantity,
44    pub uncles: Option<Vec<Hash>>,
45    pub base_fee_per_gas: Option<Quantity>,
46    pub blob_gas_used: Option<Quantity>,
47    pub excess_blob_gas: Option<Quantity>,
48    pub parent_beacon_block_root: Option<Hash>,
49    pub withdrawals_root: Option<Hash>,
50    pub withdrawals: Option<Vec<Withdrawal>>,
51    pub l1_block_number: Option<BlockNumber>,
52    pub send_count: Option<Quantity>,
53    pub send_root: Option<Hash>,
54    pub mix_hash: Option<Hash>,
55}
56
57/// Evm withdrawal object
58///
59/// See ethereum rpc spec for the meaning of fields
60#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
61#[serde(rename_all = "camelCase")]
62pub struct Withdrawal {
63    pub index: Option<Quantity>,
64    pub validator_index: Option<Quantity>,
65    pub address: Option<Address>,
66    pub amount: Option<Quantity>,
67}
68
69/// Evm block object
70///
71/// A block will contain a header and either a list of full transaction objects or
72/// a list of only transaction hashes.
73#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
74#[serde(rename_all = "camelCase")]
75pub struct Block<Tx> {
76    #[serde(flatten)]
77    pub header: BlockHeader,
78    pub transactions: Vec<Tx>,
79}
80
81/// Evm transaction object
82///
83/// See ethereum rpc spec for the meaning of fields
84#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
85#[serde(rename_all = "camelCase")]
86pub struct Transaction {
87    pub block_hash: Hash,
88    pub block_number: BlockNumber,
89    pub from: Option<Address>,
90    pub gas: Quantity,
91    pub gas_price: Option<Quantity>,
92    pub hash: Hash,
93    pub input: Data,
94    pub nonce: Quantity,
95    pub to: Option<Address>,
96    pub transaction_index: TransactionIndex,
97    pub value: Quantity,
98    pub v: Option<Quantity>,
99    pub r: Option<Quantity>,
100    pub s: Option<Quantity>,
101    pub y_parity: Option<Quantity>,
102    pub max_priority_fee_per_gas: Option<Quantity>,
103    pub max_fee_per_gas: Option<Quantity>,
104    pub chain_id: Option<Quantity>,
105    pub access_list: Option<Vec<AccessList>>,
106    pub max_fee_per_blob_gas: Option<Quantity>,
107    pub blob_versioned_hashes: Option<Vec<Hash>>,
108}
109
110/// Evm access list object
111///
112/// See ethereum rpc spec for the meaning of fields
113#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
114#[serde(rename_all = "camelCase")]
115pub struct AccessList {
116    pub address: Option<Address>,
117    pub storage_keys: Option<Vec<Hash>>,
118}
119
120/// Evm transaction receipt object
121///
122/// See ethereum rpc spec for the meaning of fields
123#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
124#[serde(rename_all = "camelCase")]
125pub struct TransactionReceipt {
126    pub transaction_hash: Hash,
127    pub transaction_index: TransactionIndex,
128    pub block_hash: Hash,
129    pub block_number: BlockNumber,
130    pub from: Address,
131    pub to: Option<Address>,
132    pub cumulative_gas_used: Quantity,
133    #[serde(default)]
134    pub effective_gas_price: Quantity,
135    pub gas_used: Quantity,
136    pub contract_address: Option<Address>,
137    pub logs: Vec<Log>,
138    pub logs_bloom: BloomFilter,
139    #[serde(rename = "type")]
140    pub kind: Option<TransactionType>,
141    pub root: Option<Hash>,
142    pub status: Option<TransactionStatus>,
143    pub l1_fee: Option<Quantity>,
144    pub l1_gas_price: Option<Quantity>,
145    pub l1_gas_used: Option<Quantity>,
146    pub l1_fee_scalar: Option<Quantity>,
147    pub gas_used_for_l1: Option<Quantity>,
148}
149
150/// Evm log object
151///
152/// See ethereum rpc spec for the meaning of fields
153#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
154#[serde(rename_all = "camelCase")]
155pub struct Log {
156    pub removed: Option<bool>,
157    pub log_index: LogIndex,
158    pub transaction_index: TransactionIndex,
159    pub transaction_hash: Hash,
160    pub block_hash: Hash,
161    pub block_number: BlockNumber,
162    pub address: Address,
163    pub data: Data,
164    pub topics: ArrayVec<LogArgument, 4>,
165}
166
167/// Evm trace object (parity style, returned from trace_block request on RPC)
168///
169/// See trace_block documentation online for meaning of fields
170#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
171#[serde(rename_all = "camelCase")]
172pub struct Trace {
173    pub action: TraceAction,
174    pub block_hash: Hash,
175    pub block_number: u64,
176    pub result: Option<TraceResult>,
177    pub subtraces: Option<u64>,
178    pub trace_address: Option<Vec<u64>>,
179    pub transaction_hash: Option<Hash>,
180    pub transaction_position: Option<u64>,
181    #[serde(rename = "type")]
182    pub kind: Option<String>,
183    pub error: Option<String>,
184}
185
186/// Action object inside trace object (parity style, returned from trace_block request on RPC)
187///
188/// See trace_block documentation online for meaning of fields
189#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
190#[serde(rename_all = "camelCase")]
191pub struct TraceAction {
192    pub from: Option<Address>,
193    pub to: Option<Address>,
194    pub call_type: Option<String>,
195    pub gas: Option<Quantity>,
196    pub input: Option<Data>,
197    pub init: Option<Data>,
198    pub value: Option<Quantity>,
199    pub author: Option<Address>,
200    pub reward_type: Option<String>,
201}
202
203/// Result object inside trace object (parity style, returned from trace_block request on RPC)
204///
205/// See trace_block documentation online for meaning of fields
206#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
207#[serde(rename_all = "camelCase")]
208pub struct TraceResult {
209    pub address: Option<Address>,
210    pub code: Option<Data>,
211    pub gas_used: Option<Quantity>,
212    pub output: Option<Data>,
213}
214
215/// EVM hash is 32 bytes of data
216pub type Hash = FixedSizeData<32>;
217
218/// EVM log argument is 32 bytes of data
219pub type LogArgument = FixedSizeData<32>;
220
221/// EVM address is 20 bytes of data
222pub type Address = FixedSizeData<20>;
223
224/// EVM nonce is 8 bytes of data
225pub type Nonce = FixedSizeData<8>;
226
227pub type BloomFilter = Data;
228pub type BlockNumber = uint::UInt;
229pub type TransactionIndex = uint::UInt;
230pub type LogIndex = uint::UInt;