solpipe_keysigner/
config.rs1use std::sync::{Arc};
2
3use clap_utils::clap::ArgMatches;
4use hidapi::HidApi;
5use lock_api::Mutex;
6use solana_clap_v3_utils::input_parsers::pubkey_of_signer;
7use solana_remote_wallet::remote_wallet::RemoteWalletManager;
8use solana_sdk::pubkey::Pubkey;
9
10use crate::error::SolpipeError;
11pub(crate) const ARG_TX: &[u8] = b"tx";
12pub(crate) const ARG_OWNER: &[u8] = b"owner";
13pub(crate) const ARG_FEE_PAYER: &[u8] = b"payer";
14
15pub struct CliConfig{
16 pub fee_payer: String,
17 pub keypair_path: String
18}
19
20
21impl CliConfig{
22 pub fn new(
23 fee_payer: &String,
24 keypair_path: &String,
25 )->Self{
26 Self{
27 fee_payer: fee_payer.clone(),
28 keypair_path: keypair_path.clone(),
29 }
30 }
31}
32
33
34pub(crate) fn wm_setup() ->Result<Option<Arc<RemoteWalletManager>>,SolpipeError>{
35 let usb = HidApi::new();
36 if usb.is_err(){
37 return Err(SolpipeError::Custom("bad usb".to_owned()))
38 }
39 let x = usb.unwrap();
40 let wm = RemoteWalletManager::new(Arc::new(Mutex::new(x)));
41 let r_1 = wm.update_devices();
42 if r_1.is_err(){
43 if let Some(r_2) = r_1.err(){
44 return Err(SolpipeError::Custom(r_2.to_string()))
45 }
46 else{
47 return Err(SolpipeError::Unknown)
48 }
49 }
50 let m = wm.list_devices();
51 let mut iter = m.iter();
52 while let Some(d)=iter.next(){
53 eprintln!("device: {}; {}; {};",d.host_device_path,d.manufacturer,d.model,);
54 }
55 return Ok(Some(wm));
56}
57
58
59pub(crate) fn local_pubkey_of_signer(
60 matches: &ArgMatches,
61 name: &str,
62 wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
63)->Result<Pubkey,SolpipeError>{
64 let content=matches.value_of(name).unwrap_or("____blank____");
65 eprintln!("searching: name {}; pubkey lookup {};",name,content);
66 match pubkey_of_signer(&matches,name,wallet_manager){
67 Ok(x) => {
68 if x.is_none(){
69 return Err(SolpipeError::SignerNotAvailable)
70 }
71 return Ok(x.unwrap());
72 },
73 Err(err) => {
74 return Err(SolpipeError::Custom(err.to_string()))
75 },
76 }
77}