Skip to content

Commit

Permalink
Add our own alloy meta module to deduplicate alloy prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed May 14, 2024
1 parent af79586 commit ae8a27b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 59 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions coins/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use thiserror::Error;

pub use alloy_core;
pub use alloy_sol_types;

pub use alloy_consensus;
pub use alloy_network;
pub use alloy_rpc_types;
pub use alloy_simple_request_transport;
pub use alloy_rpc_client;
pub use alloy_provider;
pub mod alloy {
pub use alloy_core::primitives;
pub use alloy_core as core;
pub use alloy_sol_types as sol_types;

pub use alloy_consensus as consensus;
pub use alloy_network as network;
pub use alloy_rpc_types as rpc_types;
pub use alloy_simple_request_transport as simple_request_transport;
pub use alloy_rpc_client as rpc_client;
pub use alloy_provider as provider;
}

pub mod crypto;

Expand Down
26 changes: 14 additions & 12 deletions processor/src/networks/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ use ciphersuite::{group::GroupEncoding, Ciphersuite, Secp256k1};
use frost::ThresholdKeys;

use ethereum_serai::{
alloy_core::primitives::U256,
alloy_rpc_types::{BlockNumberOrTag, Transaction},
alloy_simple_request_transport::SimpleRequest,
alloy_rpc_client::ClientBuilder,
alloy_provider::{Provider, RootProvider},
alloy::{
primitives::U256,
rpc_types::{BlockNumberOrTag, Transaction},
simple_request_transport::SimpleRequest,
rpc_client::ClientBuilder,
provider::{Provider, RootProvider},
},
crypto::{PublicKey, Signature},
erc20::Erc20,
deployer::Deployer,
router::{Router, Coin as EthereumCoin, InInstruction as EthereumInInstruction},
machine::*,
};
#[cfg(test)]
use ethereum_serai::alloy_core::primitives::B256;
use ethereum_serai::alloy::primitives::B256;

