Skip to content

Commit

Permalink
chore: remove unneeded ethers conversions (#7103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir authored Feb 13, 2024
1 parent 446bba8 commit 5a9b1dc
Showing 1 changed file with 5 additions and 104 deletions.
109 changes: 5 additions & 104 deletions crates/common/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
//! Temporary utility conversion traits between ethers-rs and alloy types.
use alloy_json_abi::{Event, EventParam, Function, InternalType, Param, StateMutability};
use alloy_primitives::{Address, Bloom, Bytes, B256, B64, I256, U128, U256, U64};
use alloy_rpc_types::{
other::OtherFields,
request::{TransactionInput, TransactionRequest as CallRequest},
AccessList, AccessListItem, Signature, Transaction,
};
use alloy_signer::{LocalWallet, Signer};
use ethers_core::{
abi as ethabi,
types::{
transaction::eip2930::{
AccessList as EthersAccessList, AccessListItem as EthersAccessListItem,
},
Bloom as EthersBloom, Bytes as EthersBytes, TransactionRequest, H160, H256, H64,
I256 as EthersI256, U256 as EthersU256, U64 as EthersU64,
use ethers_core::types::{
transaction::eip2930::{
AccessList as EthersAccessList, AccessListItem as EthersAccessListItem,
},
Bloom as EthersBloom, Bytes as EthersBytes, TransactionRequest, H160, H256, H64,
I256 as EthersI256, U256 as EthersU256, U64 as EthersU64,
};

/// Conversion trait to easily convert from Ethers types to Alloy types.
Expand Down Expand Up @@ -211,101 +207,6 @@ impl ToAlloy for EthersAccessListItem {
}
}

impl ToAlloy for ethabi::Event {
type To = Event;

fn to_alloy(self) -> Self::To {
Event {
name: self.name,
inputs: self.inputs.into_iter().map(ToAlloy::to_alloy).collect(),
anonymous: self.anonymous,
}
}
}

impl ToAlloy for ethabi::Function {
type To = Function;

fn to_alloy(self) -> Self::To {
Function {
name: self.name,
inputs: self.inputs.into_iter().map(ToAlloy::to_alloy).collect(),
outputs: self.outputs.into_iter().map(ToAlloy::to_alloy).collect(),
state_mutability: self.state_mutability.to_alloy(),
}
}
}

impl ToAlloy for ethabi::Param {
type To = Param;

fn to_alloy(self) -> Self::To {
let (ty, components) = self.kind.to_alloy();
Param {
name: self.name,
ty,
internal_type: self.internal_type.as_deref().and_then(InternalType::parse),
components,
}
}
}

impl ToAlloy for ethabi::EventParam {
type To = EventParam;

fn to_alloy(self) -> Self::To {
let (ty, components) = self.kind.to_alloy();
EventParam { name: self.name, ty, internal_type: None, components, indexed: self.indexed }
}
}

impl ToAlloy for ethabi::ParamType {
type To = (String, Vec<Param>);

fn to_alloy(self) -> Self::To {
let (s, t) = split_pt(self);
(s, t.into_iter().map(pt_to_param).collect())
}
}

fn split_pt(x: ethabi::ParamType) -> (String, Vec<ethabi::ParamType>) {
let s = ethabi::ethabi::param_type::Writer::write_for_abi(&x, false);
let t = get_tuple(x);
(s, t)
}

fn get_tuple(x: ethabi::ParamType) -> Vec<ethabi::ParamType> {
match x {
ethabi::ParamType::FixedArray(x, _) | ethabi::ParamType::Array(x) => get_tuple(*x),
ethabi::ParamType::Tuple(t) => t,
_ => Default::default(),
}
}

fn pt_to_param(x: ethabi::ParamType) -> Param {
let (ty, components) = split_pt(x);
Param {
name: String::new(),
ty,
internal_type: None,
components: components.into_iter().map(pt_to_param).collect(),
}
}

impl ToAlloy for ethabi::StateMutability {
type To = StateMutability;

#[inline(always)]
fn to_alloy(self) -> Self::To {
match self {
ethabi::StateMutability::Pure => StateMutability::Pure,
ethabi::StateMutability::View => StateMutability::View,
ethabi::StateMutability::NonPayable => StateMutability::NonPayable,
ethabi::StateMutability::Payable => StateMutability::Payable,
}
}
}

/// Conversion trait to easily convert from Alloy types to Ethers types.
pub trait ToEthers {
/// The corresponding Ethers type.
Expand Down

0 comments on commit 5a9b1dc

Please sign in to comment.