Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: add OtterscanTxResp trait #1354

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/network-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
extern crate alloc;

mod traits;
pub use traits::{BlockResponse, HeaderResponse, ReceiptResponse, TransactionResponse};
pub use traits::{
BlockResponse, HeaderResponse, OtterscanTxResp, ReceiptResponse, TransactionResponse,
};

mod block;
pub use block::{BlockTransactionHashes, BlockTransactions, BlockTransactionsKind};
6 changes: 6 additions & 0 deletions crates/network-primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ pub trait ReceiptResponse {
fn state_root(&self) -> Option<B256>;
}

/// Extension trait for [`TransactionResponse`] to support Otterscan-specific API.
pub trait OtterscanTxResp: TransactionResponse {
/// Truncate the input for Otterscan API.
fn otterscan_api_truncate_input(&mut self);
}

/// Transaction JSON-RPC response.
pub trait TransactionResponse {
/// Signature type of the transaction
Expand Down
8 changes: 7 additions & 1 deletion crates/rpc-types-eth/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloy_consensus::{
TxEnvelope, TxLegacy, TxType,
};
use alloy_eips::eip7702::SignedAuthorization;
use alloy_network_primitives::TransactionResponse;
use alloy_network_primitives::{OtterscanTxResp, TransactionResponse};
use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, TxKind, B256, U256};

use alloc::vec::Vec;
Expand Down Expand Up @@ -338,6 +338,12 @@ impl TryFrom<Transaction> for TxEnvelope {
}
}

impl OtterscanTxResp for Transaction {
fn otterscan_api_truncate_input(&mut self) {
self.input = self.input.slice(..4);
}
}

impl TransactionResponse for Transaction {
type Signature = Signature;

Expand Down