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

add upsert-permissioned-candidates smart-contracts node command #382

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions toolkit/cli/smart-contracts-commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use sidechain_domain::*;
pub mod d_parameter;
pub mod get_scripts;
pub mod governance;
pub mod permissioned_candidates;
pub mod register;
pub mod reserve;

Expand All @@ -13,6 +14,8 @@ pub enum SmartContractsCmd {
GetScripts(get_scripts::GetScripts),
/// Upsert DParameter
UpsertDParameter(d_parameter::UpsertDParameterCmd),
/// Upsert Permissioned Candidates
UpsertPermissionedCandidates(permissioned_candidates::UpsertPermissionedCandidatesCmd),
/// Register candidate
Register(register::RegisterCmd),
/// Deregister candidate
Expand Down Expand Up @@ -40,6 +43,7 @@ impl SmartContractsCmd {
Self::Governance(cmd) => cmd.execute().await,
Self::GetScripts(cmd) => cmd.execute().await,
Self::UpsertDParameter(cmd) => cmd.execute().await,
Self::UpsertPermissionedCandidates(cmd) => cmd.execute().await,
Self::Register(cmd) => cmd.execute().await,
Self::Deregister(cmd) => cmd.execute().await,
Self::Reserve(cmd) => cmd.execute().await,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use crate::parse_partnerchain_public_keys;
use crate::PaymentFilePath;
use ogmios_client::jsonrpsee::client_for_url;
use partner_chains_cardano_offchain::await_tx::FixedDelayRetries;
use partner_chains_cardano_offchain::permissioned_candidates::upsert_permissioned_candidates;
use sidechain_domain::AuraPublicKey;
use sidechain_domain::GrandpaPublicKey;
use sidechain_domain::PermissionedCandidateData;
use sidechain_domain::SidechainPublicKey;
use sidechain_domain::UtxoId;
use std::fs::read_to_string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean up, 36% of these imports are unused


#[derive(Clone, Debug, clap::Parser)]
pub struct UpsertPermissionedCandidatesCmd {
#[clap(flatten)]
common_arguments: crate::CommonArguments,
/// Path to the file containing the permissioned candidates data.
/// Each line represents one permissioned candidate in format SIDECHAIN_KEY:AURA_KEY:GRANDPA_KEY
#[arg(long)]
permissioned_candidates_file: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help is missing here. How is user supposed to know it should be colon separated CSV?

#[clap(flatten)]
payment_key_file: PaymentFilePath,
#[arg(long, short('c'))]
genesis_utxo: UtxoId,
}

impl UpsertPermissionedCandidatesCmd {
pub async fn execute(self) -> crate::CmdResult<()> {
let payment_key = self.payment_key_file.read_key()?;

let mut permissioned_candidates = Vec::new();

for line in read_to_string(&self.permissioned_candidates_file).unwrap().lines() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of unwrap, please map it to a message that points user what file is missing.

let permissioned_candidate = parse_partnerchain_public_keys(line)
.map_err(|e| format!("Failed to parse permissioned candidate: {}", e))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map_err(|e| format!("Failed to parse permissioned candidate: {}", e))?;
.map_err(|e| format!("Failed to parse permissioned candidate: '{}', because of {}", line, e))?;

permissioned_candidates.push(permissioned_candidate);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./partner-chains-node smart-contracts upsert-permissioned-candidates -c f8fbe7316561e57de9ecd1c86ee8f8b512a314ba86499ba9a584bfa8fe2edc8d#0 -k funded_address.skey --permissioned-candidates-file oneentry.csv
Error: Application("Failed to parse permissioned candidate: Failed to parse partner chain public keys.")

Just because I have \n after the last key in the file. This will surely come back to us.


let client = client_for_url(&self.common_arguments.ogmios_url).await?;

upsert_permissioned_candidates(
self.genesis_utxo,
&permissioned_candidates,
payment_key.0,
&client,
&FixedDelayRetries::two_minutes(),
)
.await?;

Ok(())
}
}
Loading