alloy_provider/provider/
sendable.rs1use alloy_network::Network;
2
3#[doc(hidden, alias = "SendableTransaction")]
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub enum SendableTx<N: Network> {
13 Builder(N::TransactionRequest),
15 Envelope(N::TxEnvelope),
17}
18
19impl<N: Network> SendableTx<N> {
20 pub fn as_mut_builder(&mut self) -> Option<&mut N::TransactionRequest> {
22 match self {
23 Self::Builder(tx) => Some(tx),
24 _ => None,
25 }
26 }
27
28 pub const fn as_builder(&self) -> Option<&N::TransactionRequest> {
30 match self {
31 Self::Builder(tx) => Some(tx),
32 _ => None,
33 }
34 }
35
36 pub const fn is_builder(&self) -> bool {
38 matches!(self, Self::Builder(_))
39 }
40
41 pub const fn is_envelope(&self) -> bool {
43 matches!(self, Self::Envelope(_))
44 }
45
46 pub const fn as_envelope(&self) -> Option<&N::TxEnvelope> {
48 match self {
49 Self::Envelope(tx) => Some(tx),
50 _ => None,
51 }
52 }
53
54 pub fn try_into_envelope(self) -> Result<N::TxEnvelope, SendableTxErr<N::TransactionRequest>> {
58 match self {
59 Self::Builder(req) => Err(SendableTxErr::new(req)),
60 Self::Envelope(env) => Ok(env),
61 }
62 }
63
64 pub fn try_into_request(self) -> Result<N::TransactionRequest, SendableTxErr<N::TxEnvelope>> {
68 match self {
69 Self::Builder(req) => Ok(req),
70 Self::Envelope(env) => Err(SendableTxErr::new(env)),
71 }
72 }
73}
74
75#[derive(Debug, Clone, thiserror::Error)]
77#[error("Unexpected variant: {0:?}")]
78pub struct SendableTxErr<T>(pub T);
79
80impl<T> SendableTxErr<T> {
81 pub const fn new(inner: T) -> Self {
83 Self(inner)
84 }
85
86 pub fn into_inner(self) -> T {
88 self.0
89 }
90}