Expand description
Json RPC for the Sidechain pallet
§Usage
§Implementing runtime APIs
Your runtime should implement the GetGenesisUtxo and GetEpochDurationApi runtime APIs. For example, if your chain uses Aura for consensus, they may be implemented similar to this:
impl sp_sidechain::GetGenesisUtxo<Block> for Runtime {
fn genesis_utxo() -> UtxoId {
Sidechain::genesis_utxo()
}
}
impl sp_sidechain::GetEpochDurationApi<Block> for Runtime {
fn get_epoch_duration_millis() -> u64 {
BLOCKS_PER_EPOCH * MILLISECS_PER_BLOCK
}
}§Adding to the RPC stack
Once the runtime APIs are in place, the RPC can be added to the node:
fn create_rpc<B: BlockT, C: Send + Sync + 'static>(
client: Arc<C>,
time_source: Arc<dyn TimeSource + Send + Sync>,
data_source: Arc<dyn SidechainRpcDataSource + Send + Sync>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<B> + GetBestHash<B> + CallApiAt<B>,
C::Api: GetGenesisUtxo<B> + GetEpochDurationApi<B>
{
let mut module = RpcModule::new(());
module.merge(
SidechainRpc::new(
client.clone(),
MainchainEpochConfig::read_from_env().unwrap(),
data_source,
time_source,
)
.into_rpc(),
)?;
// ... other RPCs
Ok(module)
}Note that your node should already have necessary time and data sources wired in. A Db-Sync-based
data source is provided by the Partner Chain toolkit in the partner_chains_db_sync_data_sources
crate.
§Legacy compatibility mode
In previous versions of the Partner Chains toolkit, the RPC services in this crate relied on now
deprecated runtime api sp_sidechain::SlotApi to compute Partner Chain epochs and current slot.
For Partner Chains that started before this dependency was removed, a compatibility mode is
provided behind the legacy-slotapi-compat feature flag. Enabling this flag will cause the nodes to
use this runtime API when present and optionally include information about current Patner Chain
slot in sidechain.slot field of sidechain_getStatus response.
Modules§
- types
- Response types returned by RPC endpoints for Sidechain pallet
Structs§
- GetParams
Output - Response type of the crate::SidechainRpcApiServer::get_params method
- Sidechain
Rpc - Json RPC service implementing SidechainRpcApiServer
Traits§
- Sidechain
RpcApi Client - Client implementation for the
SidechainRpcApiRPC API. - Sidechain
RpcApi Server - Server trait implementation for the
SidechainRpcApiRPC API. - Sidechain
RpcData Source - Data source used by SidechainRpc for querying latest block