From b822c5609aeaf72d9f2562c39bccdeef7378059b Mon Sep 17 00:00:00 2001 From: Krisztian Pinter Date: Mon, 25 Nov 2024 14:39:04 +0100 Subject: [PATCH 1/3] WIP --- .../prepare_main_chain_config.rs | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) 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..afb02dd06 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,34 @@ pub fn prepare_main_chain_config( Ok(()) } +fn get_private_key_and_key_hash(context: &C) -> Result<(MainchainPrivateKey, MainchainAddressHash), anyhow::Error> { + let cardano_payment_verification_key_file = + config_fields::CARDANO_PAYMENT_VERIFICATION_KEY_FILE + .prompt_with_default_from_file_and_save(context); + let bytes = cardano_key::get_key_bytes_from_file(&cardano_payment_verification_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 derive_address( + context: &C, + cardano_network: NetworkType, +) -> Result { + let cardano_payment_verification_key_file = + config_fields::CARDANO_PAYMENT_VERIFICATION_KEY_FILE + .prompt_with_default_from_file_and_save(context); + let key_bytes: [u8; 32] = + cardano_key::get_key_bytes_from_file(&cardano_payment_verification_key_file, context)?; + let address = + partner_chains_cardano_offchain::csl::payment_address(&key_bytes, cardano_network.to_csl()); + address.to_bech32(None).map_err(|e| anyhow!(e.to_string())) +} + + fn set_up_cardano_addresses( context: &C, genesis_utxo: UtxoId, From f1e5a24dfc8ff5843eda20defa5feec2527893c9 Mon Sep 17 00:00:00 2001 From: jankun4 Date: Tue, 26 Nov 2024 11:53:33 +0100 Subject: [PATCH 2/3] Fix address calculation --- .../prepare_main_chain_config.rs | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) 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 afb02dd06..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 @@ -20,7 +20,7 @@ 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)?; @@ -40,33 +40,17 @@ pub fn prepare_main_chain_config( } fn get_private_key_and_key_hash(context: &C) -> Result<(MainchainPrivateKey, MainchainAddressHash), anyhow::Error> { - let cardano_payment_verification_key_file = - config_fields::CARDANO_PAYMENT_VERIFICATION_KEY_FILE + 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_payment_verification_key_file, 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 derive_address( - context: &C, - cardano_network: NetworkType, -) -> Result { - let cardano_payment_verification_key_file = - config_fields::CARDANO_PAYMENT_VERIFICATION_KEY_FILE - .prompt_with_default_from_file_and_save(context); - let key_bytes: [u8; 32] = - cardano_key::get_key_bytes_from_file(&cardano_payment_verification_key_file, context)?; - let address = - partner_chains_cardano_offchain::csl::payment_address(&key_bytes, cardano_network.to_csl()); - address.to_bech32(None).map_err(|e| anyhow!(e.to_string())) -} - - fn set_up_cardano_addresses( context: &C, genesis_utxo: UtxoId, From 3f63f45e038cc8c86049689d08d81edd12c8ba1a Mon Sep 17 00:00:00 2001 From: jankun4 Date: Tue, 26 Nov 2024 11:57:50 +0100 Subject: [PATCH 3/3] update docs --- docs/user-guides/chain-builder.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: