gui: update lib liana with descriptors module cleanup

This commit is contained in:
edouard 2023-03-27 15:16:06 +02:00
parent 9c6059c996
commit f049c2f16e
8 changed files with 30 additions and 43 deletions

3
gui/Cargo.lock generated
View File

@ -1658,7 +1658,7 @@ dependencies = [
[[package]]
name = "liana"
version = "0.3.0"
source = "git+https://github.com/wizardsardine/liana?branch=master#fbde855ede57c2bfebd6e0a53adf396c5c65df30"
source = "git+https://github.com/wizardsardine/liana?branch=master#9c6059c9969c8f258854f2aad47b4c20ca4079af"
dependencies = [
"backtrace",
"base64",
@ -1667,7 +1667,6 @@ dependencies = [
"fern",
"getrandom",
"jsonrpc",
"libc",
"log",
"miniscript",
"rdrand",

View File

@ -2,7 +2,7 @@ use std::sync::Arc;
use iced::Command;
use liana::{
descriptors::LianaDescInfo,
descriptors::LianaPolicy,
miniscript::bitcoin::{
consensus,
util::{bip32::Fingerprint, psbt::Psbt},
@ -50,7 +50,7 @@ trait Action {
pub struct SpendTxState {
wallet: Arc<Wallet>,
desc_info: LianaDescInfo,
desc_policy: LianaPolicy,
tx: SpendTx,
saved: bool,
action: Option<Box<dyn Action>>,
@ -59,7 +59,7 @@ pub struct SpendTxState {
impl SpendTxState {
pub fn new(wallet: Arc<Wallet>, tx: SpendTx, saved: bool) -> Self {
Self {
desc_info: wallet.main_descriptor.info(),
desc_policy: wallet.main_descriptor.policy(),
wallet,
action: None,
tx,
@ -132,7 +132,7 @@ impl SpendTxState {
let content = detail::spend_view(
&self.tx,
self.saved,
&self.desc_info,
&self.desc_policy,
&self.wallet.keys_aliases,
cache.network,
);

View File

@ -4,7 +4,7 @@ use std::sync::Arc;
use iced::Command;
use liana::{
descriptors::MultipathDescriptor,
descriptors::LianaDescriptor,
miniscript::bitcoin::{
self, util::psbt::Psbt, Address, Amount, Denomination, Network, OutPoint,
},
@ -223,7 +223,7 @@ impl Recipient {
}
pub struct ChooseCoins {
descriptor: MultipathDescriptor,
descriptor: LianaDescriptor,
timelock: u32,
coins: Vec<(Coin, bool)>,
recipients: Vec<(Address, Amount)>,
@ -236,7 +236,7 @@ pub struct ChooseCoins {
impl ChooseCoins {
pub fn new(
descriptor: MultipathDescriptor,
descriptor: LianaDescriptor,
coins: Vec<Coin>,
timelock: u32,
blockheight: u32,

View File

@ -6,7 +6,7 @@ use iced::{
};
use liana::{
descriptors::{LianaDescInfo, PathInfo, PathSpendInfo},
descriptors::{LianaPolicy, PathInfo, PathSpendInfo},
miniscript::bitcoin::{
util::bip32::{DerivationPath, Fingerprint},
Address, Amount, Network, Transaction,
@ -38,7 +38,7 @@ use crate::{
pub fn spend_view<'a>(
tx: &'a SpendTx,
saved: bool,
desc_info: &'a LianaDescInfo,
desc_info: &'a LianaPolicy,
key_aliases: &'a HashMap<Fingerprint, String>,
network: Network,
) -> Element<'a, Message> {
@ -232,7 +232,7 @@ fn spend_header<'a>(tx: &SpendTx) -> Element<'a, Message> {
fn spend_overview_view<'a>(
tx: &'a SpendTx,
desc_info: &'a LianaDescInfo,
desc_info: &'a LianaPolicy,
key_aliases: &'a HashMap<Fingerprint, String>,
) -> Element<'a, Message> {
Container::new(
@ -281,7 +281,7 @@ fn spend_overview_view<'a>(
pub fn signatures<'a>(
tx: &'a SpendTx,
desc_info: &'a LianaDescInfo,
desc_info: &'a LianaPolicy,
keys_aliases: &'a HashMap<Fingerprint, String>,
) -> Element<'a, Message> {
Column::new()

View File

@ -9,7 +9,7 @@ use crate::{
use liana::{miniscript::bitcoin, signer::HotSigner};
use liana::descriptors::MultipathDescriptor;
use liana::descriptors::LianaDescriptor;
use liana::miniscript::bitcoin::util::bip32::Fingerprint;
pub const DEFAULT_WALLET_NAME: &str = "Liana";
@ -17,14 +17,14 @@ pub const DEFAULT_WALLET_NAME: &str = "Liana";
#[derive(Debug)]
pub struct Wallet {
pub name: String,
pub main_descriptor: MultipathDescriptor,
pub main_descriptor: LianaDescriptor,
pub keys_aliases: HashMap<Fingerprint, String>,
pub hardware_wallets: Vec<HardwareWalletConfig>,
pub signer: Option<Signer>,
}
impl Wallet {
pub fn new(main_descriptor: MultipathDescriptor) -> Self {
pub fn new(main_descriptor: LianaDescriptor) -> Self {
Self {
name: DEFAULT_WALLET_NAME.to_string(),
main_descriptor,
@ -50,7 +50,7 @@ impl Wallet {
}
pub fn descriptor_keys(&self) -> HashSet<Fingerprint> {
let info = self.main_descriptor.info();
let info = self.main_descriptor.policy();
let mut descriptor_keys = HashSet::new();
for (fingerprint, _) in info.primary_path().thresh_origins().1.iter() {
descriptor_keys.insert(*fingerprint);

View File

@ -14,7 +14,7 @@ use async_hwi::DeviceKind;
use liana::{
config::Config,
config::{BitcoinConfig, BitcoindConfig},
descriptors::MultipathDescriptor,
descriptors::LianaDescriptor,
miniscript::bitcoin,
};
@ -22,7 +22,7 @@ use liana::{
pub struct Context {
pub bitcoin_config: BitcoinConfig,
pub bitcoind_config: Option<BitcoindConfig>,
pub descriptor: Option<MultipathDescriptor>,
pub descriptor: Option<LianaDescriptor>,
pub keys: Vec<KeySetting>,
pub hws: Vec<(
DeviceKind,

View File

@ -5,7 +5,7 @@ use std::sync::Arc;
use iced::Command;
use liana::{
descriptors::{LianaDescKeys, MultipathDescriptor},
descriptors::{LianaDescriptor, LianaPolicy, PathInfo},
miniscript::{
bitcoin::{
util::bip32::{ChildNumber, DerivationPath, Fingerprint},
@ -410,38 +410,26 @@ impl Step for DefineDescriptor {
}
let spending_keys = if spending_keys.len() == 1 {
LianaDescKeys::from_single(spending_keys[0].clone())
PathInfo::Single(spending_keys[0].clone())
} else {
match LianaDescKeys::from_multi(self.spending_threshold, spending_keys) {
Ok(keys) => keys,
Err(e) => {
self.error = Some(e.to_string());
return false;
}
}
PathInfo::Multi(self.spending_threshold, spending_keys)
};
let recovery_keys = if recovery_keys.len() == 1 {
LianaDescKeys::from_single(recovery_keys[0].clone())
PathInfo::Single(recovery_keys[0].clone())
} else {
match LianaDescKeys::from_multi(self.recovery_threshold, recovery_keys) {
Ok(keys) => keys,
Err(e) => {
self.error = Some(e.to_string());
return false;
}
}
PathInfo::Multi(self.recovery_threshold, recovery_keys)
};
let desc = match MultipathDescriptor::new(spending_keys, recovery_keys, sequence.unwrap()) {
Ok(desc) => desc,
let policy = match LianaPolicy::new(spending_keys, recovery_keys, sequence.unwrap()) {
Ok(policy) => policy,
Err(e) => {
self.error = Some(e.to_string());
return false;
}
};
ctx.descriptor = Some(desc);
ctx.descriptor = Some(LianaDescriptor::new(policy));
if signer_is_used {
ctx.signer = Some(self.signer.clone());
}
@ -1115,7 +1103,7 @@ impl Step for ImportDescriptor {
ctx.bitcoin_config.network = self.network;
// descriptor forms for import or creation cannot be both empty or filled.
if !self.imported_descriptor.value.is_empty() {
if let Ok(desc) = MultipathDescriptor::from_str(&self.imported_descriptor.value) {
if let Ok(desc) = LianaDescriptor::from_str(&self.imported_descriptor.value) {
self.imported_descriptor.valid = true;
ctx.descriptor = Some(desc);
true
@ -1148,7 +1136,7 @@ impl From<ImportDescriptor> for Box<dyn Step> {
#[derive(Default)]
pub struct RegisterDescriptor {
descriptor: Option<MultipathDescriptor>,
descriptor: Option<LianaDescriptor>,
processing: bool,
chosen_hw: Option<usize>,
hws: Vec<HardwareWallet>,
@ -1262,7 +1250,7 @@ impl From<RegisterDescriptor> for Box<dyn Step> {
#[derive(Default)]
pub struct BackupDescriptor {
done: bool,
descriptor: Option<MultipathDescriptor>,
descriptor: Option<LianaDescriptor>,
}
impl Step for BackupDescriptor {

View File

@ -131,7 +131,7 @@ impl Step for RecoverMnemonic {
let fingerprint = signer.fingerprint();
if let Some(descriptor) = &ctx.descriptor {
let info = descriptor.info();
let info = descriptor.policy();
let mut descriptor_keys = HashSet::new();
for (fingerprint, _) in info.primary_path().thresh_origins().1.iter() {
descriptor_keys.insert(*fingerprint);