keyfork-seed: add Client::discover_socket()?

This commit is contained in:
Ryan Heywood 2023-09-11 23:24:09 -05:00
parent fe8b901bd3
commit ff351b12a9
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
2 changed files with 5 additions and 2 deletions

View File

@ -13,6 +13,10 @@ impl Client {
Self { socket } Self { socket }
} }
pub fn discover_socket() -> Result<Self> {
super::socket::get_socket().map(|socket| Self { socket })
}
pub fn request(&mut self, req: &DerivationRequest) -> Result<DerivationResponse> { pub fn request(&mut self, req: &DerivationRequest) -> Result<DerivationResponse> {
try_encode_to(&bincode::serialize(&req)?, &mut self.socket)?; try_encode_to(&bincode::serialize(&req)?, &mut self.socket)?;
let resp = try_decode_from(&mut self.socket)?; let resp = try_decode_from(&mut self.socket)?;

View File

@ -7,8 +7,7 @@ use keyfork_seed::*;
fn main() -> Result<()> { fn main() -> Result<()> {
let args = cli::get_args(); let args = cli::get_args();
let socket = socket::get_socket()?; let mut client = Client::discover_socket()?;
let mut client = client::Client::new(socket);
let path = args.get_one::<DerivationPath>("path").expect("required"); let path = args.get_one::<DerivationPath>("path").expect("required");
let algo = args let algo = args
.get_one::<DerivationAlgorithm>("algorithm") .get_one::<DerivationAlgorithm>("algorithm")