-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add upsert-permissioned-candidates smart-contracts node command
- Loading branch information
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
toolkit/cli/smart-contracts-commands/src/permissioned_candidates.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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::UtxoId; | ||
use sidechain_domain::AuraPublicKey; | ||
use sidechain_domain::GrandpaPublicKey; | ||
use sidechain_domain::PermissionedCandidateData; | ||
use sidechain_domain::SidechainPublicKey; | ||
|
||
#[derive(Clone, Debug, clap::Parser)] | ||
pub struct UpsertPermissionedCandidatesCmd { | ||
#[clap(flatten)] | ||
common_arguments: crate::CommonArguments, | ||
#[arg(long)] | ||
permissioned_candidates_file: String, | ||
#[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 reader = csv::ReaderBuilder::new() | ||
.delimiter(b':') | ||
.from_path(&self.permissioned_candidates_file)?; | ||
|
||
let mut permissioned_candidates = Vec::new(); | ||
|
||
for result in reader.records() { | ||
let record = result?; | ||
|
||
let permissioned_candidate = PermissionedCandidateData { | ||
sidechain_public_key: SidechainPublicKey::from_hex_unsafe( | ||
record.get(0).unwrap().to_string().as_str(), | ||
), | ||
aura_public_key: AuraPublicKey::from_hex_unsafe( | ||
record.get(1).unwrap().to_string().as_str(), | ||
), | ||
grandpa_public_key: GrandpaPublicKey::from_hex_unsafe( | ||
record.get(2).unwrap().to_string().as_str(), | ||
), | ||
}; | ||
|
||
permissioned_candidates.push(permissioned_candidate); | ||
} | ||
|
||
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(()) | ||
} | ||
} |