Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Etcm 8880 gov init in wizard #271

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/user-guides/chain-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: IOContext>(
context: &C,
Expand All @@ -17,6 +20,17 @@ pub fn prepare_main_chain_config<C: IOContext>(
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)
}
Expand All @@ -25,6 +39,18 @@ pub fn prepare_main_chain_config<C: IOContext>(
Ok(())
}

fn get_private_key_and_key_hash<C: IOContext>(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<C: IOContext>(
context: &C,
genesis_utxo: UtxoId,
Expand Down
Loading