From 1a6221bbf022b934c2ac89bcea536478c47cbcbb Mon Sep 17 00:00:00 2001 From: edouard Date: Fri, 7 Apr 2023 17:21:23 +0200 Subject: [PATCH] gui: display if signer signed in modal close #349 --- gui/src/app/state/spend/detail.rs | 11 ++++++----- gui/src/app/view/spend/detail.rs | 4 ++-- gui/src/daemon/model.rs | 22 +++++++++++++++++++++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/gui/src/app/state/spend/detail.rs b/gui/src/app/state/spend/detail.rs index 3b4348fb..990c36b7 100644 --- a/gui/src/app/state/spend/detail.rs +++ b/gui/src/app/state/spend/detail.rs @@ -1,3 +1,4 @@ +use std::collections::HashSet; use std::sync::Arc; use iced::Command; @@ -90,7 +91,7 @@ impl SpendTxState { self.action = Some(Box::new(DeleteAction::default())); } view::SpendTxMessage::Sign => { - let action = SignAction::new(self.wallet.clone()); + let action = SignAction::new(self.tx.signers(), self.wallet.clone()); let cmd = action.load(daemon); self.action = Some(Box::new(action)); return cmd; @@ -270,18 +271,18 @@ pub struct SignAction { processing: bool, hws: Vec, error: Option, - signed: Vec, + signed: HashSet, } impl SignAction { - pub fn new(wallet: Arc) -> Self { + pub fn new(signed: HashSet, wallet: Arc) -> Self { Self { wallet, chosen_hw: None, processing: false, hws: Vec::new(), error: None, - signed: Vec::new(), + signed, } } } @@ -332,7 +333,7 @@ impl Action for SignAction { Err(e) => self.error = Some(e), Ok((psbt, fingerprint)) => { self.error = None; - self.signed.push(fingerprint); + self.signed.insert(fingerprint); let daemon = daemon.clone(); tx.psbt = psbt.clone(); return Command::perform( diff --git a/gui/src/app/view/spend/detail.rs b/gui/src/app/view/spend/detail.rs index 142c572b..5755b0ac 100644 --- a/gui/src/app/view/spend/detail.rs +++ b/gui/src/app/view/spend/detail.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use iced::{ widget::{scrollable, tooltip, Space}, @@ -713,7 +713,7 @@ pub fn sign_action<'a>( signer_alias: Option<&'a String>, processing: bool, chosen_hw: Option, - signed: &[Fingerprint], + signed: &HashSet, ) -> Element<'a, Message> { Column::new() .push_maybe(warning.map(|w| warn(Some(w)))) diff --git a/gui/src/daemon/model.rs b/gui/src/daemon/model.rs index 283f022e..a0b5e174 100644 --- a/gui/src/daemon/model.rs +++ b/gui/src/daemon/model.rs @@ -1,10 +1,15 @@ +use std::collections::HashSet; + pub use liana::{ commands::{ CreateSpendResult, GetAddressResult, GetInfoResult, ListCoinsEntry, ListCoinsResult, ListSpendEntry, ListSpendResult, ListTransactionsResult, TransactionInfo, }, descriptors::{PartialSpendInfo, PathSpendInfo}, - miniscript::bitcoin::{util::psbt::Psbt, Amount, Transaction}, + miniscript::bitcoin::{ + util::{bip32::Fingerprint, psbt::Psbt}, + Amount, Transaction, + }, }; pub type Coin = ListCoinsEntry; @@ -101,6 +106,21 @@ impl SpendTx { .values() .find(|&path| path.sigs_count >= path.threshold) } + + pub fn signers(&self) -> HashSet { + let mut signers = HashSet::new(); + for (fg, _) in self.sigs.primary_path().signed_pubkeys.keys() { + signers.insert(*fg); + } + + for path in self.sigs.recovery_paths().values() { + for (fg, _) in path.signed_pubkeys.keys() { + signers.insert(*fg); + } + } + + signers + } } #[derive(Debug, Clone)]