Skip to content

Commit

Permalink
feat: (wip) get info about transaction type currently building
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa authored and prestwich committed Apr 12, 2024
1 parent 39f4572 commit 5b5e7c9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
10 changes: 9 additions & 1 deletion crates/network/src/any/builder.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -122,6 +122,14 @@ impl TransactionBuilder<AnyNetwork> for WithOtherFields<TransactionRequest> {
self.deref().can_submit()
}

fn output_tx_type(&self) -> TxType {
self.deref().output_tx_type()
}

fn output_tx_type_checked(&self) -> BuilderResult<TxType> {
self.deref().output_tx_type_checked()
}

fn build_unsigned(self) -> BuilderResult<<AnyNetwork as Network>::UnsignedTx> {
build_unsigned::<AnyNetwork>(self.inner)
}
Expand Down
29 changes: 21 additions & 8 deletions crates/network/src/ethereum/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ impl TransactionBuilder<Ethereum> for TransactionRequest {
common && (legacy || eip2930 || eip1559 || eip4844)
}

fn output_tx_type(&self) -> TxType {
todo!()
}

fn output_tx_type_checked(&self) -> BuilderResult<TxType> {
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<TypedTransaction> {
build_unsigned::<Ethereum>(self)
}
Expand All @@ -159,14 +175,11 @@ where
N: Network,
N::UnsignedTx: From<TxLegacy> + From<TxEip1559> + From<TxEip2930> + From<TxEip4844Variant>,
{
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),
}
}

Expand Down
8 changes: 8 additions & 0 deletions crates/network/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ pub trait TransactionBuilder<N: Network>: 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<TxType>;

/// Build an unsigned, but typed, transaction.
fn build_unsigned(self) -> BuilderResult<N::UnsignedTx>;

Expand Down

0 comments on commit 5b5e7c9

Please sign in to comment.