|
| 1 | +use alloy_primitives::{Address, BlockNumber, B256, U256}; |
| 2 | +use serde::{Deserialize, Serialize}; |
| 3 | +use std::collections::HashMap; |
| 4 | + |
| 5 | +/// Options for conditional raw transaction submissions. |
| 6 | +// reference for the implementation <https://notes.ethereum.org/@yoav/SkaX2lS9j#> |
| 7 | +// See also <https://pkg.go.dev/github.com/aK0nshin/go-ethereum/arbitrum_types#ConditionalOptions> |
| 8 | +#[derive(Debug, Serialize, Deserialize, Clone, Default)] |
| 9 | +#[serde(rename_all = "camelCase")] |
| 10 | +pub struct ConditionalOptions { |
| 11 | + /// A map of account addresses to their expected storage states. |
| 12 | + /// Each account can have a specified storage root or explicit slot-value pairs. |
| 13 | + #[serde(default)] |
| 14 | + pub known_accounts: HashMap<Address, AccountStorage>, |
| 15 | + /// The minimal block number at which the transaction can be included. |
| 16 | + /// `None` indicates no minimum block number constraint. |
| 17 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 18 | + pub block_number_min: Option<BlockNumber>, |
| 19 | + /// The maximal block number at which the transaction can be included. |
| 20 | + /// `None` indicates no maximum block number constraint. |
| 21 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 22 | + pub block_number_max: Option<BlockNumber>, |
| 23 | + /// The minimal timestamp at which the transaction can be included. |
| 24 | + /// `None` indicates no minimum timestamp constraint. |
| 25 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 26 | + pub timestamp_min: Option<u64>, |
| 27 | + /// The maximal timestamp at which the transaction can be included. |
| 28 | + /// `None` indicates no maximum timestamp constraint. |
| 29 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 30 | + pub timestamp_max: Option<u64>, |
| 31 | +} |
| 32 | + |
| 33 | +/// Represents the expected state of an account for a transaction to be conditionally accepted. |
| 34 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 35 | +#[serde(untagged)] |
| 36 | +pub enum AccountStorage { |
| 37 | + /// Expected storage root hash of the account. |
| 38 | + RootHash(B256), |
| 39 | + /// Explicit storage slots and their expected values. |
| 40 | + Slots(HashMap<U256, B256>), |
| 41 | +} |
0 commit comments