Skip to content

Commit

Permalink
use registration in wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
kpinter-iohk committed Dec 12, 2024
1 parent 7460ad6 commit 90632c3
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 136 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions toolkit/cli/smart-contracts-commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ pub(crate) fn parse_partnerchain_public_keys(
}
}

fn payment_signing_key_to_mainchain_address_hash(
payment_signing_key: MainchainPrivateKey,
) -> CmdResult<MainchainAddressHash> {
Ok(cardano_serialization_lib::PrivateKey::from_normal_bytes(&payment_signing_key.0)?
.to_public()
.hash()
.to_bytes()
.as_slice()
.try_into()
.map(MainchainAddressHash)?)
}

#[cfg(test)]
mod test {
use crate::parse_partnerchain_public_keys;
Expand Down
14 changes: 7 additions & 7 deletions toolkit/cli/smart-contracts-commands/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub struct RegisterCmd {
alias = "sidechain-public-keys",
value_parser=parse_partnerchain_public_keys
)]
partnerchain_public_keys: PermissionedCandidateData,
partner_chain_public_keys: PermissionedCandidateData,
#[arg(long, alias = "sidechain-signature")]
partnerchain_signature: SidechainSignature,
partner_chain_signature: SidechainSignature,
#[arg(long)]
spo_public_key: MainchainPublicKey,
#[arg(long)]
Expand All @@ -41,12 +41,12 @@ impl RegisterCmd {
pub_key: self.spo_public_key,
signature: self.spo_signature,
},
partnerchain_pub_key: self.partnerchain_public_keys.sidechain_public_key,
partnerchain_signature: self.partnerchain_signature,
own_pkh: crate::payment_signing_key_to_mainchain_address_hash(payment_key.clone())?,
partner_chain_pub_key: self.partner_chain_public_keys.sidechain_public_key,
partner_chain_signature: self.partner_chain_signature,
own_pkh: payment_key.to_pub_key_hash(),
registration_utxo: self.registration_utxo,
aura_pub_key: self.partnerchain_public_keys.aura_public_key,
grandpa_pub_key: self.partnerchain_public_keys.grandpa_public_key,
aura_pub_key: self.partner_chain_public_keys.aura_public_key,
grandpa_pub_key: self.partner_chain_public_keys.grandpa_public_key,
};

run_register(
Expand Down
14 changes: 7 additions & 7 deletions toolkit/offchain/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use ogmios_client::{
query_ledger_state::{QueryLedgerState, QueryUtxoByUtxoId},
query_network::QueryNetwork,
transactions::Transactions,
types::{OgmiosTx, OgmiosUtxo},
types::OgmiosUtxo,
};
use partner_chains_plutus_data::registered_candidates::{
candidate_registration_to_plutus_data, RegisterValidatorDatum,
Expand All @@ -32,7 +32,7 @@ pub trait Register {
genesis_utxo: UtxoId,
candidate_registration: &CandidateRegistration,
payment_signing_key: MainchainPrivateKey,
) -> Result<Option<OgmiosTx>, OffchainError>;
) -> Result<Option<McTxHash>, OffchainError>;
}

