Skip to content
Draft
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
44 changes: 44 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<String> = 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
Expand Down
28 changes: 22 additions & 6 deletions src/solana_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(())
}

Expand All @@ -136,7 +147,12 @@ pub async fn upload_program(
connection_url: Option<String>,
) -> 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...");

Expand Down