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, Transaction, 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, NetworkTransactionBuilder, NetworkWallet,
18 TransactionBuilder, TransactionBuilder4844, TransactionBuilder7702, TransactionBuilderError,
19 TxSigner, 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 {
43 #[doc(alias = "TransactionType")]
50 type TxType: Typed2718
51 + Into<u8>
52 + PartialEq
53 + Eq
54 + TryFrom<u8, Error = Eip2718Error>
55 + Debug
56 + Display
57 + Clone
58 + Copy
59 + Send
60 + Sync
61 + 'static;
62
63 #[doc(alias = "TransactionEnvelope")]
65 type TxEnvelope: Eip2718Envelope + Transaction + Debug + Clone;
66
67 #[doc(alias = "UnsignedTransaction")]
69 type UnsignedTx: From<Self::TxEnvelope>;
70
71 #[doc(alias = "TransactionReceiptEnvelope", alias = "TxReceiptEnvelope")]
73 type ReceiptEnvelope: Eip2718Envelope + TxReceipt;
74
75 type Header: BlockHeader;
77
78 #[doc(alias = "TxRequest")]
82 type TransactionRequest: RpcObject
83 + NetworkTransactionBuilder<Self>
84 + Debug
85 + From<Self::TxEnvelope>
86 + From<Self::UnsignedTx>
87 + From<Self::TransactionResponse>;
88
89 #[doc(alias = "TxResponse")]
91 type TransactionResponse: RpcObject + TransactionResponse + AsRef<Self::TxEnvelope>;
92
93 #[doc(alias = "TransactionReceiptResponse", alias = "TxReceiptResponse")]
95 type ReceiptResponse: RpcObject + ReceiptResponse;
96
97 type HeaderResponse: RpcObject + HeaderResponse + AsRef<Self::Header>;
99
100 type BlockResponse: RpcObject
102 + BlockResponse<Transaction = Self::TransactionResponse, Header = Self::HeaderResponse>;
103}
104
105#[macro_export]
107macro_rules! impl_into_wallet {
108 ($(@[$($generics:tt)*])? $signer:ty) => {
109 impl $(<$($generics)*>)? $crate::IntoWallet for $signer {
110 type NetworkWallet = $crate::EthereumWallet;
111 fn into_wallet(self) -> Self::NetworkWallet {
112 $crate::EthereumWallet::from(self)
113 }
114 }
115
116 impl $(<$($generics)*>)? $crate::IntoWallet<$crate::AnyNetwork> for $signer {
117 type NetworkWallet = $crate::EthereumWallet;
118 fn into_wallet(self) -> Self::NetworkWallet {
119 $crate::EthereumWallet::from(self)
120 }
121 }
122 };
123}