@@ -74,11 +74,11 @@ impl ConfirmationTime {
7474 }
7575}
7676
77- impl From < ChainPosition < ConfirmationTimeHeightAnchor > > for ConfirmationTime {
78- fn from ( observed_as : ChainPosition < ConfirmationTimeHeightAnchor > ) -> Self {
77+ impl From < ChainPosition < ConfirmationBlockTime > > for ConfirmationTime {
78+ fn from ( observed_as : ChainPosition < ConfirmationBlockTime > ) -> Self {
7979 match observed_as {
8080 ChainPosition :: Confirmed ( a) => Self :: Confirmed {
81- height : a. confirmation_height ,
81+ height : a. block_id . height ,
8282 time : a. confirmation_time ,
8383 } ,
8484 ChainPosition :: Unconfirmed ( last_seen) => Self :: Unconfirmed { last_seen } ,
@@ -145,9 +145,7 @@ impl From<(&u32, &BlockHash)> for BlockId {
145145 }
146146}
147147
148- /// An [`Anchor`] implementation that also records the exact confirmation height of the transaction.
149- ///
150- /// Note that the confirmation block and the anchor block can be different here.
148+ /// An [`Anchor`] implementation that also records the exact confirmation time of the transaction.
151149///
152150/// Refer to [`Anchor`] for more details.
153151#[ derive( Debug , Default , Clone , PartialEq , Eq , Copy , PartialOrd , Ord , core:: hash:: Hash ) ]
@@ -156,70 +154,27 @@ impl From<(&u32, &BlockHash)> for BlockId {
156154 derive( serde:: Deserialize , serde:: Serialize ) ,
157155 serde( crate = "serde_crate" )
158156) ]
159- pub struct ConfirmationHeightAnchor {
160- /// The exact confirmation height of the transaction.
161- ///
162- /// It is assumed that this value is never larger than the height of the anchor block.
163- pub confirmation_height : u32 ,
157+ pub struct ConfirmationBlockTime {
164158 /// The anchor block.
165- pub anchor_block : BlockId ,
166- }
167-
168- impl Anchor for ConfirmationHeightAnchor {
169- fn anchor_block ( & self ) -> BlockId {
170- self . anchor_block
171- }
172-
173- fn confirmation_height_upper_bound ( & self ) -> u32 {
174- self . confirmation_height
175- }
176- }
177-
178- impl AnchorFromBlockPosition for ConfirmationHeightAnchor {
179- fn from_block_position ( _block : & bitcoin:: Block , block_id : BlockId , _tx_pos : usize ) -> Self {
180- Self {
181- anchor_block : block_id,
182- confirmation_height : block_id. height ,
183- }
184- }
185- }
186-
187- /// An [`Anchor`] implementation that also records the exact confirmation time and height of the
188- /// transaction.
189- ///
190- /// Note that the confirmation block and the anchor block can be different here.
191- ///
192- /// Refer to [`Anchor`] for more details.
193- #[ derive( Debug , Default , Clone , PartialEq , Eq , Copy , PartialOrd , Ord , core:: hash:: Hash ) ]
194- #[ cfg_attr(
195- feature = "serde" ,
196- derive( serde:: Deserialize , serde:: Serialize ) ,
197- serde( crate = "serde_crate" )
198- ) ]
199- pub struct ConfirmationTimeHeightAnchor {
200- /// The confirmation height of the transaction being anchored.
201- pub confirmation_height : u32 ,
159+ pub block_id : BlockId ,
202160 /// The confirmation time of the transaction being anchored.
203161 pub confirmation_time : u64 ,
204- /// The anchor block.
205- pub anchor_block : BlockId ,
206162}
207163
208- impl Anchor for ConfirmationTimeHeightAnchor {
164+ impl Anchor for ConfirmationBlockTime {
209165 fn anchor_block ( & self ) -> BlockId {
210- self . anchor_block
166+ self . block_id
211167 }
212168
213169 fn confirmation_height_upper_bound ( & self ) -> u32 {
214- self . confirmation_height
170+ self . block_id . height
215171 }
216172}
217173
218- impl AnchorFromBlockPosition for ConfirmationTimeHeightAnchor {
174+ impl AnchorFromBlockPosition for ConfirmationBlockTime {
219175 fn from_block_position ( block : & bitcoin:: Block , block_id : BlockId , _tx_pos : usize ) -> Self {
220176 Self {
221- anchor_block : block_id,
222- confirmation_height : block_id. height ,
177+ block_id,
223178 confirmation_time : block. header . time as _ ,
224179 }
225180 }
@@ -305,19 +260,19 @@ mod test {
305260
306261 #[ test]
307262 fn chain_position_ord ( ) {
308- let unconf1 = ChainPosition :: < ConfirmationHeightAnchor > :: Unconfirmed ( 10 ) ;
309- let unconf2 = ChainPosition :: < ConfirmationHeightAnchor > :: Unconfirmed ( 20 ) ;
310- let conf1 = ChainPosition :: Confirmed ( ConfirmationHeightAnchor {
311- confirmation_height : 9 ,
312- anchor_block : BlockId {
313- height : 20 ,
263+ let unconf1 = ChainPosition :: < ConfirmationBlockTime > :: Unconfirmed ( 10 ) ;
264+ let unconf2 = ChainPosition :: < ConfirmationBlockTime > :: Unconfirmed ( 20 ) ;
265+ let conf1 = ChainPosition :: Confirmed ( ConfirmationBlockTime {
266+ confirmation_time : 20 ,
267+ block_id : BlockId {
268+ height : 9 ,
314269 ..Default :: default ( )
315270 } ,
316271 } ) ;
317- let conf2 = ChainPosition :: Confirmed ( ConfirmationHeightAnchor {
318- confirmation_height : 12 ,
319- anchor_block : BlockId {
320- height : 15 ,
272+ let conf2 = ChainPosition :: Confirmed ( ConfirmationBlockTime {
273+ confirmation_time : 15 ,
274+ block_id : BlockId {
275+ height : 12 ,
321276 ..Default :: default ( )
322277 } ,
323278 } ) ;
0 commit comments