@@ -6,7 +6,9 @@ use bdk_chain::{
66} ;
77use bdk_coin_select:: { ChangePolicy , DrainWeights } ;
88use bdk_testenv:: { bitcoincore_rpc:: RpcApi , TestEnv } ;
9- use bdk_tx:: { CanonicalUnspents , Input , InputCandidates , RbfParams , TxStatus , TxWithStatus } ;
9+ use bdk_tx:: {
10+ CanonicalUnspents , ConfirmationStatus , Input , InputCandidates , RbfParams , TxWithStatus ,
11+ } ;
1012use bitcoin:: { absolute, Address , Amount , BlockHash , OutPoint , Transaction , TxOut , Txid } ;
1113use miniscript:: {
1214 plan:: { Assets , Plan } ,
@@ -71,17 +73,22 @@ impl Wallet {
7173 )
7274 }
7375
74- /// TODO: Add to chain sources.
76+ /// Info for the block at the tip.
77+ ///
78+ /// Returns a tuple of:
79+ /// - Tip's height. I.e. `tip.height`
80+ /// - Tip's MTP. I.e. `MTP(tip.height)`
7581 pub fn tip_info (
7682 & self ,
7783 client : & impl RpcApi ,
7884 ) -> anyhow:: Result < ( absolute:: Height , absolute:: Time ) > {
79- let tip = self . chain . tip ( ) . block_id ( ) ;
80- let tip_info = client. get_block_header_info ( & tip. hash ) ?;
81- let tip_height = absolute:: Height :: from_consensus ( tip. height ) ?;
82- let tip_time =
83- absolute:: Time :: from_consensus ( tip_info. median_time . unwrap_or ( tip_info. time ) as _ ) ?;
84- Ok ( ( tip_height, tip_time) )
85+ let tip_hash = self . chain . tip ( ) . block_id ( ) . hash ;
86+ let tip_info = client. get_block_header_info ( & tip_hash) ?;
87+ let tip_height = absolute:: Height :: from_consensus ( tip_info. height as u32 ) ?;
88+ let tip_mtp = absolute:: Time :: from_consensus (
89+ tip_info. median_time . expect ( "must have median time" ) as _ ,
90+ ) ?;
91+ Ok ( ( tip_height, tip_mtp) )
8592 }
8693
8794 // TODO: Maybe create an `AssetsBuilder` or `AssetsExt` that makes it easier to add
@@ -112,15 +119,16 @@ impl Wallet {
112119 }
113120
114121 pub fn canonical_txs ( & self ) -> impl Iterator < Item = TxWithStatus < Arc < Transaction > > > + ' _ {
115- pub fn status_from_position ( pos : ChainPosition < ConfirmationBlockTime > ) -> Option < TxStatus > {
122+ pub fn status_from_position (
123+ pos : ChainPosition < ConfirmationBlockTime > ,
124+ ) -> Option < ConfirmationStatus > {
116125 match pos {
117- bdk_chain:: ChainPosition :: Confirmed { anchor, .. } => Some ( TxStatus {
126+ bdk_chain:: ChainPosition :: Confirmed { anchor, .. } => Some ( ConfirmationStatus {
118127 height : absolute:: Height :: from_consensus (
119128 anchor. confirmation_height_upper_bound ( ) ,
120129 )
121130 . expect ( "must convert to height" ) ,
122- time : absolute:: Time :: from_consensus ( anchor. confirmation_time as _ )
123- . expect ( "must convert from time" ) ,
131+ prev_mtp : None , // TODO: Use `CheckPoint::prev_mtp`
124132 } ) ,
125133 bdk_chain:: ChainPosition :: Unconfirmed { .. } => None ,
126134 }
0 commit comments