mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: TransactionCompat -> RpcConvert
This commit is contained in:
@ -1,21 +1,15 @@
|
||||
use super::{HlEthApi, HlNodeCore};
|
||||
use crate::evm::transaction::HlTxEnv;
|
||||
use alloy_consensus::TxType;
|
||||
use alloy_primitives::{TxKind, U256};
|
||||
use alloy_rpc_types::TransactionRequest;
|
||||
use alloy_signer::Either;
|
||||
use reth::rpc::server_types::eth::{revm_utils::CallFees, EthApiError, RpcInvalidTransactionError};
|
||||
use reth_evm::{block::BlockExecutorFactory, ConfigureEvm, EvmEnv, EvmFactory, SpecFor};
|
||||
use reth::rpc::server_types::eth::EthApiError;
|
||||
use reth_evm::{block::BlockExecutorFactory, ConfigureEvm, EvmFactory, TxEnvFor};
|
||||
use reth_primitives::NodePrimitives;
|
||||
use reth_provider::{ProviderHeader, ProviderTx};
|
||||
use reth_provider::{ProviderError, ProviderHeader, ProviderTx};
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{estimate::EstimateCall, Call, EthCall, LoadBlock, LoadState, SpawnBlocking},
|
||||
FromEthApiError, FromEvmError, FullEthApiTypes, IntoEthApiError,
|
||||
};
|
||||
use revm::{
|
||||
context::{Block as _, TxEnv},
|
||||
Database,
|
||||
FromEvmError, FullEthApiTypes, RpcConvert, RpcTypes,
|
||||
};
|
||||
use revm::context::TxEnv;
|
||||
|
||||
impl<N> EthCall for HlEthApi<N>
|
||||
where
|
||||
@ -44,7 +38,11 @@ where
|
||||
EvmFactory: EvmFactory<Tx = HlTxEnv<TxEnv>>,
|
||||
>,
|
||||
>,
|
||||
Error: FromEvmError<Self::Evm>,
|
||||
RpcConvert: RpcConvert<TxEnv = TxEnvFor<Self::Evm>, Network = Self::NetworkTypes>,
|
||||
NetworkTypes: RpcTypes<TransactionRequest: From<TransactionRequest>>,
|
||||
Error: FromEvmError<Self::Evm>
|
||||
+ From<<Self::RpcConvert as RpcConvert>::Error>
|
||||
+ From<ProviderError>,
|
||||
> + SpawnBlocking,
|
||||
Self::Error: From<EthApiError>,
|
||||
N: HlNodeCore,
|
||||
|
||||
@ -20,7 +20,6 @@ use reth::{
|
||||
};
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_network::NetworkInfo;
|
||||
use reth_optimism_rpc::eth::EthApiNodeBackend;
|
||||
use reth_primitives::NodePrimitives;
|
||||
use reth_provider::{
|
||||
BlockNumReader, BlockReader, BlockReaderIdExt, ProviderBlock, ProviderHeader, ProviderReceipt,
|
||||
@ -31,11 +30,11 @@ use reth_rpc_eth_api::{
|
||||
AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState,
|
||||
SpawnBlocking, Trace,
|
||||
},
|
||||
EthApiTypes, FromEvmError, RpcNodeCore, RpcNodeCoreExt,
|
||||
EthApiTypes, FromEvmError, RpcConverter, RpcNodeCore, RpcNodeCoreExt,
|
||||
};
|
||||
use std::{fmt, sync::Arc};
|
||||
|
||||
use crate::HlPrimitives;
|
||||
use reth_optimism_rpc::eth::EthApiNodeBackend;
|
||||
|
||||
mod block;
|
||||
mod call;
|
||||
@ -57,6 +56,8 @@ pub(crate) struct HlEthApiInner<N: HlNodeCore> {
|
||||
pub struct HlEthApi<N: HlNodeCore> {
|
||||
/// Gateway to node's core components.
|
||||
pub(crate) inner: Arc<HlEthApiInner<N>>,
|
||||
/// Converter for RPC types.
|
||||
tx_resp_builder: RpcConverter<Ethereum, N::Evm, EthApiError, ()>,
|
||||
}
|
||||
|
||||
impl<N: HlNodeCore> fmt::Debug for HlEthApi<N> {
|
||||
@ -69,13 +70,14 @@ impl<N> EthApiTypes for HlEthApi<N>
|
||||
where
|
||||
Self: Send + Sync,
|
||||
N: HlNodeCore,
|
||||
N::Evm: std::fmt::Debug,
|
||||
{
|
||||
type Error = EthApiError;
|
||||
type NetworkTypes = Ethereum;
|
||||
type TransactionCompat = Self;
|
||||
type RpcConvert = RpcConverter<Ethereum, N::Evm, EthApiError, ()>;
|
||||
|
||||
fn tx_resp_builder(&self) -> &Self::TransactionCompat {
|
||||
self
|
||||
fn tx_resp_builder(&self) -> &Self::RpcConvert {
|
||||
&self.tx_resp_builder
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +85,7 @@ impl<N> RpcNodeCore for HlEthApi<N>
|
||||
where
|
||||
N: HlNodeCore,
|
||||
{
|
||||
type Primitives = HlPrimitives;
|
||||
type Primitives = N::Primitives;
|
||||
type Provider = N::Provider;
|
||||
type Pool = N::Pool;
|
||||
type Evm = <N as RpcNodeCore>::Evm;
|
||||
@ -152,6 +154,7 @@ impl<N> SpawnBlocking for HlEthApi<N>
|
||||
where
|
||||
Self: Send + Sync + Clone + 'static,
|
||||
N: HlNodeCore,
|
||||
N::Evm: std::fmt::Debug,
|
||||
{
|
||||
#[inline]
|
||||
fn io_task_spawner(&self) -> impl TaskSpawner {
|
||||
@ -189,11 +192,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> LoadState for HlEthApi<N> where
|
||||
impl<N> LoadState for HlEthApi<N>
|
||||
where
|
||||
N: HlNodeCore<
|
||||
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
|
||||
Pool: TransactionPool,
|
||||
>
|
||||
>,
|
||||
N::Evm: std::fmt::Debug,
|
||||
{
|
||||
}
|
||||
|
||||
@ -210,7 +215,11 @@ where
|
||||
|
||||
impl<N> EthFees for HlEthApi<N>
|
||||
where
|
||||
Self: LoadFee,
|
||||
Self: LoadFee<
|
||||
Provider: ChainSpecProvider<
|
||||
ChainSpec: EthChainSpec<Header = ProviderHeader<Self::Provider>>,
|
||||
>,
|
||||
>,
|
||||
N: HlNodeCore,
|
||||
{
|
||||
}
|
||||
@ -268,6 +277,9 @@ where
|
||||
.proof_permits(ctx.config.proof_permits)
|
||||
.build_inner();
|
||||
|
||||
Ok(HlEthApi { inner: Arc::new(HlEthApiInner { eth_api }) })
|
||||
Ok(HlEthApi {
|
||||
inner: Arc::new(HlEthApiInner { eth_api }),
|
||||
tx_resp_builder: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,28 +1,14 @@
|
||||
use super::HlNodeCore;
|
||||
use crate::{
|
||||
node::{
|
||||
primitives::{tx_wrapper::convert_recovered, TransactionSigned},
|
||||
rpc::HlEthApi,
|
||||
},
|
||||
HlPrimitives,
|
||||
};
|
||||
use alloy_network::{Ethereum, Network};
|
||||
use alloy_primitives::{Bytes, Signature, B256};
|
||||
use crate::node::rpc::HlEthApi;
|
||||
use alloy_primitives::{Bytes, B256};
|
||||
use reth::{
|
||||
builder::FullNodeComponents,
|
||||
primitives::{Receipt, Recovered},
|
||||
providers::ReceiptProvider,
|
||||
rpc::{
|
||||
eth::helpers::types::EthRpcConverter,
|
||||
server_types::eth::{utils::recover_raw_transaction, EthApiError},
|
||||
types::{TransactionInfo, TransactionRequest},
|
||||
},
|
||||
rpc::server_types::eth::utils::recover_raw_transaction,
|
||||
transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool},
|
||||
};
|
||||
use reth_provider::{BlockReader, BlockReaderIdExt, ProviderTx, TransactionsProvider};
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
|
||||
FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt, TransactionCompat,
|
||||
FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt,
|
||||
};
|
||||
|
||||
impl<N> LoadTransaction for HlEthApi<N>
|
||||
@ -33,41 +19,6 @@ where
|
||||
{
|
||||
}
|
||||
|
||||
impl<N> TransactionCompat for HlEthApi<N>
|
||||
where
|
||||
N: FullNodeComponents<Provider: ReceiptProvider<Receipt = Receipt>>,
|
||||
{
|
||||
type Primitives = HlPrimitives;
|
||||
type Transaction = <Ethereum as Network>::TransactionResponse;
|
||||
|
||||
type Error = EthApiError;
|
||||
|
||||
fn fill(
|
||||
&self,
|
||||
tx: Recovered<TransactionSigned>,
|
||||
tx_info: TransactionInfo,
|
||||
) -> Result<Self::Transaction, Self::Error> {
|
||||
let builder = EthRpcConverter::default();
|
||||
builder.fill(convert_recovered(tx), tx_info)
|
||||
}
|
||||
|
||||
fn build_simulate_v1_transaction(
|
||||
&self,
|
||||
request: TransactionRequest,
|
||||
) -> Result<TransactionSigned, Self::Error> {
|
||||
let Ok(tx) = request.build_typed_tx() else {
|
||||
return Err(EthApiError::TransactionConversionError);
|
||||
};
|
||||
|
||||
// Create an empty signature for the transaction.
|
||||
let signature = Signature::new(Default::default(), Default::default(), false);
|
||||
Ok(TransactionSigned(reth_primitives::TransactionSigned::new_unhashed(
|
||||
tx.into(),
|
||||
signature,
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> EthTransactions for HlEthApi<N>
|
||||
where
|
||||
Self: LoadTransaction<Provider: BlockReaderIdExt>,
|
||||
|
||||
Reference in New Issue
Block a user