diff --git a/substrate/primitives/blockchain/src/header_metadata.rs b/substrate/primitives/blockchain/src/header_metadata.rs index b2910a32e9954..c6782a721ec1a 100644 --- a/substrate/primitives/blockchain/src/header_metadata.rs +++ b/substrate/primitives/blockchain/src/header_metadata.rs @@ -153,6 +153,29 @@ pub struct HashAndNumber { pub hash: Block::Hash, } +impl Eq for HashAndNumber {} + +impl PartialEq for HashAndNumber { + fn eq(&self, other: &Self) -> bool { + self.number.eq(&other.number) && self.hash.eq(&other.hash) + } +} + +impl Ord for HashAndNumber { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + match self.number.cmp(&other.number) { + std::cmp::Ordering::Equal => self.hash.cmp(&other.hash), + result => result, + } + } +} + +impl PartialOrd for HashAndNumber { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(&other)) + } +} + /// A tree-route from one block to another in the chain. /// /// All blocks prior to the pivot in the vector is the reverse-order unique ancestry