From e9e5ee436283180c6edc0fc729cdf584d00a30c3 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 16 Nov 2020 08:43:07 -0800 Subject: [PATCH] Use default client keypair if --keypair argument is not provided --- faucet/Cargo.toml | 1 + faucet/src/bin/faucet.rs | 9 ++++++--- faucet/src/faucet.rs | 23 ++++++++++++++++------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/faucet/Cargo.toml b/faucet/Cargo.toml index 166e8bd86..a5ac4dc84 100644 --- a/faucet/Cargo.toml +++ b/faucet/Cargo.toml @@ -17,6 +17,7 @@ log = "0.4.8" serde = "1.0.112" serde_derive = "1.0.103" solana-clap-utils = { path = "../clap-utils", version = "1.5.0" } +solana-cli-config = { path = "../cli-config", version = "1.5.0" } solana-logger = { path = "../logger", version = "1.5.0" } solana-metrics = { path = "../metrics", version = "1.5.0" } solana-sdk = { path = "../sdk", version = "1.5.0" } diff --git a/faucet/src/bin/faucet.rs b/faucet/src/bin/faucet.rs index 714470460..7b982e58c 100644 --- a/faucet/src/bin/faucet.rs +++ b/faucet/src/bin/faucet.rs @@ -13,6 +13,8 @@ use std::{ }; fn main() -> Result<(), Box> { + let default_keypair = solana_cli_config::Config::default().keypair_path; + solana_logger::setup_with_default("solana=info"); solana_metrics::set_panic_hook("faucet"); let matches = App::new(crate_name!()) @@ -25,7 +27,8 @@ fn main() -> Result<(), Box> { .value_name("PATH") .takes_value(true) .required(true) - .help("File from which to read the mint's keypair"), + .default_value(&default_keypair) + .help("File from which to read the faucet's keypair"), ) .arg( Arg::with_name("slice") @@ -51,7 +54,7 @@ fn main() -> Result<(), Box> { ) .get_matches(); - let mint_keypair = read_keypair_file(matches.value_of("keypair").unwrap()) + let faucet_keypair = read_keypair_file(matches.value_of("keypair").unwrap()) .expect("failed to read client keypair"); let time_slice = value_of(&matches, "slice"); @@ -61,7 +64,7 @@ fn main() -> Result<(), Box> { let faucet_addr = socketaddr!(0, FAUCET_PORT); let faucet = Arc::new(Mutex::new(Faucet::new( - mint_keypair, + faucet_keypair, time_slice, per_time_cap, per_request_cap, diff --git a/faucet/src/faucet.rs b/faucet/src/faucet.rs index 0094fb3cb..6a60024ed 100644 --- a/faucet/src/faucet.rs +++ b/faucet/src/faucet.rs @@ -59,7 +59,7 @@ pub enum FaucetRequest { } pub struct Faucet { - mint_keypair: Keypair, + faucet_keypair: Keypair, ip_cache: Vec, pub time_slice: Duration, per_time_cap: u64, @@ -69,7 +69,7 @@ pub struct Faucet { impl Faucet { pub fn new( - mint_keypair: Keypair, + faucet_keypair: Keypair, time_input: Option, per_time_cap: Option, per_request_cap: Option, @@ -77,7 +77,7 @@ impl Faucet { let time_slice = Duration::new(time_input.unwrap_or(TIME_SLICE), 0); let per_time_cap = per_time_cap.unwrap_or(REQUEST_CAP); Faucet { - mint_keypair, + faucet_keypair, ip_cache: Vec::new(), time_slice, per_time_cap, @@ -133,11 +133,15 @@ impl Faucet { ); info!("Requesting airdrop of {} to {:?}", lamports, to); - let mint_pubkey = self.mint_keypair.pubkey(); + let mint_pubkey = self.faucet_keypair.pubkey(); let create_instruction = system_instruction::transfer(&mint_pubkey, &to, lamports); let message = Message::new(&[create_instruction], Some(&mint_pubkey)); - Ok(Transaction::new(&[&self.mint_keypair], message, blockhash)) + Ok(Transaction::new( + &[&self.faucet_keypair], + message, + blockhash, + )) } else { Err(Error::new( ErrorKind::Other, @@ -254,14 +258,14 @@ pub fn request_airdrop_transaction( // For integration tests. Listens on random open port and reports port to Sender. pub fn run_local_faucet( - mint_keypair: Keypair, + faucet_keypair: Keypair, sender: Sender, per_time_cap: Option, ) { thread::spawn(move || { let faucet_addr = socketaddr!(0, 0); let faucet = Arc::new(Mutex::new(Faucet::new( - mint_keypair, + faucet_keypair, None, per_time_cap, None, @@ -280,6 +284,11 @@ pub fn run_faucet( send_addr.send(socket.local_addr().unwrap()).unwrap(); } info!("Faucet started. Listening on: {}", faucet_addr); + info!( + "Faucet account address: {}", + faucet.lock().unwrap().faucet_keypair.pubkey() + ); + let done = socket .incoming() .map_err(|e| debug!("failed to accept socket; error = {:?}", e))