cli_commands/
get_genesis_utxo.rs

1use sidechain_domain::UtxoId;
2use sp_api::ProvideRuntimeApi;
3use sp_blockchain::HeaderBackend;
4use sp_runtime::traits::Block as BlockT;
5use sp_sidechain::GetGenesisUtxo;
6use std::sync::Arc;
7
8/// Retrieves the genesis UTXO from the on-chain storage.
9/// This function should be used by a CLI command.
10pub async fn execute<B, C>(client: Arc<C>) -> Result<String, String>
11where
12	B: BlockT,
13	C: ProvideRuntimeApi<B> + Send + Sync + 'static,
14	C::Api: GetGenesisUtxo<B>,
15	C: HeaderBackend<B>,
16{
17	let api = client.runtime_api();
18	let best_block = client.info().best_hash;
19	let genesis_utxo = api.genesis_utxo(best_block).map_err(|err| err.to_string())?;
20	let output =
21		serde_json::to_string_pretty(&Output { genesis_utxo }).map_err(|err| err.to_string())?;
22	Ok(output)
23}
24
25#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, Debug)]
26struct Output {
27	pub genesis_utxo: UtxoId,
28}