Skip to content
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

fix(sol!): rm fake transport from contract expansion #865

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions crates/sol-macro-expander/src/expand/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,25 @@ pub(super) fn expand(cx: &mut ExpCtxt<'_>, contract: &ItemContract) -> Result<To
quote! {
#deploy_doc
#[inline]
pub fn deploy<T: alloy_contract::private::Transport + ::core::clone::Clone, P: alloy_contract::private::Provider<T, N>, N: alloy_contract::private::Network>(provider: P, #params)
-> impl ::core::future::Future<Output = alloy_contract::Result<#name<T, P, N>>>
pub fn deploy<P: alloy_contract::private::Provider<N>, N: alloy_contract::private::Network>(provider: P, #params)
-> impl ::core::future::Future<Output = alloy_contract::Result<#name<P, N>>>
{
#name::<T, P, N>::deploy(provider, #args)
#name::<P, N>::deploy(provider, #args)
}

#deploy_builder_doc
#[inline]
pub fn deploy_builder<T: alloy_contract::private::Transport + ::core::clone::Clone, P: alloy_contract::private::Provider<T, N>, N: alloy_contract::private::Network>(provider: P, #params)
-> alloy_contract::RawCallBuilder<T, P, N>
pub fn deploy_builder<P: alloy_contract::private::Provider<N>, N: alloy_contract::private::Network>(provider: P, #params)
-> alloy_contract::RawCallBuilder<P, N>
{
#name::<T, P, N>::deploy_builder(provider, #args)
#name::<P, N>::deploy_builder(provider, #args)
}
},
quote! {
#deploy_doc
#[inline]
pub async fn deploy(provider: P, #params)
-> alloy_contract::Result<#name<T, P, N>>
-> alloy_contract::Result<#name<P, N>>
{
let call_builder = Self::deploy_builder(provider, #args);
let contract_address = call_builder.deploy().await?;
Expand All @@ -349,7 +349,7 @@ pub(super) fn expand(cx: &mut ExpCtxt<'_>, contract: &ItemContract) -> Result<To
#deploy_builder_doc
#[inline]
pub fn deploy_builder(provider: P, #params)
-> alloy_contract::RawCallBuilder<T, P, N>
-> alloy_contract::RawCallBuilder<P, N>
{
alloy_contract::RawCallBuilder::new_raw_deploy(provider, #deploy_builder_data)
}
Expand All @@ -365,39 +365,40 @@ pub(super) fn expand(cx: &mut ExpCtxt<'_>, contract: &ItemContract) -> Result<To
);
quote! {
#[doc = #doc]
pub fn #name(&self) -> alloy_contract::Event<T, &P, #event_name, N> {
pub fn #name(&self) -> alloy_contract::Event<&P, #event_name, N> {
self.event_filter::<#event_name>()
}
}
});

let alloy_contract = &cx.crates.contract;
let generics_t_p_n = quote!(<T: alloy_contract::private::Transport + ::core::clone::Clone, P: alloy_contract::private::Provider<T, N>, N: alloy_contract::private::Network>);

let generic_p_n = quote!(<P: alloy_contract::private::Provider<N>, N: alloy_contract::private::Network>);

quote! {
use #alloy_contract as alloy_contract;

#[doc = #new_fn_doc]
#[inline]
pub const fn new #generics_t_p_n(
pub const fn new #generic_p_n(
address: alloy_sol_types::private::Address,
provider: P,
) -> #name<T, P, N> {
#name::<T, P, N>::new(address, provider)
) -> #name<P, N> {
#name::<P, N>::new(address, provider)
}

#deploy_fn

#[doc = #struct_doc]
#[derive(Clone)]
pub struct #name<T, P, N = alloy_contract::private::Ethereum> {
pub struct #name<P, N = alloy_contract::private::Ethereum> {
address: alloy_sol_types::private::Address,
provider: P,
_network_transport: ::core::marker::PhantomData<(N, T)>,
_network: ::core::marker::PhantomData<N>,
}

#[automatically_derived]
impl<T, P, N> ::core::fmt::Debug for #name<T, P, N> {
impl<P, N> ::core::fmt::Debug for #name<P, N> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple(#name_s).field(&self.address).finish()
Expand All @@ -406,11 +407,11 @@ pub(super) fn expand(cx: &mut ExpCtxt<'_>, contract: &ItemContract) -> Result<To

/// Instantiation and getters/setters.
#[automatically_derived]
impl #generics_t_p_n #name<T, P, N> {
impl #generic_p_n #name<P, N> {
#[doc = #new_fn_doc]
#[inline]
pub const fn new(address: alloy_sol_types::private::Address, provider: P) -> Self {
Self { address, provider, _network_transport: ::core::marker::PhantomData }
Self { address, provider, _network: ::core::marker::PhantomData }
}

#deploy_method
Expand Down Expand Up @@ -440,23 +441,23 @@ pub(super) fn expand(cx: &mut ExpCtxt<'_>, contract: &ItemContract) -> Result<To
}
}

impl<T, P: ::core::clone::Clone, N> #name<T, &P, N> {
impl<P: ::core::clone::Clone, N> #name<&P, N> {
/// Clones the provider and returns a new instance with the cloned provider.
#[inline]
pub fn with_cloned_provider(self) -> #name<T, P, N> {
#name { address: self.address, provider: ::core::clone::Clone::clone(&self.provider), _network_transport: ::core::marker::PhantomData }
pub fn with_cloned_provider(self) -> #name<P, N> {
#name { address: self.address, provider: ::core::clone::Clone::clone(&self.provider), _network: ::core::marker::PhantomData }
}
}

/// Function calls.
#[automatically_derived]
impl #generics_t_p_n #name<T, P, N> {
impl #generic_p_n #name<P, N> {
/// Creates a new call builder using this contract instance's provider and address.
///
/// Note that the call can be any function call, not just those defined in this
/// contract. Prefer using the other methods for building type-safe contract calls.
pub fn call_builder<C: alloy_sol_types::SolCall>(&self, call: &C)
-> alloy_contract::SolCallBuilder<T, &P, C, N>
-> alloy_contract::SolCallBuilder<&P, C, N>
{
alloy_contract::SolCallBuilder::new_sol(&self.provider, &self.address, call)
}
Expand All @@ -466,13 +467,13 @@ pub(super) fn expand(cx: &mut ExpCtxt<'_>, contract: &ItemContract) -> Result<To

/// Event filters.
#[automatically_derived]
impl #generics_t_p_n #name<T, P, N> {
impl #generic_p_n #name<P, N> {
/// Creates a new event filter using this contract instance's provider and address.
///
/// Note that the type can be any event, not just those defined in this contract.
/// Prefer using the other methods for building type-safe event filters.
pub fn event_filter<E: alloy_sol_types::SolEvent>(&self)
-> alloy_contract::Event<T, &P, E, N>
-> alloy_contract::Event<&P, E, N>
{
alloy_contract::Event::new_sol(&self.provider, &self.address)
}
Expand Down Expand Up @@ -988,7 +989,7 @@ fn call_builder_method(f: &ItemFunction, cx: &ExpCtxt<'_>) -> TokenStream {
let doc = format!("Creates a new call builder for the [`{name}`] function.");
quote! {
#[doc = #doc]
pub fn #name(&self, #(#param_names1: #param_tys),*) -> alloy_contract::SolCallBuilder<T, &P, #call_name, N> {
pub fn #name(&self, #(#param_names1: #param_tys),*) -> alloy_contract::SolCallBuilder<&P, #call_name, N> {
self.call_builder(&#call_name { #(#param_names2),* })
}
}
Expand Down