projects
/
rust-lightning
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
818dbdf
)
Impl PartialOrd and Ord for Invoice
author
benthecarman
<benthecarman@live.com>
Tue, 9 May 2023 00:02:05 +0000
(19:02 -0500)
committer
benthecarman
<benthecarman@live.com>
Tue, 9 May 2023 17:39:17 +0000
(12:39 -0500)
lightning-invoice/src/lib.rs
patch
|
blob
|
history
lightning/src/ln/features.rs
patch
|
blob
|
history
lightning/src/ln/mod.rs
patch
|
blob
|
history
lightning/src/routing/gossip.rs
patch
|
blob
|
history
lightning/src/routing/router.rs
patch
|
blob
|
history
diff --git
a/lightning-invoice/src/lib.rs
b/lightning-invoice/src/lib.rs
index f53c8953b47c66b9344d86a928d9e834790989f7..8ccd9d979ab139899731d3724566b0b12e27069d 100644
(file)
--- a/
lightning-invoice/src/lib.rs
+++ b/
lightning-invoice/src/lib.rs
@@
-61,6
+61,7
@@
use secp256k1::PublicKey;
use secp256k1::{Message, Secp256k1};
use secp256k1::ecdsa::RecoverableSignature;
use secp256k1::{Message, Secp256k1};
use secp256k1::ecdsa::RecoverableSignature;
+use core::cmp::Ordering;
use core::fmt::{Display, Formatter, self};
use core::iter::FilterMap;
use core::num::ParseIntError;
use core::fmt::{Display, Formatter, self};
use core::iter::FilterMap;
use core::num::ParseIntError;
@@
-248,7
+249,7
@@
pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
/// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
///
/// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
/// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
///
/// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
-#[derive(Eq, PartialEq, Debug, Clone, Hash)]
+#[derive(Eq, PartialEq, Debug, Clone, Hash
, Ord, PartialOrd
)]
pub struct Invoice {
signed_invoice: SignedRawInvoice,
}
pub struct Invoice {
signed_invoice: SignedRawInvoice,
}
@@
-258,7
+259,7
@@
pub struct Invoice {
///
/// This is not exported to bindings users as we don't have a good way to map the reference lifetimes making this
/// practically impossible to use safely in languages like C.
///
/// This is not exported to bindings users as we don't have a good way to map the reference lifetimes making this
/// practically impossible to use safely in languages like C.
-#[derive(Eq, PartialEq, Debug, Clone)]
+#[derive(Eq, PartialEq, Debug, Clone
, Ord, PartialOrd
)]
pub enum InvoiceDescription<'f> {
/// Reference to the directly supplied description in the invoice
Direct(&'f Description),
pub enum InvoiceDescription<'f> {
/// Reference to the directly supplied description in the invoice
Direct(&'f Description),
@@
-272,7
+273,7
@@
pub enum InvoiceDescription<'f> {
///
/// # Invariants
/// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`].
///
/// # Invariants
/// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`].
-#[derive(Eq, PartialEq, Debug, Clone, Hash)]
+#[derive(Eq, PartialEq, Debug, Clone, Hash
, Ord, PartialOrd
)]
pub struct SignedRawInvoice {
/// The rawInvoice that the signature belongs to
raw_invoice: RawInvoice,
pub struct SignedRawInvoice {
/// The rawInvoice that the signature belongs to
raw_invoice: RawInvoice,
@@
-295,7
+296,7
@@
pub struct SignedRawInvoice {
/// Decoding and encoding should not lead to information loss but may lead to different hashes.
///
/// For methods without docs see the corresponding methods in [`Invoice`].
/// Decoding and encoding should not lead to information loss but may lead to different hashes.
///
/// For methods without docs see the corresponding methods in [`Invoice`].
-#[derive(Eq, PartialEq, Debug, Clone, Hash)]
+#[derive(Eq, PartialEq, Debug, Clone, Hash
, Ord, PartialOrd
)]
pub struct RawInvoice {
/// human readable part
pub hrp: RawHrp,
pub struct RawInvoice {
/// human readable part
pub hrp: RawHrp,
@@
-307,7
+308,7
@@
pub struct RawInvoice {
/// Data of the [`RawInvoice`] that is encoded in the human readable part.
///
/// This is not exported to bindings users as we don't yet support `Option<Enum>`
/// Data of the [`RawInvoice`] that is encoded in the human readable part.
///
/// This is not exported to bindings users as we don't yet support `Option<Enum>`
-#[derive(Eq, PartialEq, Debug, Clone, Hash)]
+#[derive(Eq, PartialEq, Debug, Clone, Hash
, Ord, PartialOrd
)]
pub struct RawHrp {
/// The currency deferred from the 3rd and 4th character of the bech32 transaction
pub currency: Currency,
pub struct RawHrp {
/// The currency deferred from the 3rd and 4th character of the bech32 transaction
pub currency: Currency,
@@
-320,7
+321,7
@@
pub struct RawHrp {
}
/// Data of the [`RawInvoice`] that is encoded in the data part
}
/// Data of the [`RawInvoice`] that is encoded in the data part
-#[derive(Eq, PartialEq, Debug, Clone, Hash)]
+#[derive(Eq, PartialEq, Debug, Clone, Hash
, Ord, PartialOrd
)]
pub struct RawDataPart {
/// generation time of the invoice
pub timestamp: PositiveTimestamp,
pub struct RawDataPart {
/// generation time of the invoice
pub timestamp: PositiveTimestamp,
@@
-335,11
+336,11
@@
pub struct RawDataPart {
///
/// The Unix timestamp representing the stored time has to be positive and no greater than
/// [`MAX_TIMESTAMP`].
///
/// The Unix timestamp representing the stored time has to be positive and no greater than
/// [`MAX_TIMESTAMP`].
-#[derive(Eq, PartialEq, Debug, Clone, Hash)]
+#[derive(Eq, PartialEq, Debug, Clone, Hash
, Ord, PartialOrd
)]
pub struct PositiveTimestamp(Duration);
/// SI prefixes for the human readable part
pub struct PositiveTimestamp(Duration);
/// SI prefixes for the human readable part
-#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
+#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash
, Ord, PartialOrd
)]
pub enum SiPrefix {
/// 10^-3
Milli,
pub enum SiPrefix {
/// 10^-3
Milli,
@@
-376,7
+377,7
@@
impl SiPrefix {
}
/// Enum representing the crypto currencies (or networks) supported by this library
}
/// Enum representing the crypto currencies (or networks) supported by this library
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub enum Currency {
/// Bitcoin mainnet
Bitcoin,
pub enum Currency {
/// Bitcoin mainnet
Bitcoin,
@@
-420,7
+421,7
@@
impl From<Currency> for Network {
/// Tagged field which may have an unknown tag
///
/// This is not exported to bindings users as we don't currently support TaggedField
/// Tagged field which may have an unknown tag
///
/// This is not exported to bindings users as we don't currently support TaggedField
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub enum RawTaggedField {
/// Parsed tagged field with known tag
KnownSemantics(TaggedField),
pub enum RawTaggedField {
/// Parsed tagged field with known tag
KnownSemantics(TaggedField),
@@
-435,7
+436,7
@@
pub enum RawTaggedField {
/// This is not exported to bindings users as we don't yet support enum variants with the same name the struct contained
/// in the variant.
#[allow(missing_docs)]
/// This is not exported to bindings users as we don't yet support enum variants with the same name the struct contained
/// in the variant.
#[allow(missing_docs)]
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub enum TaggedField {
PaymentHash(Sha256),
Description(Description),
pub enum TaggedField {
PaymentHash(Sha256),
Description(Description),
@@
-451,7
+452,7
@@
pub enum TaggedField {
}
/// SHA-256 hash
}
/// SHA-256 hash
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub struct Sha256(/// This is not exported to bindings users as the native hash types are not currently mapped
pub sha256::Hash);
pub struct Sha256(/// This is not exported to bindings users as the native hash types are not currently mapped
pub sha256::Hash);
@@
-468,25
+469,25
@@
impl Sha256 {
///
/// # Invariants
/// The description can be at most 639 __bytes__ long
///
/// # Invariants
/// The description can be at most 639 __bytes__ long
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub struct Description(String);
/// Payee public key
pub struct Description(String);
/// Payee public key
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub struct PayeePubKey(pub PublicKey);
/// Positive duration that defines when (relatively to the timestamp) in the future the invoice
/// expires
pub struct PayeePubKey(pub PublicKey);
/// Positive duration that defines when (relatively to the timestamp) in the future the invoice
/// expires
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub struct ExpiryTime(Duration);
/// `min_final_cltv_expiry_delta` to use for the last HTLC in the route
pub struct ExpiryTime(Duration);
/// `min_final_cltv_expiry_delta` to use for the last HTLC in the route
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub struct MinFinalCltvExpiryDelta(pub u64);
/// Fallback address in case no LN payment is possible
#[allow(missing_docs)]
pub struct MinFinalCltvExpiryDelta(pub u64);
/// Fallback address in case no LN payment is possible
#[allow(missing_docs)]
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub enum Fallback {
SegWitProgram {
version: WitnessVersion,
pub enum Fallback {
SegWitProgram {
version: WitnessVersion,
@@
-500,12
+501,24
@@
pub enum Fallback {
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
pub struct InvoiceSignature(pub RecoverableSignature);
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
pub struct InvoiceSignature(pub RecoverableSignature);
+impl PartialOrd for InvoiceSignature {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ self.0.serialize_compact().1.partial_cmp(&other.0.serialize_compact().1)
+ }
+}
+
+impl Ord for InvoiceSignature {
+ fn cmp(&self, other: &Self) -> Ordering {
+ self.0.serialize_compact().1.cmp(&other.0.serialize_compact().1)
+ }
+}
+
/// Private routing information
///
/// # Invariants
/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
///
/// Private routing information
///
/// # Invariants
/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
///
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub struct PrivateRoute(RouteHint);
/// Tag constants as specified in BOLT11
pub struct PrivateRoute(RouteHint);
/// Tag constants as specified in BOLT11
diff --git
a/lightning/src/ln/features.rs
b/lightning/src/ln/features.rs
index 8ccbf4166bbe71294a64309ed4832b9364845fa9..9997a1ec8d08caf27e26c8f2af0d930722cbe04a 100644
(file)
--- a/
lightning/src/ln/features.rs
+++ b/
lightning/src/ln/features.rs
@@
-451,6
+451,16
@@
impl<T: sealed::Context> PartialEq for Features<T> {
self.flags.eq(&o.flags)
}
}
self.flags.eq(&o.flags)
}
}
+impl<T: sealed::Context> PartialOrd for Features<T> {
+ fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
+ self.flags.partial_cmp(&other.flags)
+ }
+}
+impl<T: sealed::Context + Eq> Ord for Features<T> {
+ fn cmp(&self, other: &Self) -> cmp::Ordering {
+ self.flags.cmp(&other.flags)
+ }
+}
impl<T: sealed::Context> fmt::Debug for Features<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.flags.fmt(fmt)
impl<T: sealed::Context> fmt::Debug for Features<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.flags.fmt(fmt)
diff --git
a/lightning/src/ln/mod.rs
b/lightning/src/ln/mod.rs
index 3a0efd38690946cd5a7f48da324449d52f13fe2c..92edb061165b04a9fe611c957dfdf43ada6dff1b 100644
(file)
--- a/
lightning/src/ln/mod.rs
+++ b/
lightning/src/ln/mod.rs
@@
-72,19
+72,17
@@
pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
/// payment_hash type, use to cross-lock hop
///
/// This is not exported to bindings users as we just use [u8; 32] directly
/// payment_hash type, use to cross-lock hop
///
/// This is not exported to bindings users as we just use [u8; 32] directly
-#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
-#[cfg_attr(test, derive(PartialOrd, Ord))]
+#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
pub struct PaymentHash(pub [u8; 32]);
/// payment_preimage type, use to route payment between hop
///
/// This is not exported to bindings users as we just use [u8; 32] directly
pub struct PaymentHash(pub [u8; 32]);
/// payment_preimage type, use to route payment between hop
///
/// This is not exported to bindings users as we just use [u8; 32] directly
-#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
-#[cfg_attr(test, derive(PartialOrd, Ord))]
+#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
pub struct PaymentPreimage(pub [u8; 32]);
/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
///
/// This is not exported to bindings users as we just use [u8; 32] directly
pub struct PaymentPreimage(pub [u8; 32]);
/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
///
/// This is not exported to bindings users as we just use [u8; 32] directly
-#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
+#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug
, Ord, PartialOrd
)]
pub struct PaymentSecret(pub [u8; 32]);
use crate::prelude::*;
pub struct PaymentSecret(pub [u8; 32]);
use crate::prelude::*;
diff --git
a/lightning/src/routing/gossip.rs
b/lightning/src/routing/gossip.rs
index 90ead987e7c99c4c8079f57a4c9f91ea4485fb64..c5c08cf40321185a864aee4e814d39cc62f91abd 100644
(file)
--- a/
lightning/src/routing/gossip.rs
+++ b/
lightning/src/routing/gossip.rs
@@
-1056,7
+1056,7
@@
impl EffectiveCapacity {
}
/// Fees for routing via a given channel or a node
}
/// Fees for routing via a given channel or a node
-#[derive(Eq, PartialEq, Copy, Clone, Debug, Hash)]
+#[derive(Eq, PartialEq, Copy, Clone, Debug, Hash
, Ord, PartialOrd
)]
pub struct RoutingFees {
/// Flat routing fee in millisatoshis.
pub base_msat: u32,
pub struct RoutingFees {
/// Flat routing fee in millisatoshis.
pub base_msat: u32,
diff --git
a/lightning/src/routing/router.rs
b/lightning/src/routing/router.rs
index d1d0296b501bafffba25e3eb124a07b08ef5ebf5..1031bc939009d40e4e95e78c470721cf93688ae6 100644
(file)
--- a/
lightning/src/routing/router.rs
+++ b/
lightning/src/routing/router.rs
@@
-684,7
+684,7
@@
pub enum Hints {
}
/// A list of hops along a payment path terminating with a channel to the recipient.
}
/// A list of hops along a payment path terminating with a channel to the recipient.
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub struct RouteHint(pub Vec<RouteHintHop>);
impl Writeable for RouteHint {
pub struct RouteHint(pub Vec<RouteHintHop>);
impl Writeable for RouteHint {
@@
-709,7
+709,7
@@
impl Readable for RouteHint {
}
/// A channel descriptor for a hop along a payment path.
}
/// A channel descriptor for a hop along a payment path.
-#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq
, Ord, PartialOrd
)]
pub struct RouteHintHop {
/// The node_id of the non-target end of the route
pub src_node_id: PublicKey,
pub struct RouteHintHop {
/// The node_id of the non-target end of the route
pub src_node_id: PublicKey,