@@ -8,7 +8,9 @@ use liana::{
8
8
miniscript:: bitcoin:: {
9
9
self , address, psbt:: Psbt , secp256k1, Address , Amount , Denomination , Network , OutPoint ,
10
10
} ,
11
- spend:: { create_spend, SpendCreationError , SpendOutputAddress , SpendTxFees , TxGetter } ,
11
+ spend:: {
12
+ create_spend, CandidateCoin , SpendCreationError , SpendOutputAddress , SpendTxFees , TxGetter ,
13
+ } ,
12
14
} ;
13
15
14
16
use liana_ui:: {
@@ -20,7 +22,7 @@ use crate::{
20
22
app:: { cache:: Cache , error:: Error , message:: Message , state:: psbt, view, wallet:: Wallet } ,
21
23
daemon:: {
22
24
model:: { remaining_sequence, Coin , SpendTx } ,
23
- Daemon , DaemonError ,
25
+ Daemon ,
24
26
} ,
25
27
} ;
26
28
@@ -74,6 +76,7 @@ pub struct DefineSpend {
74
76
is_valid : bool ,
75
77
is_duplicate : bool ,
76
78
79
+ network : Network ,
77
80
descriptor : LianaDescriptor ,
78
81
curve : secp256k1:: Secp256k1 < secp256k1:: VerifyOnly > ,
79
82
timelock : u16 ,
@@ -87,7 +90,12 @@ pub struct DefineSpend {
87
90
}
88
91
89
92
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 {
91
99
let balance_available = coins
92
100
. iter ( )
93
101
. filter_map ( |coin| {
@@ -101,7 +109,7 @@ impl DefineSpend {
101
109
let coins: Vec < ( Coin , bool ) > = coins
102
110
. iter ( )
103
111
. filter_map ( |c| {
104
- if c. spend_info . is_none ( ) {
112
+ if c. spend_info . is_none ( ) && !c . is_immature {
105
113
Some ( ( c. clone ( ) , false ) )
106
114
} else {
107
115
None
@@ -111,6 +119,7 @@ impl DefineSpend {
111
119
112
120
Self {
113
121
balance_available,
122
+ network,
114
123
descriptor,
115
124
curve : secp256k1:: Secp256k1 :: verification_only ( ) ,
116
125
timelock,
@@ -201,6 +210,28 @@ impl DefineSpend {
201
210
} )
202
211
. collect ( ) ;
203
212
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
+
204
235
let feerate_vb = self . feerate . value . parse :: < u64 > ( ) . expect ( "Checked before" ) ;
205
236
// Create a spend with empty inputs in order to use auto-selection.
206
237
match create_spend (
@@ -212,7 +243,7 @@ impl DefineSpend {
212
243
SpendTxFees :: Regular ( feerate_vb) ,
213
244
// we enter a dummy address to calculate
214
245
SpendOutputAddress {
215
- addr : Address :: from_str ( "" ) . unwrap ( ) . assume_checked ( ) ,
246
+ addr : dummy_address ,
216
247
info : None ,
217
248
} ,
218
249
) {
@@ -252,7 +283,10 @@ impl DefineSpend {
252
283
pub struct DaemonTxGetter < ' a > ( & ' a Arc < dyn Daemon + Sync + Send > ) ;
253
284
impl < ' a > TxGetter for DaemonTxGetter < ' a > {
254
285
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 ) )
256
290
}
257
291
}
258
292
0 commit comments