-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: remove T: Transport from public APIs #1859
Open
DaniPopes
wants to merge
13
commits into
main
Choose a base branch
from
dani/rm-T-transport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+745
−920
Open
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
52e2acf
feat: remove T: Transport from public APIs
DaniPopes 22027f0
fix: keep T for sol macro APIs, fix doctests
DaniPopes 2a78db6
fix: warning in consensus
DaniPopes c4a1ff4
docs
DaniPopes f93f6b6
feat: subsume BoxTransportConnect into TransportConnect, rename methods
DaniPopes 8b8e266
nits
DaniPopes 7562ef6
chore: more deprecations
DaniPopes 0227775
fix: specialize BoxTransport::new(BoxTransport)
DaniPopes 0151dce
chore: clippy
DaniPopes 050b8b0
docs
DaniPopes 0371332
msrv
DaniPopes 933eab4
Merge branch 'main' into dani/rm-T-transport
DaniPopes 85a3583
com
DaniPopes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,15 @@ use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256}; | |
use alloy_provider::{PendingTransactionBuilder, Provider}; | ||
use alloy_rpc_types_eth::{state::StateOverride, AccessList, BlobTransactionSidecar, BlockId}; | ||
use alloy_sol_types::SolCall; | ||
use alloy_transport::Transport; | ||
use std::{ | ||
future::{Future, IntoFuture}, | ||
marker::PhantomData, | ||
pin::Pin, | ||
}; | ||
|
||
// NOTE: The `T` generic here is kept to mitigate breakage with the `sol!` macro. | ||
// It should always be `()` and has no effect on the implementation. | ||
|
||
/// [`CallBuilder`] using a [`SolCall`] type as the call decoder. | ||
// NOTE: please avoid changing this type due to its use in the `sol!` macro. | ||
pub type SolCallBuilder<T, P, C, N = Ethereum> = CallBuilder<T, P, PhantomData<C>, N>; | ||
|
@@ -51,7 +53,7 @@ pub type RawCallBuilder<T, P, N = Ethereum> = CallBuilder<T, P, (), N>; | |
/// Using [`sol!`][sol]: | ||
/// | ||
/// ```no_run | ||
/// # async fn test<P: alloy_contract::private::Provider>(provider: P) -> Result<(), Box<dyn std::error::Error>> { | ||
/// # async fn test<P: alloy_provider::Provider>(provider: P) -> Result<(), Box<dyn std::error::Error>> { | ||
/// use alloy_contract::SolCallBuilder; | ||
/// use alloy_primitives::{Address, U256}; | ||
/// use alloy_sol_types::sol; | ||
|
@@ -87,7 +89,7 @@ pub type RawCallBuilder<T, P, N = Ethereum> = CallBuilder<T, P, (), N>; | |
/// Using [`ContractInstance`](crate::ContractInstance): | ||
/// | ||
/// ```no_run | ||
/// # async fn test<P: alloy_contract::private::Provider>(provider: P, dynamic_abi: alloy_json_abi::JsonAbi) -> Result<(), Box<dyn std::error::Error>> { | ||
/// # async fn test<P: alloy_provider::Provider>(provider: P, dynamic_abi: alloy_json_abi::JsonAbi) -> Result<(), Box<dyn std::error::Error>> { | ||
/// use alloy_primitives::{Address, Bytes, U256}; | ||
/// use alloy_dyn_abi::DynSolValue; | ||
/// use alloy_contract::{CallBuilder, ContractInstance, DynCallBuilder, Interface, RawCallBuilder}; | ||
|
@@ -101,16 +103,16 @@ pub type RawCallBuilder<T, P, N = Ethereum> = CallBuilder<T, P, (), N>; | |
/// let provider = ...; | ||
/// # ); | ||
/// let address = Address::ZERO; | ||
/// let contract: ContractInstance<_, _, _> = interface.connect(address, &provider); | ||
/// let contract: ContractInstance<_, _> = interface.connect(address, &provider); | ||
/// | ||
/// // Build and call the function: | ||
/// let call_builder: DynCallBuilder<_, _, _> = contract.function("doStuff", &[U256::ZERO.into(), true.into()])?; | ||
/// let call_builder: DynCallBuilder<(), _, _> = contract.function("doStuff", &[U256::ZERO.into(), true.into()])?; | ||
/// let result: Vec<DynSolValue> = call_builder.call().await?; | ||
/// | ||
/// // You can also decode the output manually. Get the raw bytes: | ||
/// let raw_result: Bytes = call_builder.call_raw().await?; | ||
/// // Or, equivalently: | ||
/// let raw_builder: RawCallBuilder<_, _, _> = call_builder.clone().clear_decoder(); | ||
/// let raw_builder: RawCallBuilder<(), _, _> = call_builder.clone().clear_decoder(); | ||
/// let raw_result: Bytes = raw_builder.call().await?; | ||
/// // Decode the raw bytes: | ||
/// let decoded_result: Vec<DynSolValue> = call_builder.decode_output(raw_result, false)?; | ||
|
@@ -129,7 +131,7 @@ pub struct CallBuilder<T, P, D, N: Network = Ethereum> { | |
// NOTE: This is public due to usage in `sol!`, please avoid changing it. | ||
pub provider: P, | ||
decoder: D, | ||
transport: PhantomData<T>, | ||
fake_transport: PhantomData<T>, | ||
} | ||
|
||
impl<T, P, D, N: Network> CallBuilder<T, P, D, N> { | ||
|
@@ -146,7 +148,7 @@ impl<T, P, D, N: Network> AsRef<N::TransactionRequest> for CallBuilder<T, P, D, | |
} | ||
|
||
// See [`ContractInstance`]. | ||
impl<T: Transport + Clone, P: Provider<T, N>, N: Network> DynCallBuilder<T, P, N> { | ||
impl<T, P: Provider<N>, N: Network> DynCallBuilder<T, P, N> { | ||
pub(crate) fn new_dyn( | ||
provider: P, | ||
address: &Address, | ||
|
@@ -170,23 +172,21 @@ impl<T: Transport + Clone, P: Provider<T, N>, N: Network> DynCallBuilder<T, P, N | |
state: self.state, | ||
provider: self.provider, | ||
decoder: (), | ||
transport: PhantomData, | ||
fake_transport: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
#[doc(hidden)] | ||
impl<'a, T: Transport + Clone, P: Provider<T, N>, C: SolCall, N: Network> | ||
SolCallBuilder<T, &'a P, C, N> | ||
{ | ||
impl<'a, T, P: Provider<N>, C: SolCall, N: Network> SolCallBuilder<T, &'a P, C, N> { | ||
// `sol!` macro constructor, see `#[sol(rpc)]`. Not public API. | ||
// NOTE: please avoid changing this function due to its use in the `sol!` macro. | ||
pub fn new_sol(provider: &'a P, address: &Address, call: &C) -> Self { | ||
Self::new_inner_call(provider, call.abi_encode().into(), PhantomData::<C>).to(*address) | ||
} | ||
} | ||
|
||
impl<T: Transport + Clone, P: Provider<T, N>, C: SolCall, N: Network> SolCallBuilder<T, P, C, N> { | ||
impl<T, P: Provider<N>, C: SolCall, N: Network> SolCallBuilder<T, P, C, N> { | ||
/// Clears the decoder, returning a raw call builder. | ||
#[inline] | ||
pub fn clear_decoder(self) -> RawCallBuilder<T, P, N> { | ||
|
@@ -196,12 +196,12 @@ impl<T: Transport + Clone, P: Provider<T, N>, C: SolCall, N: Network> SolCallBui | |
state: self.state, | ||
provider: self.provider, | ||
decoder: (), | ||
transport: PhantomData, | ||
fake_transport: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<T: Transport + Clone, P: Provider<T, N>, N: Network> RawCallBuilder<T, P, N> { | ||
impl<T, P: Provider<N>, N: Network> RawCallBuilder<T, P, N> { | ||
/// Sets the decoder to the provided [`SolCall`]. | ||
/// | ||
/// Converts the raw call builder into a sol call builder. | ||
|
@@ -261,12 +261,12 @@ impl<T: Transport + Clone, P: Provider<T, N>, N: Network> RawCallBuilder<T, P, N | |
state: self.state, | ||
provider: self.provider, | ||
decoder: PhantomData::<C>, | ||
transport: PhantomData, | ||
fake_transport: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<T: Transport + Clone, P: Provider<T, N>, N: Network> RawCallBuilder<T, P, N> { | ||
impl<T, P: Provider<N>, N: Network> RawCallBuilder<T, P, N> { | ||
/// Creates a new call builder with the provided provider and ABI encoded input. | ||
/// | ||
/// Will not decode the output of the call, meaning that [`call`](Self::call) will behave the | ||
|
@@ -286,15 +286,15 @@ impl<T: Transport + Clone, P: Provider<T, N>, N: Network> RawCallBuilder<T, P, N | |
} | ||
} | ||
|
||
impl<T: Transport + Clone, P: Provider<T, N>, D: CallDecoder, N: Network> CallBuilder<T, P, D, N> { | ||
impl<T, P: Provider<N>, D: CallDecoder, N: Network> CallBuilder<T, P, D, N> { | ||
fn new_inner_deploy(provider: P, input: Bytes, decoder: D) -> Self { | ||
Self { | ||
request: <N::TransactionRequest>::default().with_deploy_code(input), | ||
decoder, | ||
provider, | ||
block: BlockId::default(), | ||
state: None, | ||
transport: PhantomData, | ||
fake_transport: PhantomData, | ||
} | ||
} | ||
|
||
|
@@ -305,7 +305,7 @@ impl<T: Transport + Clone, P: Provider<T, N>, D: CallDecoder, N: Network> CallBu | |
provider, | ||
block: BlockId::default(), | ||
state: None, | ||
transport: PhantomData, | ||
fake_transport: PhantomData, | ||
} | ||
} | ||
|
||
|
@@ -447,7 +447,7 @@ impl<T: Transport + Clone, P: Provider<T, N>, D: CallDecoder, N: Network> CallBu | |
/// If this is not desired, use [`call_raw`](Self::call_raw) to get the raw output data. | ||
#[doc(alias = "eth_call")] | ||
#[doc(alias = "call_with_overrides")] | ||
pub fn call(&self) -> EthCall<'_, '_, D, T, N> { | ||
pub fn call(&self) -> EthCall<'_, '_, D, N> { | ||
self.call_raw().with_decoder(&self.decoder) | ||
} | ||
|
||
|
@@ -457,7 +457,7 @@ impl<T: Transport + Clone, P: Provider<T, N>, D: CallDecoder, N: Network> CallBu | |
/// Does not decode the output of the call, returning the raw output data instead. | ||
/// | ||
/// See [`call`](Self::call) for more information. | ||
pub fn call_raw(&self) -> EthCall<'_, '_, (), T, N> { | ||
pub fn call_raw(&self) -> EthCall<'_, '_, (), N> { | ||
let call = self.provider.call(&self.request).block(self.block); | ||
let call = match &self.state { | ||
Some(state) => call.overrides(state), | ||
|
@@ -495,7 +495,7 @@ impl<T: Transport + Clone, P: Provider<T, N>, D: CallDecoder, N: Network> CallBu | |
/// | ||
/// Returns a builder for configuring the pending transaction watcher. | ||
/// See [`Provider::send_transaction`] for more information. | ||
pub async fn send(&self) -> Result<PendingTransactionBuilder<T, N>> { | ||
pub async fn send(&self) -> Result<PendingTransactionBuilder<N>> { | ||
Ok(self.provider.send_transaction(self.request.clone()).await?) | ||
} | ||
|
||
|
@@ -508,7 +508,7 @@ impl<T: Transport + Clone, P: Provider<T, N>, D: CallDecoder, N: Network> CallBu | |
} | ||
} | ||
|
||
impl<T: Transport, P: Clone, D, N: Network> CallBuilder<T, &P, D, N> { | ||
impl<T, P: Clone, D, N: Network> CallBuilder<T, &P, D, N> { | ||
/// Clones the provider and returns a new builder with the cloned provider. | ||
pub fn with_cloned_provider(self) -> CallBuilder<T, P, D, N> { | ||
CallBuilder { | ||
|
@@ -517,7 +517,7 @@ impl<T: Transport, P: Clone, D, N: Network> CallBuilder<T, &P, D, N> { | |
state: self.state, | ||
provider: self.provider.clone(), | ||
decoder: self.decoder, | ||
transport: PhantomData, | ||
fake_transport: PhantomData, | ||
} | ||
} | ||
} | ||
|
@@ -532,10 +532,9 @@ impl<T: Transport, P: Clone, D, N: Network> CallBuilder<T, &P, D, N> { | |
/// the associated future type, the returned future, must be a concrete type (`Box<dyn Future ...>`) | ||
/// and cannot be an opaque type (`impl Future ...`) because `impl Trait` in this position is not | ||
/// stable yet. See [rust-lang/rust#63063](https://github.com/rust-lang/rust/issues/63063). | ||
impl<T, P, D, N> IntoFuture for CallBuilder<T, P, D, N> | ||
impl<T: Send + Sync, P, D, N> IntoFuture for CallBuilder<T, P, D, N> | ||
DaniPopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
where | ||
T: Transport + Clone, | ||
P: Provider<T, N>, | ||
P: Provider<N>, | ||
D: CallDecoder + Send + Sync + Unpin, | ||
N: Network, | ||
Self: 'static, | ||
|
@@ -621,11 +620,8 @@ mod tests { | |
|
||
/// Creates a new call_builder to test field modifications, taken from [call_encoding] | ||
#[allow(clippy::type_complexity)] | ||
fn build_call_builder() -> CallBuilder< | ||
alloy_transport::BoxTransport, | ||
AnvilProvider<RootProvider<alloy_transport::BoxTransport>, alloy_transport::BoxTransport>, | ||
PhantomData<MyContract::doStuffCall>, | ||
Comment on lines
-625
to
-627
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah this was kinda horrible |
||
> { | ||
fn build_call_builder( | ||
) -> CallBuilder<(), AnvilProvider<RootProvider>, PhantomData<MyContract::doStuffCall>> { | ||
let provider = ProviderBuilder::new().on_anvil(); | ||
let contract = MyContract::new(Address::ZERO, provider); | ||
let call_builder = contract.doStuff(U256::ZERO, true).with_cloned_provider(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the breakage here?
unclear to me what the relationship with the macro is
EDIT: so the macro in alloy/core generates code for alloy/alloy
this makes upgrading a bit weird, but manageable I assume
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes