@@ -61,6 +61,7 @@ use secp256k1::PublicKey;
6161use secp256k1:: { Message , Secp256k1 } ;
6262use secp256k1:: ecdsa:: RecoverableSignature ;
6363
64+ use core:: cmp:: Ordering ;
6465use core:: fmt:: { Display , Formatter , self } ;
6566use core:: iter:: FilterMap ;
6667use core:: num:: ParseIntError ;
@@ -248,7 +249,7 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
248249/// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
249250///
250251/// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
251- #[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
252+ #[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
252253pub struct Invoice {
253254 signed_invoice : SignedRawInvoice ,
254255}
@@ -258,7 +259,7 @@ pub struct Invoice {
258259///
259260/// This is not exported to bindings users as we don't have a good way to map the reference lifetimes making this
260261/// practically impossible to use safely in languages like C.
261- #[ derive( Eq , PartialEq , Debug , Clone ) ]
262+ #[ derive( Eq , PartialEq , Debug , Clone , Ord , PartialOrd ) ]
262263pub enum InvoiceDescription < ' f > {
263264 /// Reference to the directly supplied description in the invoice
264265 Direct ( & ' f Description ) ,
@@ -272,7 +273,7 @@ pub enum InvoiceDescription<'f> {
272273///
273274/// # Invariants
274275/// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`].
275- #[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
276+ #[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
276277pub struct SignedRawInvoice {
277278 /// The rawInvoice that the signature belongs to
278279 raw_invoice : RawInvoice ,
@@ -295,7 +296,7 @@ pub struct SignedRawInvoice {
295296/// Decoding and encoding should not lead to information loss but may lead to different hashes.
296297///
297298/// For methods without docs see the corresponding methods in [`Invoice`].
298- #[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
299+ #[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
299300pub struct RawInvoice {
300301 /// human readable part
301302 pub hrp : RawHrp ,
@@ -307,7 +308,7 @@ pub struct RawInvoice {
307308/// Data of the [`RawInvoice`] that is encoded in the human readable part.
308309///
309310/// This is not exported to bindings users as we don't yet support `Option<Enum>`
310- #[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
311+ #[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
311312pub struct RawHrp {
312313 /// The currency deferred from the 3rd and 4th character of the bech32 transaction
313314 pub currency : Currency ,
@@ -320,7 +321,7 @@ pub struct RawHrp {
320321}
321322
322323/// Data of the [`RawInvoice`] that is encoded in the data part
323- #[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
324+ #[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
324325pub struct RawDataPart {
325326 /// generation time of the invoice
326327 pub timestamp : PositiveTimestamp ,
@@ -335,11 +336,11 @@ pub struct RawDataPart {
335336///
336337/// The Unix timestamp representing the stored time has to be positive and no greater than
337338/// [`MAX_TIMESTAMP`].
338- #[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
339+ #[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
339340pub struct PositiveTimestamp ( Duration ) ;
340341
341342/// SI prefixes for the human readable part
342- #[ derive( Eq , PartialEq , Debug , Clone , Copy , Hash ) ]
343+ #[ derive( Eq , PartialEq , Debug , Clone , Copy , Hash , Ord , PartialOrd ) ]
343344pub enum SiPrefix {
344345 /// 10^-3
345346 Milli ,
@@ -376,7 +377,7 @@ impl SiPrefix {
376377}
377378
378379/// Enum representing the crypto currencies (or networks) supported by this library
379- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
380+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
380381pub enum Currency {
381382 /// Bitcoin mainnet
382383 Bitcoin ,
@@ -420,7 +421,7 @@ impl From<Currency> for Network {
420421/// Tagged field which may have an unknown tag
421422///
422423/// This is not exported to bindings users as we don't currently support TaggedField
423- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
424+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
424425pub enum RawTaggedField {
425426 /// Parsed tagged field with known tag
426427 KnownSemantics ( TaggedField ) ,
@@ -435,7 +436,7 @@ pub enum RawTaggedField {
435436/// This is not exported to bindings users as we don't yet support enum variants with the same name the struct contained
436437/// in the variant.
437438#[ allow( missing_docs) ]
438- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
439+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
439440pub enum TaggedField {
440441 PaymentHash ( Sha256 ) ,
441442 Description ( Description ) ,
@@ -451,7 +452,7 @@ pub enum TaggedField {
451452}
452453
453454/// SHA-256 hash
454- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
455+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
455456pub struct Sha256 ( /// This is not exported to bindings users as the native hash types are not currently mapped
456457 pub sha256:: Hash ) ;
457458
@@ -468,25 +469,25 @@ impl Sha256 {
468469///
469470/// # Invariants
470471/// The description can be at most 639 __bytes__ long
471- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
472+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
472473pub struct Description ( String ) ;
473474
474475/// Payee public key
475- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
476+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
476477pub struct PayeePubKey ( pub PublicKey ) ;
477478
478479/// Positive duration that defines when (relatively to the timestamp) in the future the invoice
479480/// expires
480- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
481+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
481482pub struct ExpiryTime ( Duration ) ;
482483
483484/// `min_final_cltv_expiry_delta` to use for the last HTLC in the route
484- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
485+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
485486pub struct MinFinalCltvExpiryDelta ( pub u64 ) ;
486487
487488/// Fallback address in case no LN payment is possible
488489#[ allow( missing_docs) ]
489- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
490+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
490491pub enum Fallback {
491492 SegWitProgram {
492493 version : WitnessVersion ,
@@ -500,12 +501,24 @@ pub enum Fallback {
500501#[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
501502pub struct InvoiceSignature ( pub RecoverableSignature ) ;
502503
504+ impl PartialOrd for InvoiceSignature {
505+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
506+ self . 0 . serialize_compact ( ) . 1 . partial_cmp ( & other. 0 . serialize_compact ( ) . 1 )
507+ }
508+ }
509+
510+ impl Ord for InvoiceSignature {
511+ fn cmp ( & self , other : & Self ) -> Ordering {
512+ self . 0 . serialize_compact ( ) . 1 . cmp ( & other. 0 . serialize_compact ( ) . 1 )
513+ }
514+ }
515+
503516/// Private routing information
504517///
505518/// # Invariants
506519/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
507520///
508- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
521+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
509522pub struct PrivateRoute ( RouteHint ) ;
510523
511524/// Tag constants as specified in BOLT11
0 commit comments