Skip to content

Commit

Permalink
Update to the latest alloy
Browse files Browse the repository at this point in the history
Also makes various tweaks as necessary.
  • Loading branch information
kayabaNerve committed May 10, 2024
1 parent 2112359 commit 5501de1
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 73 deletions.
63 changes: 33 additions & 30 deletions Cargo.lock

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

15 changes: 9 additions & 6 deletions coins/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ frost = { package = "modular-frost", path = "../../crypto/frost", default-featur

alloy-core = { version = "0.7", default-features = false }
alloy-sol-types = { version = "0.7", default-features = false, features = ["json"] }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "037dd4b20ec8533d6b6d5cf5e9489bbb182c18c6", default-features = false, features = ["k256"] }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "037dd4b20ec8533d6b6d5cf5e9489bbb182c18c6", default-features = false }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "037dd4b20ec8533d6b6d5cf5e9489bbb182c18c6", default-features = false }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false, features = ["k256"] }
alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false }
alloy-simple-request-transport = { path = "./alloy-simple-request-transport", default-features = false }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "037dd4b20ec8533d6b6d5cf5e9489bbb182c18c6", default-features = false }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false }

alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false, optional = true }

[dev-dependencies]
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false, features = ["tests"] }

tokio = { version = "1", features = ["macros"] }

alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "037dd4b20ec8533d6b6d5cf5e9489bbb182c18c6", default-features = false }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false }

[features]
tests = []
tests = ["alloy-node-bindings"]
4 changes: 2 additions & 2 deletions coins/ethereum/alloy-simple-request-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ tower = "0.4"
serde_json = { version = "1", default-features = false }
simple-request = { path = "../../../common/request", default-features = false }

alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "037dd4b20ec8533d6b6d5cf5e9489bbb182c18c6", default-features = false }
alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "037dd4b20ec8533d6b6d5cf5e9489bbb182c18c6", default-features = false }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false }
alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "b79db21734cffddc11753fe62ba571565c896f42", default-features = false }

[features]
default = ["tls"]
Expand Down
5 changes: 4 additions & 1 deletion coins/ethereum/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ pub fn address(point: &ProjectivePoint) -> [u8; 20] {
keccak256(&encoded_point.as_ref()[1 .. 65])[12 ..].try_into().unwrap()
}

pub(crate) fn deterministically_sign(tx: &TxLegacy) -> Signed<TxLegacy> {
/// Deterministically sign a transaction.
///
/// This function panics if passed a transaction with a non-None chain ID.
pub fn deterministically_sign(tx: &TxLegacy) -> Signed<TxLegacy> {
assert!(
tx.chain_id.is_none(),
"chain ID was Some when deterministically signing a TX (causing a non-deterministic signer)"
Expand Down
23 changes: 5 additions & 18 deletions coins/ethereum/src/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_core::primitives::{Address, B256, U256};

use alloy_sol_types::{SolInterface, SolEvent};

use alloy_rpc_types::{BlockNumberOrTag, Filter};
use alloy_rpc_types::Filter;
use alloy_simple_request_transport::SimpleRequest;
use alloy_provider::{Provider, RootProvider};

Expand All @@ -25,22 +25,8 @@ pub struct TopLevelErc20Transfer {
pub struct Erc20(Arc<RootProvider<SimpleRequest>>, Address);
impl Erc20 {
/// Construct a new view of the specified ERC20 contract.
///
/// This checks a contract is deployed at that address yet does not check the contract is
/// actually an ERC20.
pub async fn new(
provider: Arc<RootProvider<SimpleRequest>>,
address: [u8; 20],
) -> Result<Option<Self>, Error> {
let code = provider
.get_code_at(address.into(), BlockNumberOrTag::Finalized.into())
.await
.map_err(|_| Error::ConnectionError)?;
// Contract has yet to be deployed
if code.is_empty() {
return Ok(None);
}
Ok(Some(Self(provider.clone(), Address::from(&address))))
pub fn new(provider: Arc<RootProvider<SimpleRequest>>, address: [u8; 20]) -> Self {
Self(provider, Address::from(&address))
}

pub async fn top_level_transfers(
Expand All @@ -65,7 +51,8 @@ impl Erc20 {
}

let tx_id = log.transaction_hash.ok_or(Error::ConnectionError)?;
let tx = self.0.get_transaction_by_hash(tx_id).await.map_err(|_| Error::ConnectionError)?;
let tx =
self.0.get_transaction_by_hash(tx_id).await.ok().flatten().ok_or(Error::ConnectionError)?;

// If this is a top-level call...
if tx.to == Some(self.1) {
Expand Down
8 changes: 5 additions & 3 deletions coins/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use thiserror::Error;

pub use alloy_core;
pub use alloy_consensus;
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;
Expand All @@ -18,8 +20,8 @@ pub mod router;

pub mod machine;

#[cfg(test)]
mod tests;
#[cfg(any(test, feature = "tests"))]
pub mod tests;

#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
pub enum Error {
Expand Down
Loading

0 comments on commit 5501de1

Please sign in to comment.