Expand description
Crate providing Json RPC methods for the Block Producer Metadata feature of the Partner Chains Toolkit
§Contents
This crate provides the BlockProducerMetadataRpcApiServer trait defining the JsonRPC methods related to block producer metadata and its concrete implementation BlockProducerMetadataRpc. Currently, only a single method is provided:
pc_getBlockProducerMetadata
§Usage - PC Builders
To use the Json RPC service defined in this crate, first make your runtime implement
sp_block_producer_metadata::BlockProducerMetadataApi. Eg. assuming the pallet BlockProducerMetadataPallet
in your runtime uses BlockProducerMetadataType
as the metadata type, the following should be included in your
impl_runtime_apis
block:
impl BlockProducerMetadataApi<Block, BlockProducerMetadataType> for Runtime
{
fn get_metadata_for(
cross_chain_pub_key: &CrossChainPublicKey,
) -> Option<BlockProducerMetadataType> {
BlockProducerMetadataPallet::get_metadata_for(&cross_chain_pub_key)
}
}
Afterwards, the BlockProducerMetadataRpc Json RPC service can be added into the Json RPC stack of your node, eg.:
use jsonrpsee::RpcModule;
use std::sync::Arc;
use sp_block_producer_metadata::*;
use pallet_block_producer_metadata_rpc::*;
fn create_rpc<C, Block, Metadata>(client: Arc<C>) -> Result<RpcModule<()>, Box<dyn std::error::Error>>
where
C: Send + Sync + 'static,
Block: sp_runtime::traits::Block,
Metadata: Send + Sync + Clone + sp_core::Decode + sp_runtime::Serialize + 'static,
C: sp_api::ProvideRuntimeApi<Block>,
C: sp_blockchain::HeaderBackend<Block>,
C::Api: BlockProducerMetadataApi<Block, Metadata>
{
let mut module = RpcModule::new(());
module.merge(BlockProducerMetadataRpc::new(client.clone()).into_rpc())?;
// other RPC modules
Ok(module)
}
Structs§
- Block
Producer Metadata Rpc - Concrete implementation of BlockProducerMetadataRpcApiServer that uses BlockProducerMetadataApi for querying runtime storage.
Traits§
- Block
Producer Metadata RpcApi Client - Client implementation for the
BlockProducerMetadataRpcApi
RPC API. - Block
Producer Metadata RpcApi Server - Server trait implementation for the
BlockProducerMetadataRpcApi
RPC API.