Skip to content

Commit

Permalink
chore(docs): add doc aliases (alloy-rs#843)
Browse files Browse the repository at this point in the history
* add doc aliases

* more aliases

* more aliases

* more types

* more aliases

* add alias

* Apply suggestions from code review

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
  • Loading branch information
2 people authored and ben186 committed Jul 27, 2024
1 parent 268add4 commit b91990c
Show file tree
Hide file tree
Showing 52 changed files with 134 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/consensus/src/receipt/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use alloy_rlp::{Decodable, Encodable};
/// [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[doc(alias = "AnyTransactionReceiptEnvelope", alias = "AnyTxReceiptEnvelope")]
pub struct AnyReceiptEnvelope<T = Log> {
/// The receipt envelope.
#[cfg_attr(feature = "serde", serde(flatten))]
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type"))]
#[non_exhaustive]
#[doc(alias = "TransactionReceiptEnvelope", alias = "TxReceiptEnvelope")]
pub enum ReceiptEnvelope<T = Log> {
/// Receipt envelope with no type flag.
#[cfg_attr(feature = "serde", serde(rename = "0x0", alias = "0x00"))]
Expand All @@ -40,6 +41,7 @@ pub enum ReceiptEnvelope<T = Log> {

impl<T> ReceiptEnvelope<T> {
/// Return the [`TxType`] of the inner receipt.
#[doc(alias = "transaction_type")]
pub const fn tx_type(&self) -> TxType {
match self {
Self::Legacy(_) => TxType::Legacy,
Expand Down
1 change: 1 addition & 0 deletions crates/consensus/src/receipt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod receipts;
pub use receipts::{Receipt, ReceiptWithBloom};

/// Receipt is the result of a transaction execution.
#[doc(alias = "TransactionReceipt")]
pub trait TxReceipt<T = Log> {
/// Returns true if the transaction was successful.
fn status(&self) -> bool;
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use alloc::vec::Vec;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[doc(alias = "TransactionReceipt", alias = "TxReceipt")]
pub struct Receipt<T = Log> {
/// If transaction is executed successfully.
///
Expand Down Expand Up @@ -79,6 +80,7 @@ impl<T> From<ReceiptWithBloom<T>> for Receipt<T> {
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[doc(alias = "TransactionReceiptWithBloom", alias = "TxReceiptWithBloom")]
pub struct ReceiptWithBloom<T = Log> {
#[cfg_attr(feature = "serde", serde(flatten))]
/// The receipt.
Expand Down
4 changes: 4 additions & 0 deletions crates/consensus/src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ use alloy_primitives::{Signature, B256};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Signed<T, Sig = Signature> {
#[cfg_attr(feature = "serde", serde(flatten))]
#[doc(alias = "transaction")]
tx: T,
#[cfg_attr(feature = "serde", serde(flatten))]
signature: Sig,
#[doc(alias = "tx_hash", alias = "transaction_hash")]
hash: B256,
}

impl<T, Sig> Signed<T, Sig> {
/// Returns a reference to the transaction.
#[doc(alias = "transaction")]
pub const fn tx(&self) -> &T {
&self.tx
}
Expand All @@ -24,6 +27,7 @@ impl<T, Sig> Signed<T, Sig> {
}

/// Returns a reference to the transaction hash.
#[doc(alias = "tx_hash", alias = "transaction_hash")]
pub const fn hash(&self) -> &B256 {
&self.hash
}
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use alloc::vec::Vec;
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[doc(alias = "Eip1559Transaction", alias = "TransactionEip1559", alias = "Eip1559Tx")]
pub struct TxEip1559 {
/// EIP-155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
Expand Down Expand Up @@ -239,6 +240,7 @@ impl TxEip1559 {
}

/// Get transaction type
#[doc(alias = "transaction_type")]
pub(crate) const fn tx_type(&self) -> TxType {
TxType::Eip1559
}
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use alloc::vec::Vec;
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[doc(alias = "Eip2930Transaction", alias = "TransactionEip2930", alias = "Eip2930Tx")]
pub struct TxEip2930 {
/// Added as EIP-pub 155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
Expand Down Expand Up @@ -217,6 +218,7 @@ impl TxEip2930 {
}

/// Get transaction type.
#[doc(alias = "transaction_type")]
pub const fn tx_type(&self) -> TxType {
TxType::Eip2930
}
Expand Down
13 changes: 12 additions & 1 deletion crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use alloc::vec::Vec;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
#[doc(alias = "Eip4844TransactionVariant")]
pub enum TxEip4844Variant {
/// A standalone transaction with blob hashes and max blob fee.
TxEip4844(TxEip4844),
Expand All @@ -40,6 +41,7 @@ impl<'de> serde::Deserialize<'de> for TxEip4844Variant {
#[derive(serde::Deserialize)]
struct TxEip4844SerdeHelper {
#[serde(flatten)]
#[doc(alias = "transaction")]
tx: TxEip4844,
#[serde(flatten)]
sidecar: Option<BlobTransactionSidecar>,
Expand Down Expand Up @@ -89,11 +91,13 @@ impl TxEip4844Variant {
}

/// Get the transaction type.
#[doc(alias = "transaction_type")]
pub const fn tx_type(&self) -> TxType {
TxType::Eip4844
}

/// Get access to the inner tx [TxEip4844].
#[doc(alias = "transaction")]
pub const fn tx(&self) -> &TxEip4844 {
match self {
Self::TxEip4844(tx) => tx,
Expand Down Expand Up @@ -283,6 +287,7 @@ impl SignableTransaction<Signature> for TxEip4844Variant {
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[doc(alias = "Eip4844Transaction", alias = "TransactionEip4844", alias = "Eip4844Tx")]
pub struct TxEip4844 {
/// Added as EIP-pub 155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
Expand Down Expand Up @@ -571,7 +576,8 @@ impl TxEip4844 {
Ok(signed)
}

/// Get transaction type
/// Get transaction type.
#[doc(alias = "transaction_type")]
pub const fn tx_type(&self) -> TxType {
TxType::Eip4844
}
Expand Down Expand Up @@ -696,9 +702,11 @@ impl From<TxEip4844WithSidecar> for TxEip4844 {
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[doc(alias = "Eip4844TransactionWithSidecar", alias = "Eip4844TxWithSidecar")]
pub struct TxEip4844WithSidecar {
/// The actual transaction.
#[cfg_attr(feature = "serde", serde(flatten))]
#[doc(alias = "transaction")]
pub tx: TxEip4844,
/// The sidecar.
#[cfg_attr(feature = "serde", serde(flatten))]
Expand All @@ -707,6 +715,7 @@ pub struct TxEip4844WithSidecar {

impl TxEip4844WithSidecar {
/// Constructs a new [TxEip4844WithSidecar] from a [TxEip4844] and a [BlobTransactionSidecar].
#[doc(alias = "from_transaction_and_sidecar")]
pub const fn from_tx_and_sidecar(tx: TxEip4844, sidecar: BlobTransactionSidecar) -> Self {
Self { tx, sidecar }
}
Expand All @@ -723,11 +732,13 @@ impl TxEip4844WithSidecar {
}

/// Get the transaction type.
#[doc(alias = "transaction_type")]
pub const fn tx_type(&self) -> TxType {
self.tx.tx_type()
}

/// Get access to the inner tx [TxEip4844].
#[doc(alias = "transaction")]
pub const fn tx(&self) -> &TxEip4844 {
&self.tx
}
Expand Down
6 changes: 5 additions & 1 deletion crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSide
/// [4844]: https://eips.ethereum.org/EIPS/eip-4844
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[doc(alias = "TransactionType")]
pub enum TxType {
/// Legacy transaction type.
Legacy = 0,
Expand Down Expand Up @@ -79,6 +80,7 @@ impl TryFrom<u8> for TxType {
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type"))]
#[doc(alias = "TransactionEnvelope")]
#[non_exhaustive]
pub enum TxEnvelope {
/// An untagged [`TxLegacy`].
Expand Down Expand Up @@ -163,7 +165,8 @@ impl TxEnvelope {
}
}

/// Return the hash of the inner Signed
/// Return the hash of the inner Signed.
#[doc(alias = "transaction_hash")]
pub const fn tx_hash(&self) -> &B256 {
match self {
Self::Legacy(tx) => tx.hash(),
Expand All @@ -174,6 +177,7 @@ impl TxEnvelope {
}

/// Return the [`TxType`] of the inner txn.
#[doc(alias = "transaction_type")]
pub const fn tx_type(&self) -> TxType {
match self {
Self::Legacy(_) => TxType::Legacy,
Expand Down
1 change: 1 addition & 0 deletions crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use alloc::vec::Vec;
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[doc(alias = "LegacyTransaction", alias = "TransactionLegacy", alias = "LegacyTx")]
pub struct TxLegacy {
/// Added as EIP-155: Simple replay attack protection
#[cfg_attr(
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod typed;
pub use typed::TypedTransaction;

/// Represents a minimal EVM transaction.
#[doc(alias = "Tx")]
pub trait Transaction: any::Any + Send + Sync + 'static {
/// Get `data`.
fn input(&self) -> &[u8];
Expand Down Expand Up @@ -63,6 +64,7 @@ pub trait Transaction: any::Any + Send + Sync + 'static {
/// [`alloy_primitives::Signature`], however, it may be different for future EIP-2718 transaction
/// types, or in other networks. For example, in Optimism, the deposit transaction signature is the
/// unit type `()`.
#[doc(alias = "SignableTx", alias = "TxSignable")]
pub trait SignableTransaction<Signature>: Transaction {
/// True if the transaction uses EIP-155 signatures.
fn use_eip155(&self) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus/src/transaction/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use alloy_primitives::TxKind;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type"))]
#[doc(alias = "TypedTx", alias = "TxTyped", alias = "TransactionTyped")]
pub enum TypedTransaction {
/// Legacy transaction
#[cfg_attr(feature = "serde", serde(rename = "0x00", alias = "0x0"))]
Expand Down Expand Up @@ -78,6 +79,7 @@ impl From<TxEnvelope> for TypedTransaction {

impl TypedTransaction {
/// Return the [`TxType`] of the inner txn.
#[doc(alias = "transaction_type")]
pub const fn tx_type(&self) -> TxType {
match self {
Self::Legacy(_) => TxType::Legacy,
Expand Down
1 change: 1 addition & 0 deletions crates/eips/src/eip1898.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct RpcBlockHash {

impl RpcBlockHash {
/// Returns an [RpcBlockHash] from a [B256].
#[doc(alias = "from_block_hash")]
pub const fn from_hash(block_hash: B256, require_canonical: Option<bool>) -> Self {
Self { block_hash, require_canonical }
}
Expand Down
1 change: 1 addition & 0 deletions crates/eips/src/eip4844/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use alloc::vec::Vec;
#[repr(C)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(proptest_derive::Arbitrary))]
#[doc(alias = "BlobTxSidecar")]
pub struct BlobTransactionSidecar {
/// The blob data.
#[cfg_attr(
Expand Down
2 changes: 2 additions & 0 deletions crates/network/src/any/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ impl TransactionBuilder<AnyNetwork> for WithOtherFields<TransactionRequest> {
self.deref().can_submit()
}

#[doc(alias = "output_transaction_type")]
fn output_tx_type(&self) -> <AnyNetwork as Network>::TxType {
self.deref().output_tx_type().into()
}

#[doc(alias = "output_transaction_type_checked")]
fn output_tx_type_checked(&self) -> Option<<AnyNetwork as Network>::TxType> {
self.deref().output_tx_type_checked().map(Into::into)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/network/src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use alloy_rpc_types::{
mod builder;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(alias = "AnyTransactionType")]
pub struct AnyTxType(u8);

impl fmt::Display for AnyTxType {
Expand Down Expand Up @@ -83,6 +84,7 @@ impl ReceiptResponse for AnyTransactionReceipt {
}

impl TransactionResponse for WithOtherFields<Transaction> {
#[doc(alias = "transaction_hash")]
fn tx_hash(&self) -> alloy_primitives::B256 {
self.hash
}
Expand Down
2 changes: 2 additions & 0 deletions crates/network/src/ethereum/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ impl TransactionBuilder<Ethereum> for TransactionRequest {
common && (legacy || eip2930 || eip1559 || eip4844)
}

#[doc(alias = "output_transaction_type")]
fn output_tx_type(&self) -> TxType {
self.preferred_type()
}

#[doc(alias = "output_transaction_type_checked")]
fn output_tx_type_checked(&self) -> Option<TxType> {
self.buildable_type()
}
Expand Down
1 change: 1 addition & 0 deletions crates/network/src/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl ReceiptResponse for alloy_rpc_types::TransactionReceipt {
}

impl TransactionResponse for alloy_rpc_types::Transaction {
#[doc(alias = "transaction_hash")]
fn tx_hash(&self) -> alloy_primitives::B256 {
self.hash
}
Expand Down
2 changes: 2 additions & 0 deletions crates/network/src/ethereum/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl EthereumSigner {
self.secp_signers.get(&address).cloned()
}

#[doc(alias = "sign_tx_inner")]
async fn sign_transaction_inner(
&self,
sender: Address,
Expand Down Expand Up @@ -112,6 +113,7 @@ where
self.secp_signers.keys().copied()
}

#[doc(alias = "sign_tx_from")]
async fn sign_transaction_from(
&self,
sender: Address,
Expand Down
8 changes: 8 additions & 0 deletions crates/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub trait ReceiptResponse {
/// [`Transaction`]: alloy_consensus::Transaction
pub trait TransactionResponse {
/// Hash of the transaction
#[doc(alias = "transaction_hash")]
fn tx_hash(&self) -> B256;

/// Sender of the transaction
Expand Down Expand Up @@ -70,6 +71,7 @@ pub trait Network: Debug + Clone + Copy + Sized + Send + Sync + 'static {
///
/// This should be a simple `#[repr(u8)]` enum, and as such has strict type
/// bounds for better use in error messages, assertions etc.
#[doc(alias = "TransactionType")]
type TxType: Into<u8>
+ PartialEq
+ Eq
Expand All @@ -83,12 +85,15 @@ pub trait Network: Debug + Clone + Copy + Sized + Send + Sync + 'static {
+ 'static;

/// The network transaction envelope type.
#[doc(alias = "TransactionEnvelope")]
type TxEnvelope: Eip2718Envelope + Debug;

/// An enum over the various transaction types.
#[doc(alias = "UnsignedTransaction")]
type UnsignedTx: From<Self::TxEnvelope>;

/// The network receipt envelope type.
#[doc(alias = "TransactionReceiptEnvelope", alias = "TxReceiptEnvelope")]
type ReceiptEnvelope: Eip2718Envelope + TxReceipt;

/// The network header type.
Expand All @@ -97,16 +102,19 @@ pub trait Network: Debug + Clone + Copy + Sized + Send + Sync + 'static {
// -- JSON RPC types --

/// The JSON body of a transaction request.
#[doc(alias = "TxRequest")]
type TransactionRequest: RpcObject
+ TransactionBuilder<Self>
+ Debug
+ From<Self::TxEnvelope>
+ From<Self::UnsignedTx>;

/// The JSON body of a transaction response.
#[doc(alias = "TxResponse")]
type TransactionResponse: RpcObject + TransactionResponse;

/// The JSON body of a transaction receipt.
#[doc(alias = "TransactionReceiptResponse", alias = "TxReceiptResponse")]
type ReceiptResponse: RpcObject + ReceiptResponse;

/// The JSON body of a header response.
Expand Down
Loading

0 comments on commit b91990c

Please sign in to comment.