Skip to content

Commit 9c59be6

Browse files
fmt
1 parent 5ad624c commit 9c59be6

File tree

1 file changed

+68
-90
lines changed

1 file changed

+68
-90
lines changed

dash/src/hash_types.rs

Lines changed: 68 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ macro_rules! impl_asref_push_bytes {
6565
// newtypes module is solely here so we can rustfmt::skip.
6666
pub use newtypes::*;
6767

68-
#[rustfmt::skip]
6968
mod newtypes {
7069

71-
use crate::alloc::string::ToString;
72-
7370
use core::str::FromStr;
74-
use std::cmp::Ordering;
75-
use hashes::{sha256, sha256d, hash160, hash_newtype, Hash, hash_newtype_no_ord};
76-
use hashes::hex::Error;
77-
use crate::prelude::String;
71+
use std::cmp::Ordering;
72+
7873
#[cfg(feature = "core-block-hash-use-x11")]
7974
use hashes::hash_x11;
80-
use crate::transaction::special_transaction::quorum_commitment::QuorumEntry;
75+
use hashes::hex::Error;
76+
use hashes::{Hash, hash_newtype, hash_newtype_no_ord, hash160, sha256, sha256d};
77+
78+
use crate::alloc::string::ToString;
79+
use crate::prelude::String;
80+
use crate::transaction::special_transaction::quorum_commitment::QuorumEntry;
8181

82-
#[cfg(feature = "core-block-hash-use-x11")]
82+
#[cfg(feature = "core-block-hash-use-x11")]
8383
hash_newtype! {
8484
/// A dash block hash.
8585
pub struct BlockHash(hash_x11::Hash);
@@ -151,47 +151,43 @@ use crate::transaction::special_transaction::quorum_commitment::QuorumEntry;
151151
pub struct QuorumOrderingHash(sha256d::Hash);
152152
}
153153

154-
hash_newtype_no_ord! {
155-
pub struct ScoreHash(sha256::Hash);
156-
157-
}
154+
hash_newtype_no_ord! {
155+
pub struct ScoreHash(sha256::Hash);
156+
}
158157

159-
impl Ord for ScoreHash {
160-
fn cmp(&self, other: &Self) -> Ordering {
161-
let mut self_bytes = self.0.to_byte_array();
162-
let mut other_bytes = other.0.to_byte_array();
158+
impl Ord for ScoreHash {
159+
fn cmp(&self, other: &Self) -> Ordering {
160+
let mut self_bytes = self.0.to_byte_array();
161+
let mut other_bytes = other.0.to_byte_array();
163162

164-
self_bytes.reverse();
165-
other_bytes.reverse();
163+
self_bytes.reverse();
164+
other_bytes.reverse();
166165

167-
self_bytes.cmp(&other_bytes)
166+
self_bytes.cmp(&other_bytes)
167+
}
168168
}
169-
}
170-
171-
// impl Ord for QuorumOrderingHash {
172-
// fn cmp(&self, other: &Self) -> Ordering {
173-
// let mut self_bytes = self.0.to_byte_array();
174-
// let mut other_bytes = other.0.to_byte_array();
175-
//
176-
// self_bytes.reverse();
177-
// other_bytes.reverse();
178-
//
179-
// self_bytes.cmp(&other_bytes)
180-
// }
181-
// }
182169

183-
impl PartialOrd for ScoreHash {
184-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
185-
Some(self.cmp(other))
170+
// impl Ord for QuorumOrderingHash {
171+
// fn cmp(&self, other: &Self) -> Ordering {
172+
// let mut self_bytes = self.0.to_byte_array();
173+
// let mut other_bytes = other.0.to_byte_array();
174+
//
175+
// self_bytes.reverse();
176+
// other_bytes.reverse();
177+
//
178+
// self_bytes.cmp(&other_bytes)
179+
// }
180+
// }
181+
182+
impl PartialOrd for ScoreHash {
183+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
186184
}
187-
}
188-
189-
// impl PartialOrd for QuorumOrderingHash {
190-
// fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
191-
// Some(self.cmp(other))
192-
// }
193-
// }
194185

186+
// impl PartialOrd for QuorumOrderingHash {
187+
// fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
188+
// Some(self.cmp(other))
189+
// }
190+
// }
195191

196192
/// A hash used to identify a quorum
197193
pub type QuorumHash = BlockHash;
@@ -233,14 +229,10 @@ impl PartialOrd for ScoreHash {
233229

234230
impl Txid {
235231
/// Create a Txid from a string
236-
pub fn from_hex(s: &str) -> Result<Txid, Error> {
237-
Ok(Self(sha256d::Hash::from_str(s)?))
238-
}
232+
pub fn from_hex(s: &str) -> Result<Txid, Error> { Ok(Self(sha256d::Hash::from_str(s)?)) }
239233

240234
/// Convert a Txid to a string
241-
pub fn to_hex(&self) -> String {
242-
self.0.to_string()
243-
}
235+
pub fn to_hex(&self) -> String { self.0.to_string() }
244236
}
245237

246238
impl ProTxHash {
@@ -250,21 +242,17 @@ impl PartialOrd for ScoreHash {
250242
}
251243

252244
/// Convert a ProTxHash to a string
253-
pub fn to_hex(&self) -> String {
254-
self.0.to_string()
255-
}
245+
pub fn to_hex(&self) -> String { self.0.to_string() }
256246
}
257247

258-
impl ScoreHash {
248+
impl ScoreHash {
259249
/// Create a ScoreHash from a string
260250
pub fn from_hex(s: &str) -> Result<ScoreHash, Error> {
261251
Ok(Self(sha256::Hash::from_str(s)?))
262252
}
263253

264254
/// Convert a ScoreHash to a string
265-
pub fn to_hex(&self) -> String {
266-
self.0.to_string()
267-
}
255+
pub fn to_hex(&self) -> String { self.0.to_string() }
268256

269257
/// Creates a score based on the optional confirmed hash and the quorum modifier.
270258
///
@@ -274,9 +262,14 @@ impl PartialOrd for ScoreHash {
274262
///
275263
/// # Returns
276264
/// * A hashed score derived from the input values.
277-
pub fn create_score(confirmed_hash_hashed_with_pro_reg_tx: Option<ConfirmedHashHashedWithProRegTx>, modifier: QuorumModifierHash) -> Self {
265+
pub fn create_score(
266+
confirmed_hash_hashed_with_pro_reg_tx: Option<ConfirmedHashHashedWithProRegTx>,
267+
modifier: QuorumModifierHash,
268+
) -> Self {
278269
let mut bytes = vec![];
279-
if let Some(confirmed_hash_hashed_with_pro_reg_tx) = confirmed_hash_hashed_with_pro_reg_tx{
270+
if let Some(confirmed_hash_hashed_with_pro_reg_tx) =
271+
confirmed_hash_hashed_with_pro_reg_tx
272+
{
280273
bytes.append(&mut confirmed_hash_hashed_with_pro_reg_tx.to_byte_array().to_vec());
281274
}
282275
bytes.append(&mut modifier.to_byte_array().to_vec());
@@ -291,9 +284,7 @@ impl PartialOrd for ScoreHash {
291284
}
292285

293286
/// Convert a ScoreHash to a string
294-
pub fn to_hex(&self) -> String {
295-
self.0.to_string()
296-
}
287+
pub fn to_hex(&self) -> String { self.0.to_string() }
297288

298289
/// Creates an ordering hash based on the quorum and request id.
299290
///
@@ -312,10 +303,7 @@ impl PartialOrd for ScoreHash {
312303
}
313304

314305
impl Default for ConfirmedHash {
315-
fn default() -> Self {
316-
ConfirmedHash::from_byte_array([0;32])
317-
}
318-
306+
fn default() -> Self { ConfirmedHash::from_byte_array([0; 32]) }
319307
}
320308

321309
impl ConfirmedHash {
@@ -325,32 +313,30 @@ impl PartialOrd for ScoreHash {
325313
}
326314

327315
/// Convert a ConfirmedHash to a string
328-
pub fn to_hex(&self) -> String {
329-
self.0.to_string()
330-
}
316+
pub fn to_hex(&self) -> String { self.0.to_string() }
331317
}
332318

333319
impl ConfirmedHashHashedWithProRegTx {
334-
/// Create a ConfirmedHash from a string
320+
/// Create a ConfirmedHash from a string
335321
pub fn from_hex(s: &str) -> Result<ConfirmedHashHashedWithProRegTx, Error> {
336322
Ok(Self(sha256::Hash::from_str(s)?))
337323
}
338324

339325
/// Convert a ConfirmedHash to a string
340-
pub fn to_hex(&self) -> String {
341-
self.0.to_string()
342-
}
326+
pub fn to_hex(&self) -> String { self.0.to_string() }
343327

344328
/// Hashes the members
345329
pub fn hash_members(pro_tx_hash: &ProTxHash, confirmed_hash: &ConfirmedHash) -> Self {
346330
Self::hash(&[pro_tx_hash.to_byte_array(), confirmed_hash.to_byte_array()].concat())
347331
}
348-
/// Hashes the members
349-
pub fn hash_members_confirmed_hash_optional(pro_tx_hash: &ProTxHash, confirmed_hash: Option<&ConfirmedHash>) -> Option<Self> {
350-
confirmed_hash.map(|confirmed_hash| {
351-
Self::hash(&[pro_tx_hash.to_byte_array(), confirmed_hash.to_byte_array()].concat())
352-
})
353-
332+
/// Hashes the members
333+
pub fn hash_members_confirmed_hash_optional(
334+
pro_tx_hash: &ProTxHash,
335+
confirmed_hash: Option<&ConfirmedHash>,
336+
) -> Option<Self> {
337+
confirmed_hash.map(|confirmed_hash| {
338+
Self::hash(&[pro_tx_hash.to_byte_array(), confirmed_hash.to_byte_array()].concat())
339+
})
354340
}
355341
}
356342

@@ -361,9 +347,7 @@ impl PartialOrd for ScoreHash {
361347
}
362348

363349
/// Convert a ConfirmedHash to a string
364-
pub fn to_hex(&self) -> String {
365-
self.0.to_string()
366-
}
350+
pub fn to_hex(&self) -> String { self.0.to_string() }
367351
}
368352

369353
impl InputsHash {
@@ -373,16 +357,12 @@ impl PartialOrd for ScoreHash {
373357
}
374358

375359
/// Convert an InputsHash to a string
376-
pub fn to_hex(&self) -> String {
377-
self.0.to_string()
378-
}
360+
pub fn to_hex(&self) -> String { self.0.to_string() }
379361
}
380362

381363
impl SpecialTransactionPayloadHash {
382364
/// Create a SpecialTransactionPayloadHash from a string
383-
pub fn to_hex(&self) -> String {
384-
self.0.to_string()
385-
}
365+
pub fn to_hex(&self) -> String { self.0.to_string() }
386366
}
387367

388368
impl PubkeyHash {
@@ -392,8 +372,6 @@ impl PartialOrd for ScoreHash {
392372
}
393373

394374
/// Convert a PubkeyHash to a string
395-
pub fn to_hex(&self) -> String {
396-
self.0.to_string()
397-
}
375+
pub fn to_hex(&self) -> String { self.0.to_string() }
398376
}
399377
}

0 commit comments

Comments
 (0)