Skip to content

Commit c3eb82f

Browse files
committed
wip
1 parent 38b606f commit c3eb82f

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

gui/src/app/state/spend/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl CreateSpendPanel {
3232
current: 0,
3333
steps: vec![
3434
Box::new(
35-
step::DefineSpend::new(descriptor, coins, timelock)
35+
step::DefineSpend::new(network, descriptor, coins, timelock)
3636
.with_coins_sorted(blockheight),
3737
),
3838
Box::new(step::SaveSpend::new(wallet)),
@@ -54,7 +54,7 @@ impl CreateSpendPanel {
5454
current: 0,
5555
steps: vec![
5656
Box::new(
57-
step::DefineSpend::new(descriptor, coins, timelock)
57+
step::DefineSpend::new(network, descriptor, coins, timelock)
5858
.with_preselected_coins(preselected_coins)
5959
.with_coins_sorted(blockheight)
6060
.self_send(),

gui/src/app/state/spend/step.rs

+40-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use liana::{
88
miniscript::bitcoin::{
99
self, address, psbt::Psbt, secp256k1, Address, Amount, Denomination, Network, OutPoint,
1010
},
11-
spend::{create_spend, SpendCreationError, SpendOutputAddress, SpendTxFees, TxGetter},
11+
spend::{
12+
create_spend, CandidateCoin, SpendCreationError, SpendOutputAddress, SpendTxFees, TxGetter,
13+
},
1214
};
1315

1416
use liana_ui::{
@@ -20,7 +22,7 @@ use crate::{
2022
app::{cache::Cache, error::Error, message::Message, state::psbt, view, wallet::Wallet},
2123
daemon::{
2224
model::{remaining_sequence, Coin, SpendTx},
23-
Daemon, DaemonError,
25+
Daemon,
2426
},
2527
};
2628

@@ -74,6 +76,7 @@ pub struct DefineSpend {
7476
is_valid: bool,
7577
is_duplicate: bool,
7678

79+
network: Network,
7780
descriptor: LianaDescriptor,
7881
curve: secp256k1::Secp256k1<secp256k1::VerifyOnly>,
7982
timelock: u16,
@@ -87,7 +90,12 @@ pub struct DefineSpend {
8790
}
8891

8992
impl DefineSpend {
90-
pub fn new(descriptor: LianaDescriptor, coins: &[Coin], timelock: u16) -> Self {
93+
pub fn new(
94+
network: Network,
95+
descriptor: LianaDescriptor,
96+
coins: &[Coin],
97+
timelock: u16,
98+
) -> Self {
9199
let balance_available = coins
92100
.iter()
93101
.filter_map(|coin| {
@@ -101,7 +109,7 @@ impl DefineSpend {
101109
let coins: Vec<(Coin, bool)> = coins
102110
.iter()
103111
.filter_map(|c| {
104-
if c.spend_info.is_none() {
112+
if c.spend_info.is_none() && !c.is_immature {
105113
Some((c.clone(), false))
106114
} else {
107115
None
@@ -111,6 +119,7 @@ impl DefineSpend {
111119

112120
Self {
113121
balance_available,
122+
network,
114123
descriptor,
115124
curve: secp256k1::Secp256k1::verification_only(),
116125
timelock,
@@ -201,6 +210,28 @@ impl DefineSpend {
201210
})
202211
.collect();
203212

213+
let coins: Vec<CandidateCoin> = if self.is_user_coin_selection {
214+
self.coins
215+
.iter()
216+
.map(|(c, selected)| CandidateCoin {
217+
amount: c.amount,
218+
outpoint: c.outpoint,
219+
deriv_index: c.derivation_index,
220+
is_change: c.is_change,
221+
sequence: None,
222+
must_select: *selected,
223+
})
224+
.collect()
225+
} else {
226+
self.coins.iter().map(|(c, _)| CandidateCoin {}).collect()
227+
};
228+
229+
let dummy_address = self
230+
.descriptor
231+
.change_descriptor()
232+
.derive(0.into(), &self.curve)
233+
.address(self.network);
234+
204235
let feerate_vb = self.feerate.value.parse::<u64>().expect("Checked before");
205236
// Create a spend with empty inputs in order to use auto-selection.
206237
match create_spend(
@@ -212,7 +243,7 @@ impl DefineSpend {
212243
SpendTxFees::Regular(feerate_vb),
213244
// we enter a dummy address to calculate
214245
SpendOutputAddress {
215-
addr: Address::from_str("").unwrap().assume_checked(),
246+
addr: dummy_address,
216247
info: None,
217248
},
218249
) {
@@ -252,7 +283,10 @@ impl DefineSpend {
252283
pub struct DaemonTxGetter<'a>(&'a Arc<dyn Daemon + Sync + Send>);
253284
impl<'a> TxGetter for DaemonTxGetter<'a> {
254285
fn get_tx(&mut self, txid: &bitcoin::Txid) -> Option<bitcoin::Transaction> {
255-
None
286+
self.0
287+
.list_txs(&[*txid])
288+
.ok()
289+
.and_then(|mut txs| txs.transactions.pop().map(|tx| tx.tx))
256290
}
257291
}
258292

gui/src/app/view/warning.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl From<&Error> for WarningMessage {
4141
Error::Unexpected(_) => WarningMessage("Unknown error".to_string()),
4242
Error::HardwareWallet(_) => WarningMessage("Hardware wallet error".to_string()),
4343
Error::Desc(e) => WarningMessage(format!("Descriptor analysis error: '{}'.", e)),
44+
Error::Spend(e) => WarningMessage(format!("Spend creation error: '{}'.", e)),
4445
}
4546
}
4647
}

gui/src/daemon/embedded.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
22

33
use super::{model::*, Daemon, DaemonError};
44
use liana::{
5-
commands::{CommandError, LabelItem},
5+
commands::LabelItem,
66
config::Config,
77
miniscript::bitcoin::{address, psbt::Psbt, Address, OutPoint, Txid},
88
DaemonControl, DaemonHandle,

0 commit comments

Comments
 (0)