Skip to content

Commit e769a1a

Browse files
committed
add subcommand to upload params
1 parent 5ec4ba5 commit e769a1a

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

src/main.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ async fn main() -> anyhow::Result<()> {
177177
.multiple(true)
178178
.last(true)
179179
.help("Arguments to pass to the underlying `cargo build-bpf` command")))
180+
.subcommand(SubCommand::with_name("write")
181+
.about("Write parameters to the otter-verify PDA account associated with the given program ID")
182+
.arg(Arg::with_name("program-id")
183+
.long("program-id")
184+
.required(true)
185+
.takes_value(true)
186+
.help("The address of the program to close the PDA"))
187+
.arg(Arg::with_name("git-url")
188+
.long("git-url")
189+
.required(true)
190+
.takes_value(true)
191+
.help("The HTTPS url of the repository to verify"))
192+
.arg(Arg::with_name("commit")
193+
.long("commit")
194+
.takes_value(true)
195+
.help("The optional commit hash of the repository to verify"))
196+
.arg(Arg::with_name("flags")
197+
.multiple(true)
198+
.last(true)
199+
.help("Additional flags and values to pass")))
180200
.subcommand(SubCommand::with_name("close")
181201
.about("Close the otter-verify PDA account associated with the given program ID")
182202
.arg(Arg::with_name("program-id")
@@ -278,6 +298,30 @@ async fn main() -> anyhow::Result<()> {
278298
)
279299
.await
280300
}
301+
("write", Some(sub_m)) => {
302+
let program_id = sub_m.value_of("program-id").unwrap();
303+
let git_url = sub_m.value_of("git-url").unwrap();
304+
let commit = sub_m.value_of("commit").map(|s| s.to_string());
305+
let url = matches.value_of("url").map(|s| s.to_string());
306+
// Check program id is valid
307+
Pubkey::try_from(program_id).map_err(|_| anyhow!("Invalid program id"))?;
308+
309+
let flags: Vec<String> = sub_m
310+
.values_of("flags")
311+
.unwrap_or_default()
312+
.map(|s| s.to_string())
313+
.collect();
314+
315+
upload_program(
316+
git_url.to_string(),
317+
&commit,
318+
flags,
319+
Pubkey::try_from(program_id)?,
320+
url,
321+
)
322+
.await?;
323+
Ok(())
324+
}
281325
("close", Some(sub_m)) => {
282326
let program_id = sub_m.value_of("program-id").unwrap();
283327
process_close(Pubkey::try_from(program_id)?).await

src/solana_program.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::{
88

99
use borsh::{to_vec, BorshDeserialize, BorshSerialize};
1010
use solana_sdk::{
11-
instruction::AccountMeta, message::Message, pubkey::Pubkey, signature::Keypair, signer::Signer,
12-
system_program, transaction::Transaction,
11+
commitment_config::CommitmentConfig, instruction::AccountMeta, message::Message,
12+
pubkey::Pubkey, signature::Keypair, signer::Signer, system_program, transaction::Transaction,
1313
};
1414

1515
use crate::api::get_last_deployed_slot;
@@ -64,7 +64,12 @@ fn get_user_config() -> anyhow::Result<(Keypair, RpcClient)> {
6464
let config_file = solana_cli_config::CONFIG_FILE
6565
.as_ref()
6666
.ok_or_else(|| anyhow!("Unable to get config file path"))?;
67-
let cli_config: Config = Config::load(config_file)?;
67+
68+
let cli_config: Config = Config::load(config_file)
69+
.map_err(|err| anyhow!(
70+
"Unable to load config file {}: {}\nTry running `solana config set -um` to init a config if you haven't already.",
71+
config_file, err
72+
))?;
6873

6974
let signer = solana_clap_utils::keypair::keypair_from_path(
7075
&Default::default(),
@@ -119,12 +124,18 @@ fn process_otter_verify_ixs(
119124
tx.sign(&[&signer], connection.get_latest_blockhash()?);
120125

121126
let tx_id = connection
122-
.send_and_confirm_transaction_with_spinner(&tx)
127+
.send_and_confirm_transaction_with_spinner_and_commitment(
128+
&tx,
129+
CommitmentConfig::confirmed(),
130+
)
123131
.map_err(|err| {
124132
println!("{:?}", err);
125133
anyhow!("Failed to send transaction to the network.")
126134
})?;
127-
println!("Program uploaded successfully. Transaction ID: {}", tx_id);
135+
println!(
136+
"Program verification params uploaded successfully. Transaction ID: {}",
137+
tx_id
138+
);
128139
Ok(())
129140
}
130141

@@ -136,7 +147,12 @@ pub async fn upload_program(
136147
connection_url: Option<String>,
137148
) -> anyhow::Result<()> {
138149
if prompt_user_input(
139-
"Do you want to upload the program verification to the Solana Blockchain? (y/n) ",
150+
&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) ",
151+
program_address,
152+
git_url,
153+
commit.as_ref().unwrap_or(&"None".to_string()),
154+
args,
155+
),
140156
) {
141157
println!("Uploading the program verification params to the Solana blockchain...");
142158

0 commit comments

Comments
 (0)