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§
Required Methods§
Sourcefn on_request(
&self,
request: Self::Request,
) -> impl Future<Output = ResponseResult> + Send
fn on_request( &self, request: Self::Request, ) -> impl Future<Output = ResponseResult> + Send
Invoked when the request was received
Provided Methods§
Sourcefn on_call(
&self,
call: RpcMethodCall,
) -> impl Future<Output = RpcResponse> + Send
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>" }
Sourcefn on_request_error(
&self,
_method: &str,
_id: &Id,
_params: &Value,
_error: &RpcError,
)
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".