Skip to content

Commit 519c415

Browse files
committed
fix(cardano-blockchain-types): fix hash_or_default
1 parent 4e2bdc6 commit 519c415

File tree

1 file changed

+7
-10
lines changed
  • rust/cardano-blockchain-types/src

1 file changed

+7
-10
lines changed

rust/cardano-blockchain-types/src/point.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use std::{
1010

1111
use pallas::crypto::hash::Hash;
1212

13-
use crate::{
14-
hashes::{Blake2b256Hash, Blake2bHash},
15-
Slot,
16-
};
13+
use crate::{hashes::Blake2b256Hash, Slot};
1714

1815
/// A specific point in the blockchain. It can be used to
1916
/// identify a particular location within the blockchain, such as the tip (the
@@ -282,12 +279,12 @@ impl Point {
282279
/// # Examples
283280
///
284281
/// ```
285-
/// use cardano_blockchain_types::{hashes::Blake2bHash, Point};
282+
/// use cardano_blockchain_types::{hashes::Blake2b256Hash, Point};
286283
///
287284
/// let specific_point = Point::new(42.into(), [0; 32].into());
288285
/// assert_eq!(
289286
/// specific_point.hash_or_default(),
290-
/// Some(Blake2bHash::new(&[0; 32]))
287+
/// Some::<Blake2b256Hash>([0; 32].into())
291288
/// );
292289
///
293290
/// let origin_point = Point::ORIGIN;
@@ -297,7 +294,7 @@ impl Point {
297294
pub fn hash_or_default(&self) -> Option<Blake2b256Hash> {
298295
match &self.0 {
299296
pallas::network::miniprotocols::Point::Specific(_, hash) => {
300-
Some(Blake2bHash::new(hash))
297+
Blake2b256Hash::try_from(hash.clone()).ok()
301298
},
302299
// Origin has empty hash, so set it to None
303300
pallas::network::miniprotocols::Point::Origin => None,
@@ -507,16 +504,16 @@ fn cmp_point(
507504

508505
#[cfg(test)]
509506
mod tests {
510-
use crate::point::*;
507+
use crate::{hashes::Blake2bHash, point::*};
511508

512509
#[test]
513510
fn test_cmp_hash_simple() {
514511
let origin1 = Point::ORIGIN;
515512
let point1 = Point::new(100u64.into(), [8; 32].into());
516513

517-
assert!(origin1 != Some(Blake2bHash::<32>::new(&[0; 32])));
514+
assert!(origin1 != Some::<Blake2b256Hash>([0; 32].into()));
518515
assert!(origin1 == None::<Blake2b256Hash>);
519-
assert!(point1 == Some(Hash::<32>::new([8; 32])));
516+
assert!(point1 == Some::<Blake2b256Hash>([8; 32].into()));
520517
assert!(point1 != None::<Hash<32>>);
521518
}
522519

0 commit comments

Comments
 (0)