From f9fcfa141a808a1a1bd670b461f657fd8d0d3528 Mon Sep 17 00:00:00 2001 From: Nikolaos Dymitriadis Date: Tue, 3 Dec 2024 18:25:43 +0100 Subject: [PATCH] add: ETCM-8948 get-scripts command (#275) --- changelog.md | 2 +- .../src/get_scripts.rs | 24 +++++++++++++++++++ .../src/init_governance.rs | 6 ++--- .../cli/smart-contracts-commands/src/lib.rs | 6 ++++- toolkit/offchain/src/scripts_data.rs | 8 +++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 toolkit/cli/smart-contracts-commands/src/get_scripts.rs diff --git a/changelog.md b/changelog.md index b9e4b1ceb..5082a4946 100644 --- a/changelog.md +++ b/changelog.md @@ -33,7 +33,7 @@ This changelog is based on [Keep A Changelog](https://keepachangelog.com/en/1.1. ## Added -* Added `smart-contracts` command to the node with first command `init-governance`. +* Added `smart-contracts` command to the node with sub-commands `init-governance` and `get-scripts`. # v1.3.0 diff --git a/toolkit/cli/smart-contracts-commands/src/get_scripts.rs b/toolkit/cli/smart-contracts-commands/src/get_scripts.rs new file mode 100644 index 000000000..7bd4216bc --- /dev/null +++ b/toolkit/cli/smart-contracts-commands/src/get_scripts.rs @@ -0,0 +1,24 @@ +use jsonrpsee::http_client::HttpClient; +use partner_chains_cardano_offchain::scripts_data::get_scripts_data_with_ogmios; +use sidechain_domain::UtxoId; + +#[derive(Clone, Debug, clap::Parser)] +pub struct GetScripts { + #[clap(flatten)] + common_arguments: crate::CommonArguments, + #[arg(long, short = 'c')] + genesis_utxo: UtxoId, +} + +impl GetScripts { + pub async fn execute(self) -> crate::CmdResult<()> { + let client = HttpClient::builder().build(self.common_arguments.ogmios_host)?; + let scripts_data = get_scripts_data_with_ogmios(self.genesis_utxo, client).await?; + + let json = serde_json::to_string_pretty(&scripts_data)?; + + print!("{json}"); + + Ok(()) + } +} diff --git a/toolkit/cli/smart-contracts-commands/src/init_governance.rs b/toolkit/cli/smart-contracts-commands/src/init_governance.rs index 41f1f6e76..dbfe395bb 100644 --- a/toolkit/cli/smart-contracts-commands/src/init_governance.rs +++ b/toolkit/cli/smart-contracts-commands/src/init_governance.rs @@ -8,11 +8,11 @@ use crate::read_private_key_from_file; pub struct InitGovernanceCmd { #[clap(flatten)] common_arguments: crate::CommonArguments, - #[arg(long)] + #[arg(long, short = 'g')] governance_authority: MainchainAddressHash, - #[arg(long)] + #[arg(long, short = 'k')] payment_key_file: String, - #[arg(long)] + #[arg(long, short = 'c')] genesis_utxo: Option, } diff --git a/toolkit/cli/smart-contracts-commands/src/lib.rs b/toolkit/cli/smart-contracts-commands/src/lib.rs index 318bb8d9b..5193fec06 100644 --- a/toolkit/cli/smart-contracts-commands/src/lib.rs +++ b/toolkit/cli/smart-contracts-commands/src/lib.rs @@ -1,10 +1,13 @@ use sidechain_domain::MainchainPrivateKey; +pub mod get_scripts; pub mod init_governance; #[derive(Clone, Debug, clap::Subcommand)] #[allow(clippy::large_enum_variant)] pub enum SmartContractsCmd { + /// Print validator addresses and policy IDs of Partner Chain smart contracts + GetScripts(get_scripts::GetScripts), /// Initialize Partner Chain governance InitGovernance(init_governance::InitGovernanceCmd), } @@ -12,7 +15,7 @@ pub enum SmartContractsCmd { #[derive(Clone, Debug, clap::Parser)] #[command(author, version, about, long_about = None)] pub struct CommonArguments { - #[arg(default_value = "http://localhost:1337")] + #[arg(default_value = "http://localhost:1337", long, short = 'O')] ogmios_host: String, } @@ -22,6 +25,7 @@ impl SmartContractsCmd { pub async fn execute(self) -> CmdResult<()> { match self { Self::InitGovernance(cmd) => cmd.execute().await, + Self::GetScripts(cmd) => cmd.execute().await, } } diff --git a/toolkit/offchain/src/scripts_data.rs b/toolkit/offchain/src/scripts_data.rs index d95f8533b..9a4d3c94d 100644 --- a/toolkit/offchain/src/scripts_data.rs +++ b/toolkit/offchain/src/scripts_data.rs @@ -129,6 +129,14 @@ pub fn get_scripts_data( }) } +pub async fn get_scripts_data_with_ogmios( + genesis_utxo: UtxoId, + client: impl QueryNetwork, +) -> anyhow::Result { + let network = client.shelley_genesis_configuration().await?.network.to_csl(); + get_scripts_data(genesis_utxo, network) +} + // Returns version oracle script, policy and PlutusData required by other scripts. pub(crate) fn version_oracle( genesis_utxo: UtxoId,