@@ -61,6 +61,7 @@ use secp256k1::PublicKey;
61
61
use secp256k1:: { Message , Secp256k1 } ;
62
62
use secp256k1:: ecdsa:: RecoverableSignature ;
63
63
64
+ use core:: cmp:: Ordering ;
64
65
use core:: fmt:: { Display , Formatter , self } ;
65
66
use core:: iter:: FilterMap ;
66
67
use core:: num:: ParseIntError ;
@@ -248,7 +249,7 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
248
249
/// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
249
250
///
250
251
/// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
251
- #[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
252
+ #[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
252
253
pub struct Invoice {
253
254
signed_invoice : SignedRawInvoice ,
254
255
}
@@ -258,7 +259,7 @@ pub struct Invoice {
258
259
///
259
260
/// This is not exported to bindings users as we don't have a good way to map the reference lifetimes making this
260
261
/// practically impossible to use safely in languages like C.
261
- #[ derive( Eq , PartialEq , Debug , Clone ) ]
262
+ #[ derive( Eq , PartialEq , Debug , Clone , Ord , PartialOrd ) ]
262
263
pub enum InvoiceDescription < ' f > {
263
264
/// Reference to the directly supplied description in the invoice
264
265
Direct ( & ' f Description ) ,
@@ -272,7 +273,7 @@ pub enum InvoiceDescription<'f> {
272
273
///
273
274
/// # Invariants
274
275
/// 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 ) ]
276
277
pub struct SignedRawInvoice {
277
278
/// The rawInvoice that the signature belongs to
278
279
raw_invoice : RawInvoice ,
@@ -295,7 +296,7 @@ pub struct SignedRawInvoice {
295
296
/// Decoding and encoding should not lead to information loss but may lead to different hashes.
296
297
///
297
298
/// 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 ) ]
299
300
pub struct RawInvoice {
300
301
/// human readable part
301
302
pub hrp : RawHrp ,
@@ -307,7 +308,7 @@ pub struct RawInvoice {
307
308
/// Data of the [`RawInvoice`] that is encoded in the human readable part.
308
309
///
309
310
/// 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 ) ]
311
312
pub struct RawHrp {
312
313
/// The currency deferred from the 3rd and 4th character of the bech32 transaction
313
314
pub currency : Currency ,
@@ -320,7 +321,7 @@ pub struct RawHrp {
320
321
}
321
322
322
323
/// 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 ) ]
324
325
pub struct RawDataPart {
325
326
/// generation time of the invoice
326
327
pub timestamp : PositiveTimestamp ,
@@ -335,11 +336,11 @@ pub struct RawDataPart {
335
336
///
336
337
/// The Unix timestamp representing the stored time has to be positive and no greater than
337
338
/// [`MAX_TIMESTAMP`].
338
- #[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
339
+ #[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
339
340
pub struct PositiveTimestamp ( Duration ) ;
340
341
341
342
/// 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 ) ]
343
344
pub enum SiPrefix {
344
345
/// 10^-3
345
346
Milli ,
@@ -376,7 +377,7 @@ impl SiPrefix {
376
377
}
377
378
378
379
/// 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 ) ]
380
381
pub enum Currency {
381
382
/// Bitcoin mainnet
382
383
Bitcoin ,
@@ -420,7 +421,7 @@ impl From<Currency> for Network {
420
421
/// Tagged field which may have an unknown tag
421
422
///
422
423
/// 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 ) ]
424
425
pub enum RawTaggedField {
425
426
/// Parsed tagged field with known tag
426
427
KnownSemantics ( TaggedField ) ,
@@ -435,7 +436,7 @@ pub enum RawTaggedField {
435
436
/// This is not exported to bindings users as we don't yet support enum variants with the same name the struct contained
436
437
/// in the variant.
437
438
#[ allow( missing_docs) ]
438
- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
439
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
439
440
pub enum TaggedField {
440
441
PaymentHash ( Sha256 ) ,
441
442
Description ( Description ) ,
@@ -451,7 +452,7 @@ pub enum TaggedField {
451
452
}
452
453
453
454
/// SHA-256 hash
454
- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
455
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
455
456
pub struct Sha256 ( /// This is not exported to bindings users as the native hash types are not currently mapped
456
457
pub sha256:: Hash ) ;
457
458
@@ -468,25 +469,25 @@ impl Sha256 {
468
469
///
469
470
/// # Invariants
470
471
/// 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 ) ]
472
473
pub struct Description ( String ) ;
473
474
474
475
/// Payee public key
475
- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
476
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
476
477
pub struct PayeePubKey ( pub PublicKey ) ;
477
478
478
479
/// Positive duration that defines when (relatively to the timestamp) in the future the invoice
479
480
/// expires
480
- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
481
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
481
482
pub struct ExpiryTime ( Duration ) ;
482
483
483
484
/// `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 ) ]
485
486
pub struct MinFinalCltvExpiryDelta ( pub u64 ) ;
486
487
487
488
/// Fallback address in case no LN payment is possible
488
489
#[ allow( missing_docs) ]
489
- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
490
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
490
491
pub enum Fallback {
491
492
SegWitProgram {
492
493
version : WitnessVersion ,
@@ -500,12 +501,24 @@ pub enum Fallback {
500
501
#[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
501
502
pub struct InvoiceSignature ( pub RecoverableSignature ) ;
502
503
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
+
503
516
/// Private routing information
504
517
///
505
518
/// # Invariants
506
519
/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
507
520
///
508
- #[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
521
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
509
522
pub struct PrivateRoute ( RouteHint ) ;
510
523
511
524
/// Tag constants as specified in BOLT11
0 commit comments