Skip to content

Commit b205aca

Browse files
committed
Balance tools, add retries
1 parent f29c29f commit b205aca

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

src/cli.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ pub enum SubCommand {
2222
Init,
2323
/// Shows information about the Goki workspace.
2424
Show,
25+
/// Shows the balance of the deployer.
26+
Balance {
27+
/// Cluster.
28+
#[clap(short, long)]
29+
#[clap(default_value = "devnet")]
30+
cluster: Cluster,
31+
},
2532
/// Requests an airdrop of SOL from the Solana network.
2633
Airdrop {
2734
/// Cluster to request from.
@@ -172,12 +179,15 @@ impl Opts {
172179
} => {
173180
subcommands::airdrop::process(
174181
&workspace,
175-
cluster,
182+
&cluster,
176183
amount.as_str(),
177184
iterations,
178185
interval,
179186
)?;
180187
}
188+
SubCommand::Balance { cluster } => {
189+
subcommands::balance::process(&workspace, &cluster)?;
190+
}
181191
SubCommand::Transfer {
182192
cluster,
183193
from,

src/subcommands/airdrop.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,28 @@ use crate::workspace::Workspace;
66

77
pub fn process(
88
workspace: &Workspace,
9-
cluster: Cluster,
9+
cluster: &Cluster,
1010
amount: &str,
1111
iterations: u32,
1212
interval: u64,
1313
) -> Result<()> {
14-
if cluster == Cluster::Mainnet {
14+
if *cluster == Cluster::Mainnet {
1515
return Err(format_err!("cannot request an airdrop from mainnet"));
1616
}
1717

18-
for _ in 0..iterations {
19-
workspace.exec_deployer_command(&cluster, |cmd| {
20-
cmd.arg("airdrop").arg(amount);
21-
Ok(())
22-
})?;
18+
let ctx = workspace.new_cluster_context(cluster)?;
19+
let deployer = ctx.parse_wallet_alias("deployer")?;
2320

24-
thread::sleep(Duration::from_millis(interval));
21+
for i in 0..iterations {
22+
match ctx.exec_args(&["airdrop", amount], &deployer) {
23+
Ok(_) => {}
24+
Err(err) => {
25+
println!("Error performing airdrop: {}", err);
26+
}
27+
}
28+
if i != iterations - 1 {
29+
thread::sleep(Duration::from_millis(interval));
30+
}
2531
}
2632

2733
Ok(())

src/subcommands/balance.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use anchor_client::Cluster;
2+
use anyhow::Result;
3+
4+
use crate::workspace::Workspace;
5+
6+
pub fn process(workspace: &Workspace, cluster: &Cluster) -> Result<()> {
7+
let ctx = workspace.new_cluster_context(cluster)?;
8+
let deployer = ctx.parse_wallet_alias("deployer")?;
9+
10+
println!("Deployer:");
11+
ctx.exec_args(&["account", &deployer], &deployer)?;
12+
13+
Ok(())
14+
}

src/subcommands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod airdrop;
2+
pub mod balance;
23
pub mod deploy;
34
pub mod init;
45
pub mod pull;

src/utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ pub fn exec_command(command: &mut Command) -> Result<Output> {
8282
print_command(command);
8383
let exit = exec_command_unhandled(command)?;
8484
if !exit.status.success() {
85-
std::process::exit(exit.status.code().unwrap_or(1));
85+
return Err(format_err!(
86+
"Command returned with exit code {}",
87+
exit.status.code().unwrap_or_default()
88+
));
8689
}
8790
Ok(exit)
8891
}

0 commit comments

Comments
 (0)