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 methods
    fn on_call(
        &self,
        call: RpcMethodCall,
    ) -> impl Future<Output = RpcResponse> + Send { ... }
    fn on_request_error(
        &self,
        _method: &str,
        _id: &Id,
        _params: &Value,
        _error: &RpcError,
    ) { ... }
}
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>" }

Source

fn on_request_error( &self, _method: &str, _id: &Id, _params: &Value, _error: &RpcError, )

Invoked when a deserialized request returns an error from Self::on_request. Parameters retain their original shape with fork URL credentials redacted. Deserialization errors are excluded because their messages can contain request parameters.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§