impl<T> Register for T
Expand All @@ -44,7 +44,7 @@ where
genesis_utxo: UtxoId,
candidate_registration: &CandidateRegistration,
payment_signing_key: MainchainPrivateKey,
) -> Result<Option<OgmiosTx>, OffchainError> {
) -> Result<Option<McTxHash>, OffchainError> {
run_register(
genesis_utxo,
candidate_registration,
Expand All @@ -66,7 +66,7 @@ pub async fn run_register<
payment_signing_key: MainchainPrivateKey,
ogmios_client: &C,
await_tx: A,
) -> anyhow::Result<Option<OgmiosTx>> {
) -> anyhow::Result<Option<McTxHash>> {
let ctx = TransactionContext::for_payment_key(payment_signing_key.0, ogmios_client).await?;
let validator = crate::scripts_data::registered_candidates_scripts(genesis_utxo)?;
let validator_address = validator.address_bech32(ctx.network)?;
Expand Down Expand Up @@ -132,7 +132,7 @@ pub async fn run_register<
log::info!("✅ Transaction submitted. ID: {}", hex::encode(result.transaction.id));
await_tx.await_tx_output(ogmios_client, UtxoId::new(tx_id, 0)).await?;

Ok(Some(result.transaction))
Ok(Some(McTxHash(result.transaction.id)))
}

fn get_own_registrations(
Expand Down Expand Up @@ -249,8 +249,8 @@ mod tests {
pub_key: test_values::mainchain_pub_key(),
signature: MainchainSignature(Vec::new()),
},
partnerchain_pub_key: SidechainPublicKey(Vec::new()),
partnerchain_signature: SidechainSignature(Vec::new()),
partner_chain_pub_key: SidechainPublicKey(Vec::new()),
partner_chain_signature: SidechainSignature(Vec::new()),
registration_utxo,
own_pkh: own_pkh(),
aura_pub_key: AuraPublicKey(Vec::new()),
Expand Down
7 changes: 3 additions & 4 deletions toolkit/offchain/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use ogmios_client::{
query_ledger_state::{QueryLedgerState, QueryUtxoByUtxoId},
query_network::QueryNetwork,
transactions::Transactions,
types::OgmiosTx,
OgmiosClientError,
};
use partner_chains_cardano_offchain::{
Expand Down Expand Up @@ -183,7 +182,7 @@ async fn run_register<T: QueryLedgerState + Transactions + QueryNetwork + QueryU
genesis_utxo: UtxoId,
partnerchain_signature: SidechainSignature,
client: &T,
) -> Option<OgmiosTx> {
) -> Option<McTxHash> {
let eve_utxos = client.query_utxos(&[EVE_ADDRESS.to_string()]).await.unwrap();
let registration_utxo = eve_utxos.first().unwrap().utxo_id();
client
Expand All @@ -194,8 +193,8 @@ async fn run_register<T: QueryLedgerState + Transactions + QueryNetwork + QueryU
pub_key: EVE_PUBLIC_KEY,
signature: MainchainSignature(vec![19u8; 32]),
},
partnerchain_pub_key: SidechainPublicKey([20u8; 32].to_vec()),
partnerchain_signature,
partner_chain_pub_key: SidechainPublicKey([20u8; 32].to_vec()),
partner_chain_signature: partnerchain_signature,
own_pkh: EVE_PUBLIC_KEY_HASH,
registration_utxo,
aura_pub_key: AuraPublicKey([22u8; 32].to_vec()),
Expand Down
14 changes: 1 addition & 13 deletions toolkit/partner-chains-cli/src/cardano_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::IOContext;
use anyhow::anyhow;
use sidechain_domain::{MainchainAddressHash, MainchainPrivateKey};
use sidechain_domain::MainchainPrivateKey;

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -45,15 +45,3 @@ pub(crate) fn get_mc_pkey_from_file(
) -> anyhow::Result<MainchainPrivateKey> {
Ok(MainchainPrivateKey(get_key_bytes_from_file(path, context)?))
}

pub(crate) fn get_mc_address_hash_from_pkey(pkey: &MainchainPrivateKey) -> MainchainAddressHash {
let csl_private_key = cardano_serialization_lib::PrivateKey::from_normal_bytes(&pkey.0)
.expect("Conversion is infallible");
let csl_public_key_hash = csl_private_key
.to_public()
.hash()
.to_bytes()
.try_into()
.expect("Bytes represent correct public key hash");
MainchainAddressHash(csl_public_key_hash)
}
3 changes: 2 additions & 1 deletion toolkit/partner-chains-cli/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::{anyhow, Context};
use jsonrpsee::http_client::HttpClient;
use partner_chains_cardano_offchain::d_param::UpsertDParam;
use partner_chains_cardano_offchain::init_governance::InitGovernance;
use partner_chains_cardano_offchain::register::Register;
use partner_chains_cardano_offchain::scripts_data::GetScriptsData;
use sp_core::offchain::Timestamp;
use std::path::PathBuf;
Expand All @@ -16,7 +17,7 @@ use tempfile::{TempDir, TempPath};

pub trait IOContext {
/// It should implement all the required traits for offchain operations
type Offchain: GetScriptsData + InitGovernance + UpsertDParam;
type Offchain: GetScriptsData + InitGovernance + UpsertDParam + Register;

fn run_command(&self, cmd: &str) -> anyhow::Result<String>;
fn print(&self, msg: &str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn get_private_key_and_key_hash<C: IOContext>(
let cardano_signig_key_file = config_fields::CARDANO_PAYMENT_SIGNING_KEY_FILE
.prompt_with_default_from_file_and_save(context);
let pkey = cardano_key::get_mc_pkey_from_file(&cardano_signig_key_file, context)?;
let addr_hash = cardano_key::get_mc_address_hash_from_pkey(&pkey);
let addr_hash = pkey.to_pub_key_hash();

Ok((pkey, addr_hash))
}
Expand Down
4 changes: 2 additions & 2 deletions toolkit/partner-chains-cli/src/register/register2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl CmdRun for Register2Cmd {

context.print("To finish the registration process, run the following command on the machine with the partner chain dependencies running:\n");
context.print(&format!(
"./partner-chains-cli register3 \\\n--genesis-utxo {} \\\n--registration-utxo {} \\\n--aura-pub-key {} \\\n--grandpa-pub-key {} \\\n--sidechain-pub-key {} \\\n--sidechain-signature {} \\\n--spo-public-key {} \\\n--spo-signature {}",
"./partner-chains-cli register3 \\\n--genesis-utxo {} \\\n--registration-utxo {} \\\n--aura-pub-key {} \\\n--grandpa-pub-key {} \\\n--partner-chain-pub-key {} \\\n--partner-chain-signature {} \\\n--spo-public-key {} \\\n--spo-signature {}",
self.genesis_utxo, self.registration_utxo, self.aura_pub_key, self.grandpa_pub_key, self.sidechain_pub_key, self.sidechain_signature, spo_public_key, spo_signature));
Ok(())
}
Expand Down Expand Up @@ -124,7 +124,7 @@ mod tests {
fn output_result_io() -> Vec<MockIO> {
vec![
MockIO::print("To finish the registration process, run the following command on the machine with the partner chain dependencies running:\n"),
MockIO::print("./partner-chains-cli register3 \\\n--genesis-utxo 0000000000000000000000000000000000000000000000000000000000000001#0 \\\n--registration-utxo 7e9ebd0950ae1bec5606f0cd7ac88b3c60b1103d7feb6ffa36402edae4d1b617#0 \\\n--aura-pub-key 0xdf883ee0648f33b6103017b61be702017742d501b8fe73b1d69ca0157460b777 \\\n--grandpa-pub-key 0x5a091a06abd64f245db11d2987b03218c6bd83d64c262fe10e3a2a1230e90327 \\\n--sidechain-pub-key 0x031e75acbf45ef8df98bbe24b19b28fff807be32bf88838c30c0564d7bec5301f6 \\\n--sidechain-signature 7a7e3e585a5dc248d4a2772814e1b58c90313443dd99369f994e960ecc4931442a08305743db7ab42ab9b8672e00250e1cc7c08bc018b0630a8197c4f95528a301 \\\n--spo-public-key cef2d1630c034d3b9034eb7903d61f419a3074a1ad01d4550cc72f2b733de6e7 \\\n--spo-signature aaa39fbf163ed77c69820536f5dc22854e7e13f964f1e077efde0844a09bde64c1aab4d2b401e0fe39b43c91aa931cad26fa55c8766378462c06d86c85134801"),
MockIO::print("./partner-chains-cli register3 \\\n--genesis-utxo 0000000000000000000000000000000000000000000000000000000000000001#0 \\\n--registration-utxo 7e9ebd0950ae1bec5606f0cd7ac88b3c60b1103d7feb6ffa36402edae4d1b617#0 \\\n--aura-pub-key 0xdf883ee0648f33b6103017b61be702017742d501b8fe73b1d69ca0157460b777 \\\n--grandpa-pub-key 0x5a091a06abd64f245db11d2987b03218c6bd83d64c262fe10e3a2a1230e90327 \\\n--partner-chain-pub-key 0x031e75acbf45ef8df98bbe24b19b28fff807be32bf88838c30c0564d7bec5301f6 \\\n--partner-chain-signature 7a7e3e585a5dc248d4a2772814e1b58c90313443dd99369f994e960ecc4931442a08305743db7ab42ab9b8672e00250e1cc7c08bc018b0630a8197c4f95528a301 \\\n--spo-public-key cef2d1630c034d3b9034eb7903d61f419a3074a1ad01d4550cc72f2b733de6e7 \\\n--spo-signature aaa39fbf163ed77c69820536f5dc22854e7e13f964f1e077efde0844a09bde64c1aab4d2b401e0fe39b43c91aa931cad26fa55c8766378462c06d86c85134801"),
]
}
// non 0 genesis utxo 8ea10040249ad3033ae7c4d4b69e0b2e2b50a90741b783491cb5ddf8ced0d861
Expand Down
Loading

0 comments on commit 90632c3

Please sign in to comment.