verbs_rs/contract/structs.rs
1//! Transaction related data types
2
3use alloy_primitives::{Address, U256};
4use alloy_sol_types::SolCall;
5use revm::primitives::{Log, Output};
6
7/// EVM transaction argument data
8#[derive(Clone)]
9pub struct Transaction {
10 /// 4 byte function selector
11 pub function_selector: [u8; 4],
12 /// Address of the contract caller
13 pub callee: Address,
14 /// Address of the contract to call
15 pub transact_to: Address,
16 /// ABI encoded arguments bytes
17 pub args: Vec<u8>,
18 /// Gas priority `None` will be treated as 0 for sorting
19 pub gas_priority_fee: Option<U256>,
20 /// Transaction nonce, used for transaction ordering
21 pub nonce: Option<u64>,
22 /// Value attached to the transaction
23 pub value: U256,
24 /// Flag, if `true` the simulation will halt (panic)
25 /// if this transaction is reverted.
26 pub checked: bool,
27}
28
29impl Transaction {
30 pub fn new<T: SolCall>(
31 callee: Address,
32 contract: Address,
33 args: T,
34 gas_priority_fee: Option<U256>,
35 nonce: Option<u64>,
36 value: U256,
37 checked: bool,
38 ) -> Self {
39 Transaction {
40 function_selector: T::SELECTOR,
41 callee,
42 transact_to: contract,
43 args: args.abi_encode(),
44 gas_priority_fee,
45 nonce,
46 value,
47 checked,
48 }
49 }
50
51 pub fn basic<T: SolCall>(callee: Address, contract: Address, args: T, checked: bool) -> Self {
52 Transaction {
53 function_selector: T::SELECTOR,
54 callee,
55 transact_to: contract,
56 args: args.abi_encode(),
57 gas_priority_fee: None,
58 nonce: None,
59 value: U256::ZERO,
60 checked,
61 }
62 }
63}
64
65/// Result of a transaction included any generated events
66pub struct TransactionResult {
67 /// Flag whether transaction was successful
68 pub success: bool,
69 /// Output data
70 pub output: Output,
71 /// Vec of events returned by the transaction
72 pub events: Option<Event>,
73}
74
75/// Wraps event logs with additional event information
76///
77/// Events are created for each transaction processed
78/// during the simulation, included failed (reverted)
79/// transactions. This allow a history of simulation
80/// events to be recreated after a simulation
81///
82pub struct Event {
83 /// If the event was successful (i.e. `false`
84 /// indicates a transaction was reverted)
85 pub success: bool,
86 /// 4 byte function selector of the called function
87 pub function_selector: [u8; 4],
88 /// Event data generated by the transaction
89 pub logs: Vec<Log>,
90 /// Simulation step the event was created
91 pub step: usize,
92 /// Sequence the event was created inside a block
93 pub sequence: usize,
94}