From e769a1ae02f2f764d4bd76c1eee0d2514f984010 Mon Sep 17 00:00:00 2001 From: Noah Gundotra Date: Wed, 20 Nov 2024 01:58:42 -0500 Subject: [PATCH] add subcommand to upload params --- src/main.rs | 44 +++++++++++++++++++++++++++++++++++++++++++ src/solana_program.rs | 28 +++++++++++++++++++++------ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 320e7be..094eb62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,6 +177,26 @@ async fn main() -> anyhow::Result<()> { .multiple(true) .last(true) .help("Arguments to pass to the underlying `cargo build-bpf` command"))) + .subcommand(SubCommand::with_name("write") + .about("Write parameters to the otter-verify PDA account associated with the given program ID") + .arg(Arg::with_name("program-id") + .long("program-id") + .required(true) + .takes_value(true) + .help("The address of the program to close the PDA")) + .arg(Arg::with_name("git-url") + .long("git-url") + .required(true) + .takes_value(true) + .help("The HTTPS url of the repository to verify")) + .arg(Arg::with_name("commit") + .long("commit") + .takes_value(true) + .help("The optional commit hash of the repository to verify")) + .arg(Arg::with_name("flags") + .multiple(true) + .last(true) + .help("Additional flags and values to pass"))) .subcommand(SubCommand::with_name("close") .about("Close the otter-verify PDA account associated with the given program ID") .arg(Arg::with_name("program-id") @@ -278,6 +298,30 @@ async fn main() -> anyhow::Result<()> { ) .await } + ("write", Some(sub_m)) => { + let program_id = sub_m.value_of("program-id").unwrap(); + let git_url = sub_m.value_of("git-url").unwrap(); + let commit = sub_m.value_of("commit").map(|s| s.to_string()); + let url = matches.value_of("url").map(|s| s.to_string()); + // Check program id is valid + Pubkey::try_from(program_id).map_err(|_| anyhow!("Invalid program id"))?; + + let flags: Vec = sub_m + .values_of("flags") + .unwrap_or_default() + .map(|s| s.to_string()) + .collect(); + + upload_program( + git_url.to_string(), + &commit, + flags, + Pubkey::try_from(program_id)?, + url, + ) + .await?; + Ok(()) + } ("close", Some(sub_m)) => { let program_id = sub_m.value_of("program-id").unwrap(); process_close(Pubkey::try_from(program_id)?).await diff --git a/src/solana_program.rs b/src/solana_program.rs index e1f0ae7..1ceb09b 100644 --- a/src/solana_program.rs +++ b/src/solana_program.rs @@ -8,8 +8,8 @@ use std::{ use borsh::{to_vec, BorshDeserialize, BorshSerialize}; use solana_sdk::{ - instruction::AccountMeta, message::Message, pubkey::Pubkey, signature::Keypair, signer::Signer, - system_program, transaction::Transaction, + commitment_config::CommitmentConfig, instruction::AccountMeta, message::Message, + pubkey::Pubkey, signature::Keypair, signer::Signer, system_program, transaction::Transaction, }; use crate::api::get_last_deployed_slot; @@ -64,7 +64,12 @@ fn get_user_config() -> anyhow::Result<(Keypair, RpcClient)> { let config_file = solana_cli_config::CONFIG_FILE .as_ref() .ok_or_else(|| anyhow!("Unable to get config file path"))?; - let cli_config: Config = Config::load(config_file)?; + + let cli_config: Config = Config::load(config_file) + .map_err(|err| anyhow!( + "Unable to load config file {}: {}\nTry running `solana config set -um` to init a config if you haven't already.", + config_file, err + ))?; let signer = solana_clap_utils::keypair::keypair_from_path( &Default::default(), @@ -119,12 +124,18 @@ fn process_otter_verify_ixs( tx.sign(&[&signer], connection.get_latest_blockhash()?); let tx_id = connection - .send_and_confirm_transaction_with_spinner(&tx) + .send_and_confirm_transaction_with_spinner_and_commitment( + &tx, + CommitmentConfig::confirmed(), + ) .map_err(|err| { println!("{:?}", err); anyhow!("Failed to send transaction to the network.") })?; - println!("Program uploaded successfully. Transaction ID: {}", tx_id); + println!( + "Program verification params uploaded successfully. Transaction ID: {}", + tx_id + ); Ok(()) } @@ -136,7 +147,12 @@ pub async fn upload_program( connection_url: Option, ) -> anyhow::Result<()> { if prompt_user_input( - "Do you want to upload the program verification to the Solana Blockchain? (y/n) ", + &format!("Do you want to upload these parameters for program verification to the Solana Blockchain?\nProgram ID: {}\nGit URL: {}\nCommit Hash: {}\nArgs: {:?}\n(y/n) ", + program_address, + git_url, + commit.as_ref().unwrap_or(&"None".to_string()), + args, + ), ) { println!("Uploading the program verification params to the Solana blockchain...");