Skip to content

Commit

Permalink
add: ETCM-8948 get-scripts command (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmbientTea authored Dec 3, 2024
1 parent 183b319 commit f9fcfa1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions toolkit/cli/smart-contracts-commands/src/get_scripts.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
6 changes: 3 additions & 3 deletions toolkit/cli/smart-contracts-commands/src/init_governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UtxoId>,
}

Expand Down
6 changes: 5 additions & 1 deletion toolkit/cli/smart-contracts-commands/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
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),
}

#[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,
}

Expand All @@ -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,
}
}

Expand Down
8 changes: 8 additions & 0 deletions toolkit/offchain/src/scripts_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScriptsData> {
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,
Expand Down

0 comments on commit f9fcfa1

Please sign in to comment.