RpcConvert

Trait RpcConvert 

pub trait RpcConvert:
    Send
    + Sync
    + Unpin
    + Clone
    + Debug
    + 'static {
    type Primitives: NodePrimitives;
    type Network: RpcTypes + Send + Sync + Unpin + Clone + Debug;
    type TxEnv;
    type Error: Error + Into<ErrorObject<'static>>;
    type Spec;

    // Required methods
    fn fill(
        &self,
        tx: Recovered<<Self::Primitives as NodePrimitives>::SignedTx>,
        tx_info: TransactionInfo,
    ) -> Result<<Self::Network as RpcTypes>::TransactionResponse, Self::Error>;
    fn build_simulate_v1_transaction(
        &self,
        request: <Self::Network as RpcTypes>::TransactionRequest,
    ) -> Result<<Self::Primitives as NodePrimitives>::SignedTx, Self::Error>;
    fn tx_env(
        &self,
        request: <Self::Network as RpcTypes>::TransactionRequest,
        cfg_env: &CfgEnv<Self::Spec>,
        block_env: &BlockEnv,
    ) -> Result<Self::TxEnv, Self::Error>;
    fn convert_receipts(
        &self,
        receipts: Vec<ConvertReceiptInput<'_, Self::Primitives>>,
    ) -> Result<Vec<<Self::Network as RpcTypes>::Receipt>, Self::Error>;
    fn convert_header(
        &self,
        header: SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
        block_size: usize,
    ) -> Result<<Self::Network as RpcTypes>::Header, Self::Error>;

    // Provided method
    fn fill_pending(
        &self,
        tx: Recovered<<Self::Primitives as NodePrimitives>::SignedTx>,
    ) -> Result<<Self::Network as RpcTypes>::TransactionResponse, Self::Error> { ... }
}
Expand description

Responsible for the conversions from and into RPC requests and responses.

The JSON-RPC schema and the Node primitives are configurable using the RpcConvert::Network and RpcConvert::Primitives associated types respectively.

A generic implementation RpcConverter should be preferred over a manual implementation. As long as its trait bound requirements are met, the implementation is created automatically and can be used in RPC method handlers for all the conversions.

Required Associated Types§

type Primitives: NodePrimitives

Associated lower layer consensus types to convert from and into types of Self::Network.

type Network: RpcTypes + Send + Sync + Unpin + Clone + Debug

Associated upper layer JSON-RPC API network requests and responses to convert from and into types of Self::Primitives.

type TxEnv

A set of variables for executing a transaction.

type Error: Error + Into<ErrorObject<'static>>

An associated RPC conversion error.

type Spec

The EVM specification identifier.

Required Methods§

fn fill( &self, tx: Recovered<<Self::Primitives as NodePrimitives>::SignedTx>, tx_info: TransactionInfo, ) -> Result<<Self::Network as RpcTypes>::TransactionResponse, Self::Error>

Create a new rpc transaction result for a mined transaction, using the given block hash, number, and tx index fields to populate the corresponding fields in the rpc result.

The block hash, number, and tx index fields should be from the original block where the transaction was mined.

fn build_simulate_v1_transaction( &self, request: <Self::Network as RpcTypes>::TransactionRequest, ) -> Result<<Self::Primitives as NodePrimitives>::SignedTx, Self::Error>

Builds a fake transaction from a transaction request for inclusion into block built in eth_simulateV1.

fn tx_env( &self, request: <Self::Network as RpcTypes>::TransactionRequest, cfg_env: &CfgEnv<Self::Spec>, block_env: &BlockEnv, ) -> Result<Self::TxEnv, Self::Error>

Creates a transaction environment for execution based on request with corresponding cfg_env and block_env.

fn convert_receipts( &self, receipts: Vec<ConvertReceiptInput<'_, Self::Primitives>>, ) -> Result<Vec<<Self::Network as RpcTypes>::Receipt>, Self::Error>

Converts a set of primitive receipts to RPC representations. It is guaranteed that all receipts are from the same block.

fn convert_header( &self, header: SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>, block_size: usize, ) -> Result<<Self::Network as RpcTypes>::Header, Self::Error>

Converts a primitive header to an RPC header.

Provided Methods§

fn fill_pending( &self, tx: Recovered<<Self::Primitives as NodePrimitives>::SignedTx>, ) -> Result<<Self::Network as RpcTypes>::TransactionResponse, Self::Error>

Wrapper for fill() with default TransactionInfo Create a new rpc transaction result for a pending signed transaction, setting block environment related fields to None.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<N, Network, Evm, Receipt, Header, Map, SimTx, RpcTx, TxEnv> RpcConvert for RpcConverter<Network, Evm, Receipt, Header, Map, SimTx, RpcTx, TxEnv>
where N: NodePrimitives, Network: RpcTypes + Send + Sync + Unpin + Clone + Debug, Evm: ConfigureEvm<Primitives = N> + 'static, Receipt: ReceiptConverter<N, RpcReceipt = <Network as RpcTypes>::Receipt> + Send + Sync + Unpin + Clone + Debug, <Receipt as ReceiptConverter<N>>::Error: From<TransactionConversionError> + From<<TxEnv as TxEnvConverter<<Network as RpcTypes>::TransactionRequest, <<<Evm as ConfigureEvm>::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx, <<<Evm as ConfigureEvm>::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>>::Error> + From<<Map as TxInfoMapper<<N as NodePrimitives>::SignedTx>>::Err> + From<<RpcTx as RpcTxConverter<<N as NodePrimitives>::SignedTx, <Network as RpcTypes>::TransactionResponse, <Map as TxInfoMapper<<N as NodePrimitives>::SignedTx>>::Out>>::Err> + Error + Unpin + Sync + Send + Into<ErrorObject<'static>>, Header: HeaderConverter<<N as NodePrimitives>::BlockHeader, <Network as RpcTypes>::Header>, Map: TxInfoMapper<<N as NodePrimitives>::SignedTx> + Clone + Debug + Unpin + Send + Sync + 'static, SimTx: SimTxConverter<<Network as RpcTypes>::TransactionRequest, <N as NodePrimitives>::SignedTx>, RpcTx: RpcTxConverter<<N as NodePrimitives>::SignedTx, <Network as RpcTypes>::TransactionResponse, <Map as TxInfoMapper<<N as NodePrimitives>::SignedTx>>::Out>, TxEnv: TxEnvConverter<<Network as RpcTypes>::TransactionRequest, <<<Evm as ConfigureEvm>::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx, <<<Evm as ConfigureEvm>::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>,

§

type Primitives = N

§

type Network = Network

§

type TxEnv = <<<Evm as ConfigureEvm>::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx

§

type Error = <Receipt as ReceiptConverter<N>>::Error

§

type Spec = <<<Evm as ConfigureEvm>::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec