use alloy_eips::eip7702::SignedAuthorization;
use alloy_primitives::{Address, BlockHash, Bytes, TxHash, B256, U256};
use alloy_serde::WithOtherFields;
use crate::BlockTransactions;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
pub trait ReceiptResponse {
fn contract_address(&self) -> Option<Address>;
fn status(&self) -> bool;
fn block_hash(&self) -> Option<BlockHash>;
fn block_number(&self) -> Option<u64>;
fn transaction_hash(&self) -> TxHash;
fn transaction_index(&self) -> Option<u64>;
fn gas_used(&self) -> u128;
fn effective_gas_price(&self) -> u128;
fn blob_gas_used(&self) -> Option<u128>;
fn blob_gas_price(&self) -> Option<u128>;
fn from(&self) -> Address;
fn to(&self) -> Option<Address>;
fn authorization_list(&self) -> Option<&[SignedAuthorization]>;
}
pub trait TransactionResponse {
#[doc(alias = "transaction_hash")]
fn tx_hash(&self) -> TxHash;
fn from(&self) -> Address;
fn to(&self) -> Option<Address>;
fn value(&self) -> U256;
fn gas(&self) -> u128;
#[doc(alias = "calldata")]
fn input(&self) -> &Bytes;
}
pub trait HeaderResponse {
fn hash(&self) -> BlockHash;
fn number(&self) -> u64;
fn timestamp(&self) -> u64;
fn extra_data(&self) -> &Bytes;
fn base_fee_per_gas(&self) -> Option<u128>;
fn next_block_blob_fee(&self) -> Option<u128>;
fn coinbase(&self) -> Address;
fn gas_limit(&self) -> u128;
fn mix_hash(&self) -> Option<B256>;
fn difficulty(&self) -> U256;
}
pub trait BlockResponse {
type Header;
type Transaction;
fn header(&self) -> &Self::Header;
fn transactions(&self) -> &BlockTransactions<Self::Transaction>;
fn transactions_mut(&mut self) -> &mut BlockTransactions<Self::Transaction>;
fn other_fields(&self) -> Option<&alloy_serde::OtherFields> {
None
}
}
impl<T: TransactionResponse> TransactionResponse for WithOtherFields<T> {
fn tx_hash(&self) -> TxHash {
self.inner.tx_hash()
}
fn from(&self) -> Address {
self.inner.from()
}
fn to(&self) -> Option<Address> {
self.inner.to()
}
fn value(&self) -> U256 {
self.inner.value()
}
fn gas(&self) -> u128 {
self.inner.gas()
}
fn input(&self) -> &Bytes {
self.inner.input()
}
}
impl<T: ReceiptResponse> ReceiptResponse for WithOtherFields<T> {
fn contract_address(&self) -> Option<Address> {
self.inner.contract_address()
}
fn status(&self) -> bool {
self.inner.status()
}
fn block_hash(&self) -> Option<BlockHash> {
self.inner.block_hash()
}
fn block_number(&self) -> Option<u64> {
self.inner.block_number()
}
fn transaction_hash(&self) -> TxHash {
self.inner.transaction_hash()
}
fn transaction_index(&self) -> Option<u64> {
self.inner.transaction_index()
}
fn gas_used(&self) -> u128 {
self.inner.gas_used()
}
fn effective_gas_price(&self) -> u128 {
self.inner.effective_gas_price()
}
fn blob_gas_used(&self) -> Option<u128> {
self.inner.blob_gas_used()
}
fn blob_gas_price(&self) -> Option<u128> {
self.inner.blob_gas_price()
}
fn from(&self) -> Address {
self.inner.from()
}
fn to(&self) -> Option<Address> {
self.inner.to()
}
fn authorization_list(&self) -> Option<&[SignedAuthorization]> {
self.inner.authorization_list()
}
}
impl<T: BlockResponse> BlockResponse for WithOtherFields<T> {
type Header = T::Header;
type Transaction = T::Transaction;
fn header(&self) -> &Self::Header {
self.inner.header()
}
fn transactions(&self) -> &BlockTransactions<Self::Transaction> {
self.inner.transactions()
}
fn transactions_mut(&mut self) -> &mut BlockTransactions<Self::Transaction> {
self.inner.transactions_mut()
}
fn other_fields(&self) -> Option<&alloy_serde::OtherFields> {
Some(&self.other)
}
}
impl<T: HeaderResponse> HeaderResponse for WithOtherFields<T> {
fn hash(&self) -> BlockHash {
self.inner.hash()
}
fn number(&self) -> u64 {
self.inner.number()
}
fn timestamp(&self) -> u64 {
self.inner.timestamp()
}
fn extra_data(&self) -> &Bytes {
self.inner.extra_data()
}
fn base_fee_per_gas(&self) -> Option<u128> {
self.inner.base_fee_per_gas()
}
fn next_block_blob_fee(&self) -> Option<u128> {
self.inner.next_block_blob_fee()
}
fn coinbase(&self) -> Address {
self.inner.coinbase()
}
fn gas_limit(&self) -> u128 {
self.inner.gas_limit()
}
fn mix_hash(&self) -> Option<B256> {
self.inner.mix_hash()
}
fn difficulty(&self) -> U256 {
self.inner.difficulty()
}
}