cuprate_rpc_interface

Trait RpcHandler

Source
pub trait RpcHandler:
    RpcService<JsonRpcRequest, JsonRpcResponse>
    + RpcService<BinRequest, BinResponse>
    + RpcService<OtherRequest, OtherResponse> {
    // Required method
    fn restricted(&self) -> bool;
}
Expand description

An RPC handler.

This trait represents a type that can turn Requests into Responses.

Implementors of this trait must be:

In other words, an RpcHandler is a type that implements tower::Service 3 times, one for each request/response enum type found in cuprate_rpc_types.

The error type must always be anyhow::Error.

See this crate’s RpcHandlerDummy for an implementation example of this trait.

§Panics

Your RpcHandler must reply to Requests with the correct Response or else this crate will panic during routing functions.

For example, a JsonRpcRequest::GetBlockCount must be replied with JsonRpcResponse::GetBlockCount. If anything else is returned, this crate may panic.

Required Methods§

Source

fn restricted(&self) -> bool

Is this RpcHandler restricted?

If this returns true, restricted methods and endpoints such as:

  • /json_rpc’s relay_tx method
  • The /pop_blocks endpoint

will automatically be denied access when using the axum::Router provided by RouterBuilder.

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§