@@ -10,6 +10,8 @@ use std::{
1010
1111use pallas:: crypto:: hash:: Hash ;
1212
13+ use crate :: { hashes:: Blake2bHash , Slot } ;
14+
1315/// A specific point in the blockchain. It can be used to
1416/// identify a particular location within the blockchain, such as the tip (the
1517/// most recent block) or any other block. It has special kinds of `Point`,
@@ -78,8 +80,8 @@ impl Point {
7880 ///
7981 /// # Parameters
8082 ///
81- /// * `slot` - A `u64` value representing the slot number in the blockchain.
82- /// * `hash` - A `Vec<u8>` containing the hash of the block at the specified slot.
83+ /// * `slot` - A `Slot` representing the slot number in the blockchain.
84+ /// * `hash` - A `Blake2bHash` size 32, block hash at the specified slot.
8385 ///
8486 /// # Returns
8587 ///
@@ -95,8 +97,11 @@ impl Point {
9597 /// let point = Point::new(slot, hash);
9698 /// ```
9799 #[ must_use]
98- pub fn new ( slot : u64 , hash : Vec < u8 > ) -> Self {
99- Self ( pallas:: network:: miniprotocols:: Point :: Specific ( slot, hash) )
100+ pub fn new ( slot : Slot , hash : Blake2bHash < 32 > ) -> Self {
101+ Self ( pallas:: network:: miniprotocols:: Point :: Specific (
102+ slot. into ( ) ,
103+ hash. into ( ) ,
104+ ) )
100105 }
101106
102107 /// Creates a new `Point` instance representing a specific
@@ -106,7 +111,7 @@ impl Point {
106111 ///
107112 /// # Parameters
108113 ///
109- /// * `slot` - A `u64` value representing the slot number in the blockchain.
114+ /// * `slot` - A `Slot` representing the slot number in the blockchain.
110115 ///
111116 /// # Returns
112117 ///
@@ -121,9 +126,9 @@ impl Point {
121126 /// let point = Point::fuzzy(slot);
122127 /// ```
123128 #[ must_use]
124- pub fn fuzzy ( slot : u64 ) -> Self {
129+ pub fn fuzzy ( slot : Slot ) -> Self {
125130 Self ( pallas:: network:: miniprotocols:: Point :: Specific (
126- slot,
131+ slot. into ( ) ,
127132 Vec :: new ( ) ,
128133 ) )
129134 }
@@ -137,7 +142,9 @@ impl Point {
137142 Self :: TIP
138143 } else {
139144 match self . 0 {
140- pallas:: network:: miniprotocols:: Point :: Specific ( slot, _) => Self :: fuzzy ( slot) ,
145+ pallas:: network:: miniprotocols:: Point :: Specific ( slot, _) => {
146+ Self :: fuzzy ( slot. into ( ) )
147+ } ,
141148 pallas:: network:: miniprotocols:: Point :: Origin => Self :: ORIGIN ,
142149 }
143150 }
@@ -500,16 +507,16 @@ mod tests {
500507
501508 #[ test]
502509 fn test_create_points ( ) {
503- let point1 = Point :: new ( 100u64 , vec ! [ ] ) ;
504- let fuzzy1 = Point :: fuzzy ( 100u64 ) ;
510+ let point1 = Point :: new ( 100u64 . into ( ) , Blake2bHash :: new ( & [ ] ) ) ;
511+ let fuzzy1 = Point :: fuzzy ( 100u64 . into ( ) ) ;
505512
506513 assert ! ( point1 == fuzzy1) ;
507514 }
508515
509516 #[ test]
510517 fn test_cmp_hash_simple ( ) {
511518 let origin1 = Point :: ORIGIN ;
512- let point1 = Point :: new ( 100u64 , vec ! [ 8 ; 32 ] ) ;
519+ let point1 = Point :: new ( 100u64 . into ( ) , [ 8 ; 32 ] . into ( ) ) ;
513520
514521 assert ! ( !origin1. cmp_hash( & Some ( Hash :: new( [ 0 ; 32 ] ) ) ) ) ;
515522 assert ! ( origin1. cmp_hash( & None ) ) ;
@@ -520,16 +527,16 @@ mod tests {
520527
521528 #[ test]
522529 fn test_get_hash_simple ( ) {
523- let point1 = Point :: new ( 100u64 , vec ! [ 8 ; 32 ] ) ;
530+ let point1 = Point :: new ( 100u64 . into ( ) , [ 8 ; 32 ] . into ( ) ) ;
524531
525532 assert_eq ! ( point1. hash_or_default( ) , vec![ 8 ; 32 ] ) ;
526533 }
527534
528535 #[ test]
529536 fn test_identical_compare ( ) {
530- let point1 = Point :: new ( 100u64 , vec ! [ 8 ; 32 ] ) ;
531- let point2 = Point :: new ( 100u64 , vec ! [ 8 ; 32 ] ) ;
532- let point3 = Point :: new ( 999u64 , vec ! [ 8 ; 32 ] ) ;
537+ let point1 = Point :: new ( 100u64 . into ( ) , [ 8 ; 32 ] . into ( ) ) ;
538+ let point2 = Point :: new ( 100u64 . into ( ) , [ 8 ; 32 ] . into ( ) ) ;
539+ let point3 = Point :: new ( 999u64 . into ( ) , [ 8 ; 32 ] . into ( ) ) ;
533540
534541 assert ! ( point1. strict_eq( & point2) ) ;
535542 assert ! ( !point1. strict_eq( & point3) ) ;
@@ -541,9 +548,9 @@ mod tests {
541548 let origin2 = Point :: ORIGIN ;
542549 let tip1 = Point :: TIP ;
543550 let tip2 = Point :: TIP ;
544- let early_block = Point :: new ( 100u64 , vec ! [ ] ) ;
545- let late_block1 = Point :: new ( 5000u64 , vec ! [ ] ) ;
546- let late_block2 = Point :: new ( 5000u64 , vec ! [ ] ) ;
551+ let early_block = Point :: new ( 100u64 . into ( ) , Blake2bHash :: new ( & [ ] ) ) ;
552+ let late_block1 = Point :: new ( 5000u64 . into ( ) , Blake2bHash :: new ( & [ ] ) ) ;
553+ let late_block2 = Point :: new ( 5000u64 . into ( ) , Blake2bHash :: new ( & [ ] ) ) ;
547554
548555 assert ! ( origin1 == origin2) ;
549556 assert ! ( origin1 < early_block) ;
0 commit comments