Use default client keypair if --keypair argument is not provided
This commit is contained in:
parent
6c5fb329b2
commit
e9e5ee4362
|
@ -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" }
|
||||
|
|
|
@ -13,6 +13,8 @@ use std::{
|
|||
};
|
||||
|
||||
fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
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<dyn error::Error>> {
|
|||
.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<dyn error::Error>> {
|
|||
)
|
||||
.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<dyn error::Error>> {
|
|||
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,
|
||||
|
|
|
@ -59,7 +59,7 @@ pub enum FaucetRequest {
|
|||
}
|
||||
|
||||
pub struct Faucet {
|
||||
mint_keypair: Keypair,
|
||||
faucet_keypair: Keypair,
|
||||
ip_cache: Vec<IpAddr>,
|
||||
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<u64>,
|
||||
per_time_cap: Option<u64>,
|
||||
per_request_cap: Option<u64>,
|
||||
|
@ -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<SocketAddr>,
|
||||
per_time_cap: Option<u64>,
|
||||
) {
|
||||
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))
|
||||
|
|
Loading…
Reference in New Issue