-
Notifications
You must be signed in to change notification settings - Fork 33
/
transaction.rs
81 lines (71 loc) · 2.94 KB
/
transaction.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Optimism specific types related to transactions.
use alloy_network::TransactionResponse;
use alloy_primitives::B256;
use alloy_serde::OtherFields;
use serde::{Deserialize, Serialize};
/// OP Transaction type
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[serde(rename_all = "camelCase")]
pub struct Transaction {
/// Ethereum Transaction Types
#[serde(flatten)]
pub inner: alloy_rpc_types_eth::Transaction,
/// The ETH value to mint on L2
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub mint: Option<u128>,
/// Hash that uniquely identifies the source of the deposit.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_hash: Option<B256>,
/// Field indicating whether the transaction is a system transaction, and therefore
/// exempt from the L2 gas limit.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_system_tx: Option<bool>,
/// Deposit receipt version for deposit transactions post-canyon
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub deposit_receipt_version: Option<u64>,
}
impl TransactionResponse for Transaction {
fn from(&self) -> alloy_primitives::Address {
self.inner.from()
}
fn to(&self) -> Option<alloy_primitives::Address> {
self.inner.to()
}
fn tx_hash(&self) -> alloy_primitives::TxHash {
self.inner.tx_hash()
}
fn value(&self) -> alloy_primitives::U256 {
self.inner.value()
}
fn gas(&self) -> u128 {
self.inner.gas()
}
fn input(&self) -> &alloy_primitives::Bytes {
self.inner.input()
}
}
/// Optimism specific transaction fields
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[doc(alias = "OptimismTxFields")]
#[serde(rename_all = "camelCase")]
pub struct OptimismTransactionFields {
/// The ETH value to mint on L2
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub mint: Option<u128>,
/// Hash that uniquely identifies the source of the deposit.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_hash: Option<B256>,
/// Field indicating whether the transaction is a system transaction, and therefore
/// exempt from the L2 gas limit.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_system_tx: Option<bool>,
/// Deposit receipt version for deposit transactions post-canyon
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub deposit_receipt_version: Option<u64>,
}
impl From<OptimismTransactionFields> for OtherFields {
fn from(value: OptimismTransactionFields) -> Self {
serde_json::to_value(value).unwrap().try_into().unwrap()
}
}