@@ -93,7 +93,7 @@ impl Point {
9393 /// use cardano_chain_follower::Point;
9494 ///
9595 /// let slot = 42;
96- /// let hash = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
96+ /// let hash = vec![0; 32 ];
9797 /// let point = Point::new(slot, hash);
9898 /// ```
9999 #[ must_use]
@@ -244,55 +244,6 @@ impl Point {
244244 }
245245 }
246246
247- /// Compares the hash stored in the `Point` with a known hash.
248- /// It returns `true` if the hashes match and `false` otherwise. If the
249- /// provided hash is `None`, the function checks if the `Point` has an
250- /// empty hash.
251- ///
252- /// # Parameters
253- ///
254- /// * `hash` - An `Option<Hash<32>>` containing the hash to compare against. If
255- /// `Some`, the contained hash is compared with the `Point`'s hash. If `None`, the
256- /// function checks if the `Point`'s hash is empty.
257- ///
258- /// # Returns
259- ///
260- /// A `bool` indicating whether the hashes match.
261- ///
262- /// # Examples
263- ///
264- /// ```rs
265- /// use cardano_chain_follower::Point;
266- ///
267- /// use pallas::crypto::hash::Hash;
268- ///
269- /// let point = Point::new(42, vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
270- /// let hash = Some(Hash::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]));
271- /// assert!(point.cmp_hash(&hash));
272- ///
273- /// let empty_point = Point::fuzzy(42);
274- /// assert!(empty_point.cmp_hash(&None));
275- /// ```
276- #[ must_use]
277- pub fn cmp_hash ( & self , hash : & Option < Hash < 32 > > ) -> bool {
278- match hash {
279- Some ( cmp_hash) => {
280- match self . 0 {
281- pallas:: network:: miniprotocols:: Point :: Specific ( _, ref hash) => {
282- * * hash == * * cmp_hash
283- } ,
284- pallas:: network:: miniprotocols:: Point :: Origin => false ,
285- }
286- } ,
287- None => {
288- match self . 0 {
289- pallas:: network:: miniprotocols:: Point :: Specific ( _, ref hash) => hash. is_empty ( ) ,
290- pallas:: network:: miniprotocols:: Point :: Origin => true ,
291- }
292- } ,
293- }
294- }
295-
296247 /// Retrieves the slot number from the `Point`. If the `Point`
297248 /// is the origin, it returns a default slot number.
298249 ///
@@ -306,15 +257,15 @@ impl Point {
306257 /// ```rs
307258 /// use cardano_chain_follower::{Point, ORIGIN_POINT};
308259 ///
309- /// let specific_point = Point::new(42, vec![1, 2, 3 ]);
260+ /// let specific_point = Point::new(42, vec![0; 32 ]);
310261 /// assert_eq!(specific_point.slot_or_default(), 42);
311262 ///
312263 /// let origin_point = ORIGIN_POINT;
313- /// assert_eq!(origin_point.slot_or_default(), 0); // assuming 0 is the default
264+ /// assert_eq!(origin_point.slot_or_default(), 0.into() ); // assuming 0 is the default
314265 /// ```
315266 #[ must_use]
316- pub fn slot_or_default ( & self ) -> u64 {
317- self . 0 . slot_or_default ( )
267+ pub fn slot_or_default ( & self ) -> Slot {
268+ self . 0 . slot_or_default ( ) . into ( )
318269 }
319270
320271 /// Retrieves the hash from the `Point`. If the `Point` is
@@ -374,6 +325,31 @@ impl Point {
374325 }
375326}
376327
328+ impl PartialEq < Option < Hash < 32 > > > for Point {
329+ /// Compares the hash stored in the `Point` with a known hash.
330+ /// It returns `true` if the hashes match and `false` otherwise. If the
331+ /// provided hash is `None`, the function checks if the `Point` has an
332+ /// empty hash.
333+ fn eq ( & self , other : & Option < Hash < 32 > > ) -> bool {
334+ match other {
335+ Some ( cmp_hash) => {
336+ match self . 0 {
337+ pallas:: network:: miniprotocols:: Point :: Specific ( _, ref hash) => {
338+ * * hash == * * cmp_hash
339+ } ,
340+ pallas:: network:: miniprotocols:: Point :: Origin => false ,
341+ }
342+ } ,
343+ None => {
344+ match self . 0 {
345+ pallas:: network:: miniprotocols:: Point :: Specific ( _, ref hash) => hash. is_empty ( ) ,
346+ pallas:: network:: miniprotocols:: Point :: Origin => true ,
347+ }
348+ } ,
349+ }
350+ }
351+ }
352+
377353impl Display for Point {
378354 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: result:: Result < ( ) , std:: fmt:: Error > {
379355 if * self == Self :: ORIGIN {
@@ -387,9 +363,9 @@ impl Display for Point {
387363 let slot = self . slot_or_default ( ) ;
388364 let hash = self . hash_or_default ( ) ;
389365 if hash. is_empty ( ) {
390- return write ! ( f, "Point @ Probe:{slot}" ) ;
366+ return write ! ( f, "Point @ Probe:{slot:? }" ) ;
391367 }
392- write ! ( f, "Point @ {slot}:{}" , hex:: encode( hash) )
368+ write ! ( f, "Point @ {slot:? }:{}" , hex:: encode( hash) )
393369 }
394370}
395371
@@ -422,10 +398,6 @@ impl Ord for Point {
422398}
423399
424400impl PartialEq < u64 > for Point {
425- /// Allows to compare a `SnapshotID` against `u64` (Just the Immutable File Number).
426- ///
427- /// Equality ONLY checks the Immutable File Number, not the path.
428- /// This is because the Filename is already the Immutable File Number.
429401 fn eq ( & self , other : & u64 ) -> bool {
430402 self . 0 . slot_or_default ( ) == * other
431403 }
@@ -510,11 +482,11 @@ mod tests {
510482 let origin1 = Point :: ORIGIN ;
511483 let point1 = Point :: new ( 100u64 . into ( ) , [ 8 ; 32 ] . into ( ) ) ;
512484
513- assert ! ( ! origin1. cmp_hash ( & Some ( Hash :: new( [ 0 ; 32 ] ) ) ) ) ;
514- assert ! ( origin1. cmp_hash ( & None ) ) ;
485+ assert ! ( origin1 != Some ( Hash :: new( [ 0 ; 32 ] ) ) ) ;
486+ assert ! ( origin1 == None :: < Hash < 32 >> ) ;
515487
516- assert ! ( point1. cmp_hash ( & Some ( Hash :: new( [ 8 ; 32 ] ) ) ) ) ;
517- assert ! ( ! point1. cmp_hash ( & None ) ) ;
488+ assert ! ( point1 == Some ( Hash :: new( [ 8 ; 32 ] ) ) ) ;
489+ assert ! ( point1 != None :: < Hash < 32 >> ) ;
518490 }
519491
520492 #[ test]
0 commit comments