mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: support blobs in eth_sendRawTransaction (#4495)
This commit is contained in:
1
crates/net/eth-wire/testdata/rpc_blob_transaction
vendored
Normal file
1
crates/net/eth-wire/testdata/rpc_blob_transaction
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
//! Decoding tests for [`PooledTransactions`]
|
||||
use reth_eth_wire::PooledTransactions;
|
||||
use reth_primitives::{hex, PooledTransactionsElement};
|
||||
use reth_primitives::{hex, Bytes, PooledTransactionsElement};
|
||||
use reth_rlp::Decodable;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
@ -21,3 +21,13 @@ fn decode_blob_transaction_data() {
|
||||
let hex_data = hex::decode(data.trim()).unwrap();
|
||||
let _txs = PooledTransactionsElement::decode(&mut &hex_data[..]).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decode_blob_rpc_transaction() {
|
||||
// test data pulled from hive test that sends blob transactions
|
||||
let network_data_path =
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("testdata/rpc_blob_transaction");
|
||||
let data = fs::read_to_string(network_data_path).expect("Unable to read file");
|
||||
let hex_data = Bytes::from(hex::decode(data.trim()).unwrap());
|
||||
let _txs = PooledTransactionsElement::decode_enveloped(hex_data).unwrap();
|
||||
}
|
||||
|
||||
@ -394,7 +394,7 @@ impl PooledTransactionsElementEcRecovered {
|
||||
self.transaction
|
||||
}
|
||||
|
||||
/// Transform back to [`PooledTransactionsElement`]
|
||||
/// Transform back to [`TransactionSignedEcRecovered`]
|
||||
pub fn into_ecrecovered_transaction(self) -> TransactionSignedEcRecovered {
|
||||
let (tx, signer) = self.into_components();
|
||||
tx.into_ecrecovered_transaction(signer)
|
||||
@ -414,3 +414,11 @@ impl PooledTransactionsElementEcRecovered {
|
||||
Self { transaction, signer }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionSignedEcRecovered> for PooledTransactionsElementEcRecovered {
|
||||
fn from(tx: TransactionSignedEcRecovered) -> Self {
|
||||
let signer = tx.signer;
|
||||
let transaction = tx.signed_transaction.into();
|
||||
Self { transaction, signer }
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ use crate::{
|
||||
use async_trait::async_trait;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{
|
||||
Address, BlockId, BlockNumberOrTag, Bytes, FromRecoveredTransaction, Header,
|
||||
Address, BlockId, BlockNumberOrTag, Bytes, FromRecoveredPooledTransaction, Header,
|
||||
IntoRecoveredTransaction, Receipt, SealedBlock,
|
||||
TransactionKind::{Call, Create},
|
||||
TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, H256, U128, U256, U64,
|
||||
@ -504,7 +504,7 @@ where
|
||||
let recovered =
|
||||
signed_tx.into_ecrecovered().ok_or(EthApiError::InvalidTransactionSignature)?;
|
||||
|
||||
let pool_transaction = <Pool::Transaction>::from_recovered_transaction(recovered);
|
||||
let pool_transaction = <Pool::Transaction>::from_recovered_transaction(recovered.into());
|
||||
|
||||
// submit the transaction to the pool with a `Local` origin
|
||||
let hash = self.pool().add_transaction(TransactionOrigin::Local, pool_transaction).await?;
|
||||
|
||||
@ -1,18 +1,20 @@
|
||||
//! Commonly used code snippets
|
||||
|
||||
use crate::eth::error::{EthApiError, EthResult};
|
||||
use reth_primitives::{Bytes, TransactionSigned, TransactionSignedEcRecovered};
|
||||
use reth_primitives::{Bytes, PooledTransactionsElement, PooledTransactionsElementEcRecovered};
|
||||
|
||||
/// Recovers a [TransactionSignedEcRecovered] from an enveloped encoded byte stream.
|
||||
/// Recovers a [PooledTransactionsElementEcRecovered] from an enveloped encoded byte stream.
|
||||
///
|
||||
/// See [TransactionSigned::decode_enveloped]
|
||||
pub(crate) fn recover_raw_transaction(data: Bytes) -> EthResult<TransactionSignedEcRecovered> {
|
||||
/// See [PooledTransactionsElement::decode_enveloped]
|
||||
pub(crate) fn recover_raw_transaction(
|
||||
data: Bytes,
|
||||
) -> EthResult<PooledTransactionsElementEcRecovered> {
|
||||
if data.is_empty() {
|
||||
return Err(EthApiError::EmptyRawTransactionData)
|
||||
}
|
||||
|
||||
let transaction = TransactionSigned::decode_enveloped(data)
|
||||
let transaction = PooledTransactionsElement::decode_enveloped(data)
|
||||
.map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
|
||||
|
||||
transaction.into_ecrecovered().ok_or(EthApiError::InvalidTransactionSignature)
|
||||
transaction.try_into_ecrecovered().or(Err(EthApiError::InvalidTransactionSignature))
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ where
|
||||
.eth_api
|
||||
.evm_env_at(block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)))
|
||||
.await?;
|
||||
let tx = tx_env_with_recovered(&tx);
|
||||
let tx = tx_env_with_recovered(&tx.into_ecrecovered_transaction());
|
||||
let env = Env { cfg, block, tx };
|
||||
|
||||
let config = tracing_config(&trace_types);
|
||||
|
||||
Reference in New Issue
Block a user