Skip to main content

RpcHandler

Trait RpcHandler 

Source
pub trait RpcHandler:
    Clone
    + Send
    + Sync
    + 'static {
    type Request: DeserializeOwned + Send + Sync + Debug;

    // Required method
    fn on_request(
        &self,
        request: Self::Request,
    ) -> impl Future<Output = ResponseResult> + Send;

    // Provided method
    fn on_call(
        &self,
        call: RpcMethodCall,
    ) -> impl Future<Output = RpcResponse> + Send { ... }
}
Expand description

Helper trait that is used to execute ethereum rpc calls

Required Associated Types§

Source

type Request: DeserializeOwned + Send + Sync + Debug

The request type to expect

Required Methods§

Source

fn on_request( &self, request: Self::Request, ) -> impl Future<Output = ResponseResult> + Send

Invoked when the request was received

Provided Methods§

Source

fn on_call( &self, call: RpcMethodCall, ) -> impl Future<Output = RpcResponse> + Send

Invoked for every incoming RpcMethodCall. Notifications are adapted to method calls with an anvil_rpc::request::Id::Null identifier, and their responses are discarded.

This will attempt to deserialize a { "method" : "<name>", "params": "<params>" } message into the Request type of this handler. If a Request instance was deserialized successfully, Self::on_request will be invoked.

Note: override this function if the expected Request deviates from { "method" : "<name>", "params": "<params>" }

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§