@@ -208,7 +208,7 @@ def get_address(self):
208
208
assert_equal (self ._mode , MiniWalletMode .ADDRESS_OP_TRUE )
209
209
return self ._address
210
210
211
- def get_utxo (self , * , txid : str = '' , vout : Optional [int ] = None , mark_as_spent = True ) -> dict :
211
+ def get_utxo (self , * , txid : str = '' , vout : Optional [int ] = None , mark_as_spent = True , confirmed_only = False ) -> dict :
212
212
"""
213
213
Returns a utxo and marks it as spent (pops it from the internal list)
214
214
@@ -224,19 +224,23 @@ def get_utxo(self, *, txid: str = '', vout: Optional[int] = None, mark_as_spent=
224
224
utxo_filter = reversed (mature_coins ) # By default the largest utxo
225
225
if vout is not None :
226
226
utxo_filter = filter (lambda utxo : vout == utxo ['vout' ], utxo_filter )
227
+ if confirmed_only :
228
+ utxo_filter = filter (lambda utxo : utxo ['confirmations' ] > 0 , utxo_filter )
227
229
index = self ._utxos .index (next (utxo_filter ))
228
230
if mark_as_spent :
229
231
return self ._utxos .pop (index )
230
232
else :
231
233
return self ._utxos [index ]
232
234
233
- def get_utxos (self , * , include_immature_coinbase = False , mark_as_spent = True ):
235
+ def get_utxos (self , * , include_immature_coinbase = False , mark_as_spent = True , confirmed_only = False ):
234
236
"""Returns the list of all utxos and optionally mark them as spent"""
235
237
if not include_immature_coinbase :
236
238
blocks_height = self ._test_node .getblockchaininfo ()['blocks' ]
237
239
utxo_filter = filter (lambda utxo : not utxo ['coinbase' ] or COINBASE_MATURITY - 1 <= blocks_height - utxo ['height' ], self ._utxos )
238
240
else :
239
241
utxo_filter = self ._utxos
242
+ if confirmed_only :
243
+ utxo_filter = filter (lambda utxo : utxo ['confirmations' ] > 0 , utxo_filter )
240
244
utxos = deepcopy (list (utxo_filter ))
241
245
if mark_as_spent :
242
246
self ._utxos = []
@@ -286,14 +290,15 @@ def create_self_transfer_multi(
286
290
locktime = 0 ,
287
291
sequence = 0 ,
288
292
fee_per_output = 1000 ,
289
- target_weight = 0
293
+ target_weight = 0 ,
294
+ confirmed_only = False
290
295
):
291
296
"""
292
297
Create and return a transaction that spends the given UTXOs and creates a
293
298
certain number of outputs with equal amounts. The output amounts can be
294
299
set by amount_per_output or automatically calculated with a fee_per_output.
295
300
"""
296
- utxos_to_spend = utxos_to_spend or [self .get_utxo ()]
301
+ utxos_to_spend = utxos_to_spend or [self .get_utxo (confirmed_only = confirmed_only )]
297
302
sequence = [sequence ] * len (utxos_to_spend ) if type (sequence ) is int else sequence
298
303
assert_equal (len (utxos_to_spend ), len (sequence ))
299
304
@@ -333,9 +338,17 @@ def create_self_transfer_multi(
333
338
"tx" : tx ,
334
339
}
335
340
336
- def create_self_transfer (self , * , fee_rate = Decimal ("0.003" ), fee = Decimal ("0" ), utxo_to_spend = None , locktime = 0 , sequence = 0 , target_weight = 0 ):
341
+ def create_self_transfer (self , * ,
342
+ fee_rate = Decimal ("0.003" ),
343
+ fee = Decimal ("0" ),
344
+ utxo_to_spend = None ,
345
+ locktime = 0 ,
346
+ sequence = 0 ,
347
+ target_weight = 0 ,
348
+ confirmed_only = False
349
+ ):
337
350
"""Create and return a tx with the specified fee. If fee is 0, use fee_rate, where the resulting fee may be exact or at most one satoshi higher than needed."""
338
- utxo_to_spend = utxo_to_spend or self .get_utxo ()
351
+ utxo_to_spend = utxo_to_spend or self .get_utxo (confirmed_only = confirmed_only )
339
352
assert fee_rate >= 0
340
353
assert fee >= 0
341
354
# calculate fee
0 commit comments