@@ -22,7 +22,7 @@ use crate::chain::channelmonitor::{
2222use crate :: chain:: transaction:: OutPoint ;
2323use crate :: chain:: WatchedOutput ;
2424use crate :: events:: bump_transaction:: sync:: WalletSourceSync ;
25- use crate :: events:: bump_transaction:: Utxo ;
25+ use crate :: events:: bump_transaction:: { ConfirmedUtxo , Utxo } ;
2626#[ cfg( any( test, feature = "_externalize_tests" ) ) ]
2727use crate :: ln:: chan_utils:: CommitmentTransaction ;
2828use crate :: ln:: channel_state:: ChannelDetails ;
@@ -62,7 +62,6 @@ use crate::util::persist::{KVStore, KVStoreSync, MonitorName};
6262use crate :: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
6363use crate :: util:: test_channel_signer:: { EnforcementState , TestChannelSigner } ;
6464
65- use bitcoin:: absolute:: LockTime ;
6665use bitcoin:: amount:: Amount ;
6766use bitcoin:: block:: Block ;
6867use bitcoin:: constants:: genesis_block;
@@ -72,7 +71,7 @@ use bitcoin::hashes::{hex::FromHex, Hash};
7271use bitcoin:: network:: Network ;
7372use bitcoin:: script:: { Builder , Script , ScriptBuf } ;
7473use bitcoin:: sighash:: { EcdsaSighashType , SighashCache } ;
75- use bitcoin:: transaction:: { Transaction , TxOut , Version } ;
74+ use bitcoin:: transaction:: { Transaction , TxOut } ;
7675use bitcoin:: { opcodes, Witness } ;
7776
7877use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
@@ -2211,7 +2210,7 @@ impl Drop for TestScorer {
22112210
22122211pub struct TestWalletSource {
22132212 secret_key : SecretKey ,
2214- utxos : Mutex < Vec < Utxo > > ,
2213+ utxos : Mutex < Vec < ConfirmedUtxo > > ,
22152214 secp : Secp256k1 < bitcoin:: secp256k1:: All > ,
22162215}
22172216
@@ -2220,21 +2219,13 @@ impl TestWalletSource {
22202219 Self { secret_key, utxos : Mutex :: new ( Vec :: new ( ) ) , secp : Secp256k1 :: new ( ) }
22212220 }
22222221
2223- pub fn add_utxo ( & self , outpoint : bitcoin:: OutPoint , value : Amount ) -> TxOut {
2224- let public_key = bitcoin:: PublicKey :: new ( self . secret_key . public_key ( & self . secp ) ) ;
2225- let utxo = Utxo :: new_v0_p2wpkh ( outpoint, value, & public_key. wpubkey_hash ( ) . unwrap ( ) ) ;
2226- self . utxos . lock ( ) . unwrap ( ) . push ( utxo. clone ( ) ) ;
2227- utxo. output
2228- }
2229-
2230- pub fn add_custom_utxo ( & self , utxo : Utxo ) -> TxOut {
2231- let output = utxo. output . clone ( ) ;
2222+ pub fn add_utxo ( & self , prevtx : Transaction , vout : u32 ) {
2223+ let utxo = ConfirmedUtxo :: new_p2wpkh ( prevtx, vout) . unwrap ( ) ;
22322224 self . utxos . lock ( ) . unwrap ( ) . push ( utxo) ;
2233- output
22342225 }
22352226
22362227 pub fn remove_utxo ( & self , outpoint : bitcoin:: OutPoint ) {
2237- self . utxos . lock ( ) . unwrap ( ) . retain ( |utxo| utxo. outpoint != outpoint) ;
2228+ self . utxos . lock ( ) . unwrap ( ) . retain ( |utxo| utxo. outpoint ( ) != outpoint) ;
22382229 }
22392230
22402231 pub fn clear_utxos ( & self ) {
@@ -2246,8 +2237,8 @@ impl TestWalletSource {
22462237 ) -> Result < Transaction , bitcoin:: sighash:: P2wpkhError > {
22472238 let utxos = self . utxos . lock ( ) . unwrap ( ) ;
22482239 for i in 0 ..tx. input . len ( ) {
2249- if let Some ( utxo) =
2250- utxos. iter ( ) . find ( |utxo| utxo. outpoint == tx. input [ i] . previous_output )
2240+ if let Some ( ConfirmedUtxo { utxo, .. } ) =
2241+ utxos. iter ( ) . find ( |utxo| utxo. outpoint ( ) == tx. input [ i] . previous_output )
22512242 {
22522243 let sighash = SighashCache :: new ( & tx) . p2wpkh_signature_hash (
22532244 i,
@@ -2277,16 +2268,17 @@ impl TestWalletSource {
22772268
22782269impl WalletSourceSync for TestWalletSource {
22792270 fn list_confirmed_utxos ( & self ) -> Result < Vec < Utxo > , ( ) > {
2280- Ok ( self . utxos . lock ( ) . unwrap ( ) . clone ( ) )
2271+ Ok ( self . utxos . lock ( ) . unwrap ( ) . iter ( ) . map ( | ConfirmedUtxo { utxo , .. } | utxo . clone ( ) ) . collect ( ) )
22812272 }
22822273
22832274 fn get_prevtx ( & self , utxo : & Utxo ) -> Result < Transaction , ( ) > {
2284- Ok ( Transaction {
2285- version : Version :: TWO ,
2286- lock_time : LockTime :: ZERO ,
2287- input : vec ! [ ] ,
2288- output : vec ! [ utxo. output. clone( ) ] ,
2289- } )
2275+ self . utxos
2276+ . lock ( )
2277+ . unwrap ( )
2278+ . iter ( )
2279+ . find ( |confirmed_utxo| confirmed_utxo. utxo == * utxo)
2280+ . map ( |ConfirmedUtxo { prevtx, .. } | prevtx. clone ( ) )
2281+ . ok_or ( ( ) )
22902282 }
22912283
22922284 fn get_change_script ( & self ) -> Result < ScriptBuf , ( ) > {
0 commit comments