Trait mmr_rpc::MmrApiServer
source · pub trait MmrApiServer<BlockHash, BlockNumber, MmrHash>: Sized + Send + Sync + 'static {
// Required methods
fn mmr_root(&self, at: Option<BlockHash>) -> RpcResult<MmrHash>;
fn generate_proof(
&self,
block_numbers: Vec<BlockNumber>,
best_known_block_number: Option<BlockNumber>,
at: Option<BlockHash>,
) -> RpcResult<LeavesProof<BlockHash>>;
fn verify_proof(&self, proof: LeavesProof<BlockHash>) -> RpcResult<bool>;
fn verify_proof_stateless(
&self,
mmr_root: MmrHash,
proof: LeavesProof<BlockHash>,
) -> RpcResult<bool>;
// Provided method
fn into_rpc(self) -> RpcModule<Self>
where BlockHash: Send + Sync + 'static + DeserializeOwned + Clone + Serialize,
BlockNumber: Send + Sync + 'static + DeserializeOwned,
MmrHash: Send + Sync + 'static + DeserializeOwned + Clone + Serialize { ... }
}
Expand description
Server trait implementation for the MmrApi
RPC API.
Required Methods§
sourcefn mmr_root(&self, at: Option<BlockHash>) -> RpcResult<MmrHash>
fn mmr_root(&self, at: Option<BlockHash>) -> RpcResult<MmrHash>
Get the MMR root hash for the current best block.
sourcefn generate_proof(
&self,
block_numbers: Vec<BlockNumber>,
best_known_block_number: Option<BlockNumber>,
at: Option<BlockHash>,
) -> RpcResult<LeavesProof<BlockHash>>
fn generate_proof( &self, block_numbers: Vec<BlockNumber>, best_known_block_number: Option<BlockNumber>, at: Option<BlockHash>, ) -> RpcResult<LeavesProof<BlockHash>>
Generate an MMR proof for the given block_numbers
.
This method calls into a runtime with MMR pallet included and attempts to generate
an MMR proof for the set of blocks that have the given block_numbers
with the MMR root at
best_known_block_number
. best_known_block_number
must be larger than all the
block_numbers
for the function to succeed.
Optionally via at
, a block hash at which the runtime should be queried can be specified.
Optionally via best_known_block_number
, the proof can be generated using the MMR’s state
at a specific best block. Note that if best_known_block_number
is provided, then also
specifying the block hash via at
isn’t super-useful here, unless you’re generating proof
using non-finalized blocks where there are several competing forks. That’s because MMR state
will be fixed to the state with best_known_block_number
, which already points to
some historical block.
Returns the (full) leaves and a proof for these leaves (compact encoding, i.e. hash of
the leaves). Both parameters are SCALE-encoded.
The order of entries in the leaves
field of the returned struct
is the same as the order of the entries in block_numbers
supplied
sourcefn verify_proof(&self, proof: LeavesProof<BlockHash>) -> RpcResult<bool>
fn verify_proof(&self, proof: LeavesProof<BlockHash>) -> RpcResult<bool>
Verify an MMR proof
.
This method calls into a runtime with MMR pallet included and attempts to verify an MMR proof.
Returns true
if the proof is valid, else returns the verification error.
sourcefn verify_proof_stateless(
&self,
mmr_root: MmrHash,
proof: LeavesProof<BlockHash>,
) -> RpcResult<bool>
fn verify_proof_stateless( &self, mmr_root: MmrHash, proof: LeavesProof<BlockHash>, ) -> RpcResult<bool>
Verify an MMR proof
statelessly given an mmr_root
.
This method calls into a runtime with MMR pallet included and attempts to verify an MMR proof against a provided MMR root.
Returns true
if the proof is valid, else returns the verification error.
Provided Methods§
sourcefn into_rpc(self) -> RpcModule<Self>where
BlockHash: Send + Sync + 'static + DeserializeOwned + Clone + Serialize,
BlockNumber: Send + Sync + 'static + DeserializeOwned,
MmrHash: Send + Sync + 'static + DeserializeOwned + Clone + Serialize,
fn into_rpc(self) -> RpcModule<Self>where
BlockHash: Send + Sync + 'static + DeserializeOwned + Clone + Serialize,
BlockNumber: Send + Sync + 'static + DeserializeOwned,
MmrHash: Send + Sync + 'static + DeserializeOwned + Clone + Serialize,
Collects all the methods and subscriptions defined in the trait and adds them into a single RpcModule
.