Skip to content

Commit

Permalink
feat: asref bound for transaction response
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Oct 13, 2024
1 parent ee7ce99 commit df5b08a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub trait Network: Debug + Clone + Copy + Sized + Send + Sync + 'static {

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

/// The JSON body of a transaction receipt.
#[doc(alias = "TransactionReceiptResponse", alias = "TxReceiptResponse")]
Expand Down
6 changes: 6 additions & 0 deletions crates/rpc-types-eth/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ pub struct Transaction<T = TxEnvelope> {
// pub hash: B256,
}

impl<T> AsRef<T> for Transaction<T> {
fn as_ref(&self) -> &T {
&self.inner
}
}

impl<T> TransactionTrait for Transaction<T>
where
T: TransactionTrait,
Expand Down
9 changes: 9 additions & 0 deletions crates/serde/src/other/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ pub struct WithOtherFields<T> {
pub other: OtherFields,
}

impl<T, U> AsRef<U> for WithOtherFields<T>
where
T: AsRef<U>,
{
fn as_ref(&self) -> &U {
self.inner.as_ref()
}
}

impl<T> WithOtherFields<T> {
/// Creates a new [`WithOtherFields`] instance.
pub fn new(inner: T) -> Self {
Expand Down

0 comments on commit df5b08a

Please sign in to comment.