use structopt::StructOpt;
use super::*;
#[derive(Debug, StructOpt)]
pub enum AirdropSubcommands {
#[structopt(name = "sol")]
Sol {
#[structopt(short, long)]
keypair: Option<String>,
#[structopt(short = "L", long)]
recipient_list: Option<String>,
#[structopt(short, long)]
cache_file: Option<String>,
#[structopt(short = "R", long)]
rate_limit: Option<u64>,
#[structopt(short = "P", long, default_value = "none")]
priority: Priority,
},
#[structopt(name = "spl")]
Spl {
#[structopt(short, long)]
keypair: Option<String>,
#[structopt(short = "L", long)]
recipient_list: Option<String>,
#[structopt(short, long)]
cache_file: Option<String>,
#[structopt(short, long)]
mint: Pubkey,
#[structopt(long)]
mint_tokens: bool,
#[structopt(short = "R", long)]
rate_limit: Option<u64>,
#[structopt(short = "P", long, default_value = "none")]
priority: Priority,
},
ReadCache {
cache_file: String,
#[structopt(long)]
errors: bool,
},
}
pub async fn process_airdrop(client: RpcClient, commands: AirdropSubcommands) -> Result<()> {
match commands {
AirdropSubcommands::Sol {
keypair,
recipient_list,
cache_file,
priority,
rate_limit,
} => {
airdrop_sol(AirdropSolArgs {
client,
keypair,
recipient_list,
cache_file,
priority,
rate_limit,
})
.await
}
AirdropSubcommands::Spl {
keypair,
recipient_list,
cache_file,
mint,
mint_tokens,
priority,
rate_limit,
} => {
airdrop_spl(AirdropSplArgs {
client,
keypair,
recipient_list,
cache_file,
mint,
mint_tokens,
priority,
rate_limit,
})
.await
}
AirdropSubcommands::ReadCache { cache_file, errors } => {
let path = std::path::Path::new(&cache_file);
let file = File::open(path)?;
let cache: Vec<JibFailedTransaction> = bincode::deserialize_from(file)?;
let json_filename = path.with_extension("json");
let pb = ProgressBar::new_spinner();
pb.set_message("Writing cache file...");
pb.enable_steady_tick(100);
let cache_file = std::fs::File::create(json_filename)?;
serde_json::to_writer(cache_file, &cache)?;
pb.finish_and_clear();
if errors {
for tx in cache {
println!("{:?}", tx.error);
}
}
Ok(())
}
}
}