Expand description
Json RPC for the Sidechain pallet
§Usage
§Implementing runtime APIs
Your runtime should implement the SlotApi and GetGenesisUtxo runtime APIs. For example, if your chain uses Aura for consensus, they may be implemented similar to this:
ⓘ
impl sidechain_slots::SlotApi<Block> for Runtime {
fn slot_config() -> sidechain_slots::ScSlotConfig {
sidechain_slots::ScSlotConfig {
slots_per_epoch: Sidechain::slots_per_epoch(),
slot_duration: SlotDuration::from(Aura::slot_duration())
}
}
}
impl sp_sidechain::GetGenesisUtxo<Block> for Runtime {
fn genesis_utxo() -> UtxoId {
Sidechain::genesis_utxo()
}
}
§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>,
C::Api: SlotApi<B> + GetGenesisUtxo<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.
Modules§
- types
- Response types returned by RPC endpoints for Sidechain pallet
Structs§
- GetParams
Output - Response type of the [SidechainRpcApi::get_params] method
- Sidechain
Rpc - Json RPC service implementing SidechainRpcApiServer
Traits§
- Sidechain
RpcApi Client - Client implementation for the
SidechainRpcApi
RPC API. - Sidechain
RpcApi Server - Server trait implementation for the
SidechainRpcApi
RPC API. - Sidechain
RpcData Source - Data source used by SidechainRpc for querying latest block