Don't get the network from parse_args
This commit is contained in:
parent
e1a551e8f2
commit
5ca473ac2d
|
@ -5,14 +5,13 @@ extern crate dirs;
|
|||
extern crate solana;
|
||||
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use solana::drone::DRONE_PORT;
|
||||
use solana::logger;
|
||||
use solana::rpc::RPC_PORT;
|
||||
use solana::signature::{read_keypair, KeypairUtil};
|
||||
use solana::thin_client::poll_gossip_for_leader;
|
||||
use solana::wallet::{gen_keypair_file, parse_command, process_command, WalletConfig, WalletError};
|
||||
use std::error;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
|
||||
pub fn parse_args(matches: &ArgMatches) -> Result<WalletConfig, Box<error::Error>> {
|
||||
let network = if let Some(addr) = matches.value_of("network") {
|
||||
|
@ -30,6 +29,14 @@ pub fn parse_args(matches: &ArgMatches) -> Result<WalletConfig, Box<error::Error
|
|||
None
|
||||
};
|
||||
|
||||
let proxy = matches.value_of("proxy").map(|proxy| proxy.to_string());
|
||||
|
||||
let rpc_port = if let Some(port) = matches.value_of("rpc-port") {
|
||||
port.to_string().parse().expect("integer")
|
||||
} else {
|
||||
RPC_PORT
|
||||
};
|
||||
|
||||
let mut path = dirs::home_dir().expect("home directory");
|
||||
let id_path = if matches.is_present("keypair") {
|
||||
matches.value_of("keypair").unwrap()
|
||||
|
@ -49,32 +56,18 @@ pub fn parse_args(matches: &ArgMatches) -> Result<WalletConfig, Box<error::Error
|
|||
)))
|
||||
})?;
|
||||
|
||||
let leader = poll_gossip_for_leader(network, timeout)?;
|
||||
|
||||
let mut drone_addr = leader.contact_info.tpu;
|
||||
drone_addr.set_port(DRONE_PORT);
|
||||
|
||||
let rpc_addr = if let Some(proxy) = matches.value_of("proxy") {
|
||||
proxy.to_string()
|
||||
} else {
|
||||
let rpc_port = if let Some(port) = matches.value_of("rpc-port") {
|
||||
port.to_string().parse().expect("integer")
|
||||
} else {
|
||||
RPC_PORT
|
||||
};
|
||||
let mut rpc_addr = leader.contact_info.tpu;
|
||||
rpc_addr.set_port(rpc_port);
|
||||
format!("http://{}", rpc_addr.to_string())
|
||||
};
|
||||
|
||||
let command = parse_command(id.pubkey(), &matches)?;
|
||||
|
||||
let default_addr = socketaddr!(0, 8000);
|
||||
Ok(WalletConfig {
|
||||
leader,
|
||||
id,
|
||||
drone_addr, // TODO: Add an option for this.
|
||||
rpc_addr,
|
||||
drone_addr: default_addr,
|
||||
rpc_addr: default_addr.to_string(),
|
||||
command,
|
||||
network,
|
||||
timeout,
|
||||
proxy,
|
||||
rpc_port,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -252,7 +245,10 @@ fn main() -> Result<(), Box<error::Error>> {
|
|||
)
|
||||
).get_matches();
|
||||
|
||||
let config = parse_args(&matches)?;
|
||||
let mut config = parse_args(&matches)?;
|
||||
let leader = poll_gossip_for_leader(config.network, config.timeout)?;
|
||||
config.update_leader_addrs(leader.contact_info.tpu);
|
||||
|
||||
let result = process_command(&config)?;
|
||||
println!("{}", result);
|
||||
Ok(())
|
||||
|
|
|
@ -5,8 +5,7 @@ use budget_program::BudgetState;
|
|||
use budget_transaction::BudgetTransaction;
|
||||
use chrono::prelude::*;
|
||||
use clap::ArgMatches;
|
||||
use cluster_info::NodeInfo;
|
||||
use drone::DroneRequest;
|
||||
use drone::{DroneRequest, DRONE_PORT};
|
||||
use elf;
|
||||
use fullnode::Config;
|
||||
use hash::Hash;
|
||||
|
@ -84,26 +83,45 @@ impl error::Error for WalletError {
|
|||
}
|
||||
|
||||
pub struct WalletConfig {
|
||||
pub leader: NodeInfo,
|
||||
pub id: Keypair,
|
||||
pub drone_addr: SocketAddr,
|
||||
pub rpc_addr: String,
|
||||
pub command: WalletCommand,
|
||||
pub network: SocketAddr,
|
||||
pub timeout: Option<u64>,
|
||||
pub proxy: Option<String>,
|
||||
pub rpc_port: u16,
|
||||
}
|
||||
|
||||
impl Default for WalletConfig {
|
||||
fn default() -> WalletConfig {
|
||||
let default_addr = socketaddr!(0, 8000);
|
||||
WalletConfig {
|
||||
leader: NodeInfo::new_with_socketaddr(&default_addr),
|
||||
id: Keypair::new(),
|
||||
drone_addr: default_addr,
|
||||
rpc_addr: default_addr.to_string(),
|
||||
command: WalletCommand::Balance,
|
||||
network: default_addr,
|
||||
timeout: None,
|
||||
proxy: None,
|
||||
rpc_port: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WalletConfig {
|
||||
pub fn update_leader_addrs(&mut self, tpu_addr: SocketAddr) {
|
||||
let mut drone_addr = tpu_addr;
|
||||
drone_addr.set_port(DRONE_PORT);
|
||||
self.drone_addr = drone_addr;
|
||||
|
||||
let mut rpc_addr = tpu_addr;
|
||||
rpc_addr.set_port(self.rpc_port);
|
||||
let rpc_addr_str = format!("http://{}", rpc_addr.to_string());
|
||||
self.rpc_addr = self.proxy.clone().unwrap_or(rpc_addr_str);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_command(
|
||||
pubkey: Pubkey,
|
||||
matches: &ArgMatches,
|
||||
|
@ -1079,7 +1097,6 @@ mod tests {
|
|||
let leader_keypair = Arc::new(Keypair::new());
|
||||
let leader = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||
let leader_data = leader.info.clone();
|
||||
let leader_data1 = leader.info.clone();
|
||||
let (alice, ledger_path) =
|
||||
create_tmp_genesis("wallet_process_command", 10_000_000, leader_data.id, 1000);
|
||||
let mut bank = Bank::new(&alice);
|
||||
|
@ -1111,7 +1128,6 @@ mod tests {
|
|||
let (sender, receiver) = channel();
|
||||
run_local_drone(alice.keypair(), leader_data.contact_info.ncp, sender);
|
||||
config.drone_addr = receiver.recv().unwrap();
|
||||
config.leader = leader_data1;
|
||||
|
||||
let mut rpc_addr = leader_data.contact_info.ncp;
|
||||
rpc_addr.set_port(rpc_port);
|
||||
|
@ -1239,8 +1255,6 @@ mod tests {
|
|||
let leader_keypair = Arc::new(Keypair::new());
|
||||
let leader = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||
let leader_data = leader.info.clone();
|
||||
let leader_data1 = leader.info.clone();
|
||||
let leader_data2 = leader.info.clone();
|
||||
let (alice, ledger_path) =
|
||||
create_tmp_genesis("wallet_timestamp_tx", 10_000_000, leader_data.id, 1000);
|
||||
let mut bank = Bank::new(&alice);
|
||||
|
@ -1273,8 +1287,6 @@ mod tests {
|
|||
run_local_drone(alice.keypair(), leader_data.contact_info.ncp, sender);
|
||||
config_payer.drone_addr = receiver.recv().unwrap();
|
||||
config_witness.drone_addr = config_payer.drone_addr.clone();
|
||||
config_payer.leader = leader_data1;
|
||||
config_witness.leader = leader_data2;
|
||||
|
||||
let mut rpc_addr = leader_data.contact_info.ncp;
|
||||
rpc_addr.set_port(rpc_port);
|
||||
|
@ -1365,8 +1377,6 @@ mod tests {
|
|||
let leader_keypair = Arc::new(Keypair::new());
|
||||
let leader = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||
let leader_data = leader.info.clone();
|
||||
let leader_data1 = leader.info.clone();
|
||||
let leader_data2 = leader.info.clone();
|
||||
let (alice, ledger_path) =
|
||||
create_tmp_genesis("wallet_witness_tx", 10_000_000, leader_data.id, 1000);
|
||||
let mut bank = Bank::new(&alice);
|
||||
|
@ -1397,8 +1407,6 @@ mod tests {
|
|||
run_local_drone(alice.keypair(), leader_data.contact_info.ncp, sender);
|
||||
config_payer.drone_addr = receiver.recv().unwrap();
|
||||
config_witness.drone_addr = config_payer.drone_addr.clone();
|
||||
config_payer.leader = leader_data1;
|
||||
config_witness.leader = leader_data2;
|
||||
|
||||
let rpc_addr = leader_data.contact_info.rpc;
|
||||
config_payer.rpc_addr = format!("http://{}", rpc_addr.to_string());
|
||||
|
@ -1486,8 +1494,6 @@ mod tests {
|
|||
let leader_keypair = Arc::new(Keypair::new());
|
||||
let leader = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||
let leader_data = leader.info.clone();
|
||||
let leader_data1 = leader.info.clone();
|
||||
let leader_data2 = leader.info.clone();
|
||||
|
||||
let (alice, ledger_path) =
|
||||
create_tmp_genesis("wallet_cancel_tx", 10_000_000, leader_data.id, 1000);
|
||||
|
@ -1521,8 +1527,6 @@ mod tests {
|
|||
run_local_drone(alice.keypair(), leader_data.contact_info.ncp, sender);
|
||||
config_payer.drone_addr = receiver.recv().unwrap();
|
||||
config_witness.drone_addr = config_payer.drone_addr.clone();
|
||||
config_payer.leader = leader_data1;
|
||||
config_witness.leader = leader_data2;
|
||||
|
||||
let mut rpc_addr = leader_data.contact_info.ncp;
|
||||
rpc_addr.set_port(rpc_port);
|
||||
|
|
Loading…
Reference in New Issue