diff --git a/docs/user-guides/chain-builder.md b/docs/user-guides/chain-builder.md index 730d4b507..34d3c2c83 100644 --- a/docs/user-guides/chain-builder.md +++ b/docs/user-guides/chain-builder.md @@ -272,7 +272,7 @@ Before running this wizard, be sure that `cardano-cli` is available and has an e 3. Set the partner-chains parameters 4. Store the main chain configuration -This wizard will result in a `partner-chains-cli-chain-config.json` file. After it has been generated, it should be updated with your keys and the keys of other *permissioned* candidates in the `initial_permissioned_candidates` array. +This wizard will submit a governance initialisation transaction, that spends the genesis utxo. It will also result in a `partner-chains-cli-chain-config.json` file. After it has been generated, it should be updated with your keys and the keys of other *permissioned* candidates in the `initial_permissioned_candidates` array. Example: diff --git a/toolkit/partner-chains-cli/src/prepare_configuration/prepare_main_chain_config.rs b/toolkit/partner-chains-cli/src/prepare_configuration/prepare_main_chain_config.rs index 4aeccc3bc..86d599fa1 100644 --- a/toolkit/partner-chains-cli/src/prepare_configuration/prepare_main_chain_config.rs +++ b/toolkit/partner-chains-cli/src/prepare_configuration/prepare_main_chain_config.rs @@ -7,7 +7,10 @@ use crate::config::ServiceConfig; use crate::io::IOContext; use crate::prepare_configuration::prepare_cardano_params::prepare_cardano_params; use partner_chains_cardano_offchain::scripts_data::GetScriptsData; -use sidechain_domain::{PolicyId, UtxoId}; +use sidechain_domain::{MainchainPrivateKey, MainchainAddressHash, PolicyId, UtxoId}; +use partner_chains_cardano_offchain::init_governance::run_init_governance; +use crate::{config::config_fields, *}; +use cardano_serialization_lib::*; pub fn prepare_main_chain_config( context: &C, @@ -17,6 +20,17 @@ pub fn prepare_main_chain_config( let cardano_parameteres = prepare_cardano_params(ogmios_config, context)?; cardano_parameteres.save(context); set_up_cardano_addresses(context, genesis_utxo, ogmios_config)?; + + println!("{}", ogmios_config.hostname.clone()); + let ogmios_url = format!("http://{}:{}", ogmios_config.hostname, ogmios_config.port ); + let client = jsonrpsee::http_client::HttpClient::builder().build(ogmios_url)?; + let (payment_key, governance_authority) = get_private_key_and_key_hash(context)?; + + let runtime = tokio::runtime::Runtime::new().map_err(|e| anyhow::anyhow!(e))?; + runtime + .block_on(run_init_governance(governance_authority, payment_key, Some(genesis_utxo), client)) + .map_err(|e| anyhow::anyhow!("Offchain call failed: {e:?}!"))?; + if INITIAL_PERMISSIONED_CANDIDATES.load_from_file(context).is_none() { INITIAL_PERMISSIONED_CANDIDATES.save_to_file(&vec![], context) } @@ -25,6 +39,18 @@ pub fn prepare_main_chain_config( Ok(()) } +fn get_private_key_and_key_hash(context: &C) -> Result<(MainchainPrivateKey, MainchainAddressHash), anyhow::Error> { + let cardano_signig_key_file = + config_fields::CARDANO_PAYMENT_SIGNING_KEY_FILE + .prompt_with_default_from_file_and_save(context); + let bytes = cardano_key::get_key_bytes_from_file(&cardano_signig_key_file, context)?; + + let csl_private_key = PrivateKey::from_normal_bytes(&bytes)?; + let csl_public_key_hash = csl_private_key.to_public().hash().to_bytes().try_into().expect("aaa"); + + Ok((MainchainPrivateKey(bytes), MainchainAddressHash(csl_public_key_hash))) +} + fn set_up_cardano_addresses( context: &C, genesis_utxo: UtxoId,