@@ -251,63 +251,76 @@ impl From<ConfirmationBlockTime> for ReceiveTo {
251251 }
252252}
253253
254- /// Receive a tx output with the given value in the latest block
255- pub fn receive_output_in_latest_block < K > ( wallet : & mut Wallet < K > , value : Amount , keychain : K ) -> OutPoint
256- where K : Ord + Clone + fmt:: Debug {
257- let latest_cp = wallet. latest_checkpoint ( ) ;
258- let height = latest_cp. height ( ) ;
259- assert ! ( height > 0 , "cannot receive tx into genesis block" ) ;
260- receive_output (
261- wallet,
262- value,
263- ConfirmationBlockTime {
264- block_id : latest_cp. block_id ( ) ,
265- confirmation_time : 0 ,
266- } ,
267- keychain,
268- )
269- }
270-
271- /// Receive a tx output with the given value and chain position
272- pub fn receive_output < K > (
273- wallet : & mut Wallet < K > ,
274- value : Amount ,
275- receive_to : impl Into < ReceiveTo > ,
276- keychain : K ,
277- ) -> OutPoint
278- where K : Ord + Clone + fmt:: Debug {
279- let addr = wallet. next_unused_address ( keychain) . expect ( "keychain should exist" ) . address ;
280- receive_output_to_address ( wallet, addr, value, receive_to)
281- }
282-
283- /// Receive a tx output to an address with the given value and chain position
284- pub fn receive_output_to_address < K > (
285- wallet : & mut Wallet < K > ,
286- addr : Address ,
287- value : Amount ,
288- receive_to : impl Into < ReceiveTo > ,
289- ) -> OutPoint
290- where K : Ord + Clone + fmt:: Debug {
291- let tx = Transaction {
292- version : transaction:: Version :: ONE ,
293- lock_time : absolute:: LockTime :: ZERO ,
294- input : vec ! [ ] ,
295- output : vec ! [ TxOut {
296- script_pubkey: addr. script_pubkey( ) ,
297- value,
298- } ] ,
299- } ;
300-
301- let txid = tx. compute_txid ( ) ;
302- insert_tx ( wallet, tx) ;
303-
304- match receive_to. into ( ) {
305- ReceiveTo :: Block ( anchor) => insert_anchor ( wallet, txid, anchor) ,
306- ReceiveTo :: Mempool ( last_seen) => insert_seen_at ( wallet, txid, last_seen) ,
307- }
308-
309- OutPoint { txid, vout : 0 }
310- }
254+ /// Receive a tx output with the given value in the latest block
255+ pub fn receive_output_in_latest_block < K > (
256+ wallet : & mut Wallet < K > ,
257+ value : Amount ,
258+ keychain : K ,
259+ ) -> OutPoint
260+ where
261+ K : Ord + Clone + fmt:: Debug ,
262+ {
263+ let latest_cp = wallet. latest_checkpoint ( ) ;
264+ let height = latest_cp. height ( ) ;
265+ assert ! ( height > 0 , "cannot receive tx into genesis block" ) ;
266+ receive_output (
267+ wallet,
268+ value,
269+ ConfirmationBlockTime {
270+ block_id : latest_cp. block_id ( ) ,
271+ confirmation_time : 0 ,
272+ } ,
273+ keychain,
274+ )
275+ }
276+
277+ /// Receive a tx output with the given value and chain position
278+ pub fn receive_output < K > (
279+ wallet : & mut Wallet < K > ,
280+ value : Amount ,
281+ receive_to : impl Into < ReceiveTo > ,
282+ keychain : K ,
283+ ) -> OutPoint
284+ where
285+ K : Ord + Clone + fmt:: Debug ,
286+ {
287+ let addr = wallet
288+ . next_unused_address ( keychain)
289+ . expect ( "keychain should exist" )
290+ . address ;
291+ receive_output_to_address ( wallet, addr, value, receive_to)
292+ }
293+
294+ /// Receive a tx output to an address with the given value and chain position
295+ pub fn receive_output_to_address < K > (
296+ wallet : & mut Wallet < K > ,
297+ addr : Address ,
298+ value : Amount ,
299+ receive_to : impl Into < ReceiveTo > ,
300+ ) -> OutPoint
301+ where
302+ K : Ord + Clone + fmt:: Debug ,
303+ {
304+ let tx = Transaction {
305+ version : transaction:: Version :: ONE ,
306+ lock_time : absolute:: LockTime :: ZERO ,
307+ input : vec ! [ ] ,
308+ output : vec ! [ TxOut {
309+ script_pubkey: addr. script_pubkey( ) ,
310+ value,
311+ } ] ,
312+ } ;
313+
314+ let txid = tx. compute_txid ( ) ;
315+ insert_tx ( wallet, tx) ;
316+
317+ match receive_to. into ( ) {
318+ ReceiveTo :: Block ( anchor) => insert_anchor ( wallet, txid, anchor) ,
319+ ReceiveTo :: Mempool ( last_seen) => insert_seen_at ( wallet, txid, last_seen) ,
320+ }
321+
322+ OutPoint { txid, vout : 0 }
323+ }
311324
312325/// Insert a checkpoint into the wallet. This can be used to extend the wallet's local chain
313326/// or to insert a block that did not exist previously. Note that if replacing a block with
@@ -361,15 +374,17 @@ pub fn insert_anchor<K: Ord + fmt::Debug + Clone>(
361374 . expect ( "failed to apply update" ) ;
362375}
363376
364- /// Marks the given `txid` seen as unconfirmed at `seen_at`
365- pub fn insert_seen_at < K > ( wallet : & mut Wallet < K > , txid : Txid , seen_at : u64 )
366- where K : Ord + Clone + fmt:: Debug {
367- let mut tx_update = TxUpdate :: default ( ) ;
368- tx_update. seen_ats = [ ( txid, seen_at) ] . into ( ) ;
369- wallet
370- . apply_update ( Update {
371- tx_update,
372- ..Default :: default ( )
373- } )
374- . expect ( "failed to apply update" ) ;
375- }
377+ /// Marks the given `txid` seen as unconfirmed at `seen_at`
378+ pub fn insert_seen_at < K > ( wallet : & mut Wallet < K > , txid : Txid , seen_at : u64 )
379+ where
380+ K : Ord + Clone + fmt:: Debug ,
381+ {
382+ let mut tx_update = TxUpdate :: default ( ) ;
383+ tx_update. seen_ats = [ ( txid, seen_at) ] . into ( ) ;
384+ wallet
385+ . apply_update ( Update {
386+ tx_update,
387+ ..Default :: default ( )
388+ } )
389+ . expect ( "failed to apply update" ) ;
390+ }
0 commit comments