From 5b5e7c9e97ea73b2c1fec34b798263b59664b65f Mon Sep 17 00:00:00 2001 From: leruaa Date: Wed, 3 Apr 2024 18:31:08 +0000 Subject: [PATCH] feat: (wip) get info about transaction type currently building --- crates/network/src/any/builder.rs | 10 +++++++- crates/network/src/ethereum/builder.rs | 29 ++++++++++++++++------- crates/network/src/transaction/builder.rs | 8 +++++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/crates/network/src/any/builder.rs b/crates/network/src/any/builder.rs index ef367d7e83da..2da32ddf3f57 100644 --- a/crates/network/src/any/builder.rs +++ b/crates/network/src/any/builder.rs @@ -1,6 +1,6 @@ use std::ops::{Deref, DerefMut}; -use alloy_consensus::BlobTransactionSidecar; +use alloy_consensus::{BlobTransactionSidecar, TxType}; use alloy_rpc_types::{AccessList, TransactionRequest, WithOtherFields}; use crate::{ @@ -122,6 +122,14 @@ impl TransactionBuilder for WithOtherFields { self.deref().can_submit() } + fn output_tx_type(&self) -> TxType { + self.deref().output_tx_type() + } + + fn output_tx_type_checked(&self) -> BuilderResult { + self.deref().output_tx_type_checked() + } + fn build_unsigned(self) -> BuilderResult<::UnsignedTx> { build_unsigned::(self.inner) } diff --git a/crates/network/src/ethereum/builder.rs b/crates/network/src/ethereum/builder.rs index 6b273d79a381..aadb448451ba 100644 --- a/crates/network/src/ethereum/builder.rs +++ b/crates/network/src/ethereum/builder.rs @@ -141,6 +141,22 @@ impl TransactionBuilder for TransactionRequest { common && (legacy || eip2930 || eip1559 || eip4844) } + fn output_tx_type(&self) -> TxType { + todo!() + } + + fn output_tx_type_checked(&self) -> BuilderResult { + if will_build_4844(self)? { + Ok(TxType::Eip4844) + } else if will_build_2930(self)? { + Ok(TxType::Eip2930) + } else if will_build_legacy(self)? { + Ok(TxType::Legacy) + } else { + Ok(TxType::Eip1559) + } + } + fn build_unsigned(self) -> BuilderResult { build_unsigned::(self) } @@ -159,14 +175,11 @@ where N: Network, N::UnsignedTx: From + From + From + From, { - if will_build_4844(&request)? { - build_4844(request).map(TxEip4844Variant::from).map(Into::into) - } else if will_build_2930(&request)? { - build_2930(request).map(Into::into) - } else if will_build_legacy(&request)? { - build_legacy(request).map(Into::into) - } else { - build_1559(request).map(Into::into) + match request.output_tx_type_checked()? { + TxType::Legacy => build_legacy(request).map(Into::into), + TxType::Eip2930 => build_2930(request).map(Into::into), + TxType::Eip1559 => build_1559(request).map(Into::into), + TxType::Eip4844 => build_4844(request).map(TxEip4844Variant::from).map(Into::into), } } diff --git a/crates/network/src/transaction/builder.rs b/crates/network/src/transaction/builder.rs index 4f7c757250ff..3369f6653a19 100644 --- a/crates/network/src/transaction/builder.rs +++ b/crates/network/src/transaction/builder.rs @@ -278,6 +278,14 @@ pub trait TransactionBuilder: Default + Sized + Send + Sync + 'stati /// a valid transaction. fn can_build(&self) -> bool; + /// Returns the transaction type that this builder will attempt to build. This does not imply + /// that the builder is ready to build. + fn output_tx_type(&self) -> TxType; + + /// Returns the transaction type that this builder will build. `Err` if the builder + /// is not ready to build, containing the attempt type and missing/conflicted information + fn output_tx_type_checked(&self) -> BuilderResult; + /// Build an unsigned, but typed, transaction. fn build_unsigned(self) -> BuilderResult;