Skip to content

Commit

Permalink
psbt: fix signing with unknown devices
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Apr 12, 2023
1 parent 74a7ded commit cbc9818
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/view/psbt/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use electrum_client::ElectrumApi;
use gladis::Gladis;
use gtk::prelude::ListModelExt;
use gtk::{ApplicationWindow, MessageType};
use hwi::types::{HWIChain, HWIDevice, HWIDeviceType};
use hwi::types::HWIChain;
use hwi::HWIClient;
use miniscript::psbt::PsbtExt;
use relm::{init, Cast, Channel, Relm, Sender, StreamHandle, Update, Widget};
Expand Down Expand Up @@ -62,14 +62,6 @@ impl Component {
let signer = self.signer_for_index(signer_index);
let name = signer.name();
let master_fp = signer.master_fp();
let device = HWIDevice {
device_type: HWIDeviceType::Other(s!("")),
model: s!(""),
path: s!(""),
needs_pin_sent: false,
needs_passphrase_sent: false,
fingerprint: master_fp,
};

self.widgets
.show_sign(&format!("Signing with device {} [{}]", name, master_fp));
Expand All @@ -82,7 +74,21 @@ impl Component {
PublicNetwork::Signet => HWIChain::Signet,
};
thread::spawn(move || {
match HWIClient::get_client(&device, false, chain)
let device = match HWIClient::enumerate().ok().and_then(|devices| {
devices
.into_iter()
.filter_map(|d| d.ok())
.find(|d| d.fingerprint == master_fp)
}) {
None => {
sender
.send(SignMsg::Failed(name, master_fp, s!("device is not found")))
.expect("channel is broken");
return;
}
Some(device) => device,
};
match HWIClient::get_client(&device, true, chain)
.and_then(|client| client.sign_tx(&psbt).map(|resp| resp.psbt))
{
Err(err) => sender.send(SignMsg::Failed(name, master_fp, err.to_string())),
Expand Down

0 comments on commit cbc9818

Please sign in to comment.