use tokio::{
time::sleep,
Expand Down Expand Up @@ -112,7 +114,7 @@ impl TryInto<Vec<u8>> for Address {

impl fmt::Display for Address {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ethereum_serai::alloy_core::primitives::Address::from(self.0).fmt(f)
ethereum_serai::alloy::primitives::Address::from(self.0).fmt(f)
}
}

Expand Down Expand Up @@ -181,7 +183,7 @@ impl<D: Db> Output<Ethereum<D>> for EthereumInInstruction {
let mut id = [0; 40];
id[.. 32].copy_from_slice(&self.id.0);
id[32 ..].copy_from_slice(&self.id.1.to_le_bytes());
*ethereum_serai::alloy_core::primitives::keccak256(id)
*ethereum_serai::alloy::primitives::keccak256(id)
}
fn tx_id(&self) -> [u8; 32] {
self.id.0
Expand Down Expand Up @@ -853,7 +855,7 @@ impl<D: Db> Network for Ethereum<D> {
async fn test_send(&self, send_to: Self::Address) -> Self::Block {
use rand_core::OsRng;
use ciphersuite::group::ff::Field;
use ethereum_serai::alloy_sol_types::SolCall;
use ethereum_serai::alloy::sol_types::SolCall;

let key = <Secp256k1 as Ciphersuite>::F::random(&mut OsRng);
let address = ethereum_serai::crypto::address(&(Secp256k1::generator() * key));
Expand All @@ -869,12 +871,12 @@ impl<D: Db> Network for Ethereum<D> {
.unwrap();

let value = U256::from_str_radix("1000000000000000000", 10).unwrap();
let tx = ethereum_serai::alloy_consensus::TxLegacy {
let tx = ethereum_serai::alloy::consensus::TxLegacy {
chain_id: None,
nonce: 0,
gas_price: 1_000_000_000u128,
gas_limit: 200_000u128,
to: ethereum_serai::alloy_core::primitives::TxKind::Call(send_to.0.into()),
to: ethereum_serai::alloy::primitives::TxKind::Call(send_to.0.into()),
// 1 ETH
value,
input: ethereum_serai::router::abi::inInstructionCall::new((
Expand All @@ -886,7 +888,7 @@ impl<D: Db> Network for Ethereum<D> {
.into(),
};

use ethereum_serai::alloy_consensus::SignableTransaction;
use ethereum_serai::alloy::consensus::SignableTransaction;
let sig = k256::ecdsa::SigningKey::from(k256::elliptic_curve::NonZeroScalar::new(key).unwrap())
.sign_prehash_recoverable(tx.signature_hash().as_ref())
.unwrap();
Expand Down
10 changes: 6 additions & 4 deletions processor/src/tests/literal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,12 @@ mod ethereum {
) -> impl Fn(MemDb) -> Pin<Box<dyn Send + Future<Output = Ethereum<MemDb>>>> {
use std::sync::Arc;
use ethereum_serai::{
alloy_core::primitives::U256,
alloy_simple_request_transport::SimpleRequest,
alloy_rpc_client::ClientBuilder,
alloy_provider::{Provider, RootProvider},
alloy::{
primitives::U256,
simple_request_transport::SimpleRequest,
rpc_client::ClientBuilder,
provider::{Provider, RootProvider},
},
deployer::Deployer,
};

Expand Down
54 changes: 27 additions & 27 deletions tests/processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ impl Coordinator {
}
}
NetworkId::Ethereum => {
use ethereum_serai::{
alloy_simple_request_transport::SimpleRequest,
alloy_rpc_client::ClientBuilder,
alloy_provider::{Provider, RootProvider},
alloy_network::Ethereum,
use ethereum_serai::alloy::{
simple_request_transport::SimpleRequest,
rpc_client::ClientBuilder,
provider::{Provider, RootProvider},
network::Ethereum,
};

let provider = RootProvider::<_, Ethereum>::new(
Expand Down Expand Up @@ -293,12 +293,12 @@ impl Coordinator {
(hash, block_buf)
}
NetworkId::Ethereum => {
use ethereum_serai::{
alloy_simple_request_transport::SimpleRequest,
alloy_rpc_types::BlockNumberOrTag,
alloy_rpc_client::ClientBuilder,
alloy_provider::{Provider, RootProvider},
alloy_network::Ethereum,
use ethereum_serai::alloy::{
simple_request_transport::SimpleRequest,
rpc_types::BlockNumberOrTag,
rpc_client::ClientBuilder,
provider::{Provider, RootProvider},
network::Ethereum,
};

let provider = RootProvider::<_, Ethereum>::new(
Expand Down Expand Up @@ -395,11 +395,11 @@ impl Coordinator {
}
}
NetworkId::Ethereum => {
use ethereum_serai::{
alloy_simple_request_transport::SimpleRequest,
alloy_rpc_client::ClientBuilder,
alloy_provider::{Provider, RootProvider},
alloy_network::Ethereum,
use ethereum_serai::alloy::{
simple_request_transport::SimpleRequest,
rpc_client::ClientBuilder,
provider::{Provider, RootProvider},
network::Ethereum,
};

let provider = RootProvider::<_, Ethereum>::new(
Expand Down Expand Up @@ -464,11 +464,11 @@ impl Coordinator {
rpc.send_raw_transaction(&Transaction::consensus_decode(&mut &*tx).unwrap()).await.unwrap();
}
NetworkId::Ethereum => {
use ethereum_serai::{
alloy_simple_request_transport::SimpleRequest,
alloy_rpc_client::ClientBuilder,
alloy_provider::{Provider, RootProvider},
alloy_network::Ethereum,
use ethereum_serai::alloy::{
simple_request_transport::SimpleRequest,
rpc_client::ClientBuilder,
provider::{Provider, RootProvider},
network::Ethereum,
};

let provider = RootProvider::<_, Ethereum>::new(
Expand Down Expand Up @@ -517,12 +517,12 @@ impl Coordinator {
}
}
NetworkId::Ethereum => {
use ethereum_serai::{
alloy_simple_request_transport::SimpleRequest,
alloy_consensus::{TxLegacy, Signed},
alloy_rpc_client::ClientBuilder,
alloy_provider::{Provider, RootProvider},
alloy_network::Ethereum,
use ethereum_serai::alloy::{
consensus::{TxLegacy, Signed},
simple_request_transport::SimpleRequest,
rpc_client::ClientBuilder,
provider::{Provider, RootProvider},
network::Ethereum,
};

let provider = RootProvider::<_, Ethereum>::new(
Expand Down
14 changes: 7 additions & 7 deletions tests/processor/src/networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ impl Wallet {

NetworkId::Ethereum => {
use ciphersuite::{group::ff::Field, Ciphersuite, Secp256k1};
use ethereum_serai::{
alloy_core::primitives::{U256, Address},
alloy_simple_request_transport::SimpleRequest,
alloy_rpc_client::ClientBuilder,
alloy_provider::{Provider, RootProvider},
alloy_network::Ethereum,
use ethereum_serai::alloy::{
primitives::{U256, Address},
simple_request_transport::SimpleRequest,
rpc_client::ClientBuilder,
provider::{Provider, RootProvider},
network::Ethereum,
};

let key = <Secp256k1 as Ciphersuite>::F::random(&mut OsRng);
Expand Down Expand Up @@ -330,7 +330,7 @@ impl Wallet {

Wallet::Ethereum { key, ref mut nonce } => {
/*
use ethereum_serai::alloy_core::primitives::U256;
use ethereum_serai::alloy::primitives::U256;
let eight_decimals = U256::from(100_000_000u64);
let nine_decimals = eight_decimals * U256::from(10u64);
Expand Down

0 comments on commit ae8a27b

Please sign in to comment.