1#![doc = include_str!("../README.md")]
2#![doc(
3    html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
4    html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
5)]
6#![cfg_attr(not(test), warn(unused_crate_dependencies))]
7#![cfg_attr(docsrs, feature(doc_cfg))]
8
9use alloy_consensus::{BlockHeader, TxReceipt};
10use alloy_eips::eip2718::{Eip2718Envelope, Eip2718Error};
11use alloy_json_rpc::RpcObject;
12use alloy_network_primitives::HeaderResponse;
13use core::fmt::{Debug, Display};
14
15mod transaction;
16pub use transaction::{
17    BuildResult, FullSigner, FullSignerSync, NetworkWallet, TransactionBuilder,
18    TransactionBuilder4844, TransactionBuilder7702, TransactionBuilderError, TxSigner,
19    TxSignerSync, UnbuiltTransactionError,
20};
21
22mod ethereum;
23pub use ethereum::{Ethereum, EthereumWallet, IntoWallet};
24
25pub mod any;
27pub use any::{
28    AnyHeader, AnyNetwork, AnyReceiptEnvelope, AnyRpcBlock, AnyRpcHeader, AnyRpcTransaction,
29    AnyTransactionReceipt, AnyTxEnvelope, AnyTxType, AnyTypedTransaction, UnknownTxEnvelope,
30    UnknownTypedTransaction,
31};
32
33pub use alloy_eips::eip2718;
34use alloy_eips::Typed2718;
35pub use alloy_network_primitives::{
36    self as primitives, BlockResponse, ReceiptResponse, TransactionResponse,
37};
38
39pub trait Network: Debug + Clone + Copy + Sized + Send + Sync + 'static {
45    #[doc(alias = "TransactionType")]
52    type TxType: Typed2718
53        + Into<u8>
54        + PartialEq
55        + Eq
56        + TryFrom<u8, Error = Eip2718Error>
57        + Debug
58        + Display
59        + Clone
60        + Copy
61        + Send
62        + Sync
63        + 'static;
64
65    #[doc(alias = "TransactionEnvelope")]
67    type TxEnvelope: Eip2718Envelope + Debug;
68
69    #[doc(alias = "UnsignedTransaction")]
71    type UnsignedTx: From<Self::TxEnvelope>;
72
73    #[doc(alias = "TransactionReceiptEnvelope", alias = "TxReceiptEnvelope")]
75    type ReceiptEnvelope: Eip2718Envelope + TxReceipt;
76
77    type Header: BlockHeader;
79
80    #[doc(alias = "TxRequest")]
84    type TransactionRequest: RpcObject
85        + TransactionBuilder<Self>
86        + Debug
87        + From<Self::TxEnvelope>
88        + From<Self::UnsignedTx>;
89
90    #[doc(alias = "TxResponse")]
92    type TransactionResponse: RpcObject + TransactionResponse + AsRef<Self::TxEnvelope>;
93
94    #[doc(alias = "TransactionReceiptResponse", alias = "TxReceiptResponse")]
96    type ReceiptResponse: RpcObject + ReceiptResponse;
97
98    type HeaderResponse: RpcObject + HeaderResponse + AsRef<Self::Header>;
100
101    type BlockResponse: RpcObject
103        + BlockResponse<Transaction = Self::TransactionResponse, Header = Self::HeaderResponse>;
104}
105
106#[macro_export]
108macro_rules! impl_into_wallet {
109    ($(@[$($generics:tt)*])? $signer:ty) => {
110        impl $(<$($generics)*>)? $crate::IntoWallet for $signer {
111            type NetworkWallet = $crate::EthereumWallet;
112            fn into_wallet(self) -> Self::NetworkWallet {
113                $crate::EthereumWallet::from(self)
114            }
115        }
116
117        impl $(<$($generics)*>)? $crate::IntoWallet<$crate::AnyNetwork> for $signer {
118            type NetworkWallet = $crate::EthereumWallet;
119            fn into_wallet(self) -> Self::NetworkWallet {
120                $crate::EthereumWallet::from(self)
121            }
122        }
123    };
124}