fix(contract): relax Middleware trait bound for getters (#1728)

* wip

* fix(contract): relax Middleware trait bound for getters

* chore: clippy

* move

* fix: multicall
This commit is contained in:
DaniPopes 2022-09-24 02:32:24 +02:00 committed by GitHub
parent dc68de8cdc
commit 733c5d3dfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 40 deletions

View File

@ -95,7 +95,6 @@ pub(crate) fn struct_declaration(cx: &Context) -> TokenStream {
let abi_name = cx.inline_abi_ident();
let ethers_core = ethers_core_crate();
let ethers_providers = ethers_providers_crate();
let ethers_contract = ethers_contract_crate();
let abi_parse = if !cx.human_readable {
@ -144,7 +143,7 @@ pub(crate) fn struct_declaration(cx: &Context) -> TokenStream {
fn deref(&self) -> &Self::Target { &self.0 }
}
impl<M: #ethers_providers::Middleware> std::fmt::Debug for #name<M> {
impl<M> std::fmt::Debug for #name<M> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_tuple(stringify!(#name))
.field(&self.address())

View File

@ -152,9 +152,16 @@ use std::{fmt::Debug, marker::PhantomData, sync::Arc};
/// [`method`]: method@crate::Contract::method
#[derive(Debug)]
pub struct Contract<M> {
address: Address,
base_contract: BaseContract,
client: Arc<M>,
address: Address,
}
impl<M> std::ops::Deref for Contract<M> {
type Target = BaseContract;
fn deref(&self) -> &Self::Target {
&self.base_contract
}
}
impl<M> Clone for Contract<M> {
@ -167,10 +174,31 @@ impl<M> Clone for Contract<M> {
}
}
impl<M> Contract<M> {
/// Returns the contract's address
pub fn address(&self) -> Address {
self.address
}
/// Returns a reference to the contract's ABI
pub fn abi(&self) -> &Abi {
&self.base_contract.abi
}
/// Returns a reference to the contract's client
pub fn client(&self) -> &M {
&self.client
}
}
impl<M: Middleware> Contract<M> {
/// Creates a new contract from the provided client, abi and address
pub fn new(address: Address, abi: impl Into<BaseContract>, client: impl Into<Arc<M>>) -> Self {
Self { base_contract: abi.into(), client: client.into(), address }
pub fn new(
address: impl Into<Address>,
abi: impl Into<BaseContract>,
client: impl Into<Arc<M>>,
) -> Self {
Self { base_contract: abi.into(), client: client.into(), address: address.into() }
}
/// Returns an [`Event`](crate::builders::Event) builder for the provided event.
@ -277,26 +305,4 @@ impl<M: Middleware> Contract<M> {
{
Contract { base_contract: self.base_contract.clone(), client, address: self.address }
}
/// Returns the contract's address
pub fn address(&self) -> Address {
self.address
}
/// Returns a reference to the contract's ABI
pub fn abi(&self) -> &Abi {
&self.base_contract.abi
}
/// Returns a reference to the contract's client
pub fn client(&self) -> &M {
&self.client
}
}
impl<M: Middleware> std::ops::Deref for Contract<M> {
type Target = BaseContract;
fn deref(&self) -> &Self::Target {
&self.base_contract
}
}

View File

@ -26,7 +26,7 @@ pub mod multicall_3 {
&self.0
}
}
impl<M: ethers_providers::Middleware> std::fmt::Debug for Multicall3<M> {
impl<M> std::fmt::Debug for Multicall3<M> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_tuple(stringify!(Multicall3)).field(&self.address()).finish()
}

View File

@ -339,13 +339,7 @@ impl I256 {
/// Returns an `i64` representing the sign of the number.
fn signum64(self) -> i64 {
match self.sign() {
Sign::Positive => {
if self.is_zero() {
0
} else {
1
}
}
Sign::Positive => (!self.is_zero()) as i64,
Sign::Negative => -1,
}
}

View File

@ -141,11 +141,7 @@ impl LedgerEthereum {
signature.v = match tx {
TypedTransaction::Eip2930(_) | TypedTransaction::Eip1559(_) => {
if ecc_parity % 2 == 1 {
0
} else {
1
}
(ecc_parity % 2 != 1) as u64
}
TypedTransaction::Legacy(_) => eip155_chain_id + ecc_parity,
};