Skip to content

Commit 7a9be2d

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

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

src/main.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use signal_hook::{
88
};
99
use solana_cli_config::{Config, CONFIG_FILE};
1010
use solana_client::rpc_client::RpcClient;
11+
use solana_program::process_upload_program;
1112
use solana_sdk::{
1213
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
1314
pubkey::Pubkey,
@@ -177,6 +178,26 @@ async fn main() -> anyhow::Result<()> {
177178
.multiple(true)
178179
.last(true)
179180
.help("Arguments to pass to the underlying `cargo build-bpf` command")))
181+
.subcommand(SubCommand::with_name("write")
182+
.about("Write parameters to the otter-verify PDA account associated with the given program ID")
183+
.arg(Arg::with_name("program-id")
184+
.long("program-id")
185+
.required(true)
186+
.takes_value(true)
187+
.help("The address of the program to close the PDA"))
188+
.arg(Arg::with_name("git-url")
189+
.long("git-url")
190+
.required(true)
191+
.takes_value(true)
192+
.help("The HTTPS url of the repository to verify"))
193+
.arg(Arg::with_name("commit")
194+
.long("commit")
195+
.takes_value(true)
196+
.help("The optional commit hash of the repository to verify"))
197+
.arg(Arg::with_name("flags")
198+
.multiple(true)
199+
.last(true)
200+
.help("Additional flags and values to pass")))
180201
.subcommand(SubCommand::with_name("close")
181202
.about("Close the otter-verify PDA account associated with the given program ID")
182203
.arg(Arg::with_name("program-id")
@@ -278,6 +299,28 @@ async fn main() -> anyhow::Result<()> {
278299
)
279300
.await
280301
}
302+
("write", Some(sub_m)) => {
303+
let program_id = sub_m.value_of("program-id").unwrap();
304+
let git_url = sub_m.value_of("git-url").unwrap();
305+
let commit = sub_m.value_of("commit").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+
process_upload_program(
316+
Pubkey::try_from(program_id)?,
317+
git_url.to_string(),
318+
&commit,
319+
flags,
320+
)
321+
.await?;
322+
Ok(())
323+
}
281324
("close", Some(sub_m)) => {
282325
let program_id = sub_m.value_of("program-id").unwrap();
283326
process_close(Pubkey::try_from(program_id)?).await

src/solana_program.rs

Lines changed: 35 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,15 +124,34 @@ 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

142+
pub async fn process_upload_program(
143+
program_address: Pubkey,
144+
git_url: String,
145+
commit: &Option<String>,
146+
args: Vec<String>,
147+
) -> anyhow::Result<()> {
148+
let user_config = get_user_config()?;
149+
let connection = user_config.1;
150+
let rpc_url = connection.url();
151+
152+
upload_program(git_url, commit, args, program_address, Some(rpc_url)).await
153+
}
154+
131155
pub async fn upload_program(
132156
git_url: String,
133157
commit: &Option<String>,
@@ -136,7 +160,12 @@ pub async fn upload_program(
136160
connection_url: Option<String>,
137161
) -> anyhow::Result<()> {
138162
if prompt_user_input(
139-
"Do you want to upload the program verification to the Solana Blockchain? (y/n) ",
163+
&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) ",
164+
program_address,
165+
git_url,
166+
commit.as_ref().unwrap_or(&"None".to_string()),
167+
args,
168+
),
140169
) {
141170
println!("Uploading the program verification params to the Solana blockchain...");
142171

0 commit comments

Comments
 (0)