1515//! # Transactions
1616//!
1717
18- use std:: { io, fmt, str} ;
18+ use std:: { io, fmt, str, cmp } ;
1919use std:: collections:: HashMap ;
2020use std:: convert:: TryFrom ;
2121
@@ -34,7 +34,7 @@ use secp256k1_zkp::{
3434} ;
3535
3636/// Description of an asset issuance in a transaction input
37- #[ derive( Copy , Clone , Debug , Default , Eq , Hash , PartialEq ) ]
37+ #[ derive( Copy , Clone , Debug , Default , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
3838pub struct AssetIssuance {
3939 /// Zero for a new asset issuance; otherwise a blinding factor for the input
4040 pub asset_blinding_nonce : Tweak ,
@@ -343,7 +343,7 @@ impl std::error::Error for RelativeLockTimeError {
343343
344344
345345/// Transaction input witness
346- #[ derive( Clone , Default , PartialEq , Eq , Debug , Hash ) ]
346+ #[ derive( Clone , Default , PartialEq , Eq , Debug , Hash , PartialOrd , Ord ) ]
347347pub struct TxInWitness {
348348 /// Amount rangeproof
349349 pub amount_rangeproof : Option < Box < RangeProof > > ,
@@ -443,7 +443,7 @@ impl<'tx> PeginData<'tx> {
443443}
444444
445445/// A transaction input, which defines old coins to be consumed
446- #[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
446+ #[ derive( Clone , PartialEq , Eq , Debug , Hash , PartialOrd , Ord ) ]
447447pub struct TxIn {
448448 /// The reference to the previous output that is being used an an input
449449 pub previous_output : OutPoint ,
@@ -604,7 +604,7 @@ impl TxIn {
604604}
605605
606606/// Transaction output witness
607- #[ derive( Clone , Default , PartialEq , Eq , Debug , Hash ) ]
607+ #[ derive( Clone , Default , PartialEq , Eq , Debug , Hash , PartialOrd , Ord ) ]
608608pub struct TxOutWitness {
609609 /// Surjection proof showing that the asset commitment is legitimate
610610 // We Box it because surjection proof internally is an array [u8; N] that
@@ -651,7 +651,7 @@ pub struct PegoutData<'txo> {
651651}
652652
653653/// Transaction output
654- #[ derive( Clone , Default , PartialEq , Eq , Debug , Hash ) ]
654+ #[ derive( Clone , Default , PartialEq , Eq , Debug , Hash , PartialOrd , Ord ) ]
655655pub struct TxOut {
656656 /// Committed asset
657657 pub asset : confidential:: Asset ,
@@ -1067,6 +1067,26 @@ impl Decodable for Transaction {
10671067 }
10681068 }
10691069}
1070+
1071+ impl cmp:: PartialOrd for Transaction {
1072+ fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
1073+ Some ( self . cmp ( other) )
1074+ }
1075+ }
1076+ impl cmp:: Ord for Transaction {
1077+ fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
1078+ self . version
1079+ . cmp ( & other. version )
1080+ . then (
1081+ self . lock_time
1082+ . to_consensus_u32 ( )
1083+ . cmp ( & other. lock_time . to_consensus_u32 ( ) ) ,
1084+ )
1085+ . then ( self . input . cmp ( & other. input ) )
1086+ . then ( self . output . cmp ( & other. output ) )
1087+ }
1088+ }
1089+
10701090/// Hashtype of a transaction, encoded in the last byte of a signature
10711091/// Fixed values so they can be casted as integer types for encoding
10721092#[ derive( PartialEq , Eq , Debug , Copy , Clone ) ]
0 commit comments