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

feat: helpers for AnyNetwork #476

Merged
merged 5 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions crates/network/src/any/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{Network, ReceiptResponse};
use alloy_consensus::AnyReceiptEnvelope;
use alloy_rpc_types::{
Header, Log, Transaction, TransactionReceipt, TransactionRequest, WithOtherFields,
AnyTransactionReceipt, Header, Transaction, TransactionRequest, WithOtherFields,
};

mod builder;
Expand Down Expand Up @@ -29,12 +28,12 @@ impl Network for AnyNetwork {

type TransactionResponse = WithOtherFields<Transaction>;

type ReceiptResponse = WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Log>>>;
type ReceiptResponse = AnyTransactionReceipt;

type HeaderResponse = WithOtherFields<Header>;
}

impl ReceiptResponse for WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Log>>> {
impl ReceiptResponse for AnyTransactionReceipt {
fn contract_address(&self) -> Option<alloy_primitives::Address> {
self.contract_address
}
Expand Down
8 changes: 5 additions & 3 deletions crates/network/src/ethereum/signer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::Ethereum;
use crate::{NetworkSigner, TxSigner};
use crate::{Network, NetworkSigner, TxSigner};
use alloy_consensus::{SignableTransaction, TxEnvelope, TypedTransaction};
use alloy_signer::Signature;
use async_trait::async_trait;
Expand Down Expand Up @@ -43,7 +42,10 @@ impl EthereumSigner {

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl NetworkSigner<Ethereum> for EthereumSigner {
impl<N> NetworkSigner<N> for EthereumSigner
where
N: Network<UnsignedTx = TypedTransaction, TxEnvelope = TxEnvelope>,
{
async fn sign_transaction(&self, tx: TypedTransaction) -> alloy_signer::Result<TxEnvelope> {
match tx {
TypedTransaction::Legacy(mut t) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-types/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use optimism::OptimismTransactionReceiptFields;

mod receipt;
pub use alloy_consensus::{AnyReceiptEnvelope, Receipt, ReceiptEnvelope, ReceiptWithBloom};
pub use receipt::TransactionReceipt;
pub use receipt::{AnyTransactionReceipt, TransactionReceipt};

pub mod request;
pub use request::{TransactionInput, TransactionRequest};
Expand Down
7 changes: 5 additions & 2 deletions crates/rpc-types/src/eth/transaction/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Log;
use alloy_consensus::{ReceiptEnvelope, TxType};
use crate::{Log, WithOtherFields};
use alloy_consensus::{AnyReceiptEnvelope, ReceiptEnvelope, TxType};
use alloy_primitives::{Address, B256};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -115,6 +115,9 @@ impl<T> TransactionReceipt<T> {
}
}

/// Alias for a catch-all receipt type.
pub type AnyTransactionReceipt = WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Log>>>;

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading