Skip to content

Commit 52df102

Browse files
committed
Implement core::hash::Hash more incl invoice::RawTaggedField
1 parent 6a43294 commit 52df102

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

lightning-invoice/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl SiPrefix {
321321
}
322322

323323
/// Enum representing the crypto currencies (or networks) supported by this library
324-
#[derive(Eq, PartialEq, Debug, Clone)]
324+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
325325
pub enum Currency {
326326
/// Bitcoin mainnet
327327
Bitcoin,
@@ -342,7 +342,7 @@ pub enum Currency {
342342
/// Tagged field which may have an unknown tag
343343
///
344344
/// (C-not exported) as we don't currently support TaggedField
345-
#[derive(Eq, PartialEq, Debug, Clone)]
345+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
346346
pub enum RawTaggedField {
347347
/// Parsed tagged field with known tag
348348
KnownSemantics(TaggedField),
@@ -357,7 +357,7 @@ pub enum RawTaggedField {
357357
/// (C-not exported) As we don't yet support enum variants with the same name the struct contained
358358
/// in the variant.
359359
#[allow(missing_docs)]
360-
#[derive(Eq, PartialEq, Debug, Clone)]
360+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
361361
pub enum TaggedField {
362362
PaymentHash(Sha256),
363363
Description(Description),
@@ -372,18 +372,18 @@ pub enum TaggedField {
372372
}
373373

374374
/// SHA-256 hash
375-
#[derive(Eq, PartialEq, Debug, Clone)]
375+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
376376
pub struct Sha256(pub sha256::Hash);
377377

378378
/// Description string
379379
///
380380
/// # Invariants
381381
/// The description can be at most 639 __bytes__ long
382-
#[derive(Eq, PartialEq, Debug, Clone)]
382+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
383383
pub struct Description(String);
384384

385385
/// Payee public key
386-
#[derive(Eq, PartialEq, Debug, Clone)]
386+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
387387
pub struct PayeePubKey(pub PublicKey);
388388

389389
/// Positive duration that defines when (relatively to the timestamp) in the future the invoice
@@ -393,17 +393,17 @@ pub struct PayeePubKey(pub PublicKey);
393393
/// The number of seconds this expiry time represents has to be in the range
394394
/// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
395395
/// timestamp
396-
#[derive(Eq, PartialEq, Debug, Clone)]
396+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
397397
pub struct ExpiryTime(Duration);
398398

399399
/// `min_final_cltv_expiry` to use for the last HTLC in the route
400-
#[derive(Eq, PartialEq, Debug, Clone)]
400+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
401401
pub struct MinFinalCltvExpiry(pub u64);
402402

403403
// TODO: better types instead onf byte arrays
404404
/// Fallback address in case no LN payment is possible
405405
#[allow(missing_docs)]
406-
#[derive(Eq, PartialEq, Debug, Clone)]
406+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
407407
pub enum Fallback {
408408
SegWitProgram {
409409
version: u5,
@@ -414,15 +414,15 @@ pub enum Fallback {
414414
}
415415

416416
/// Recoverable signature
417-
#[derive(Eq, PartialEq, Debug, Clone)]
417+
#[derive(Clone, Debug, Eq, PartialEq)]
418418
pub struct InvoiceSignature(pub RecoverableSignature);
419419

420420
/// Private routing information
421421
///
422422
/// # Invariants
423423
/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
424424
///
425-
#[derive(Eq, PartialEq, Debug, Clone)]
425+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
426426
pub struct PrivateRoute(RouteHint);
427427

428428
/// Tag constants as specified in BOLT11

lightning/src/ln/features.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use io;
2626
use prelude::*;
2727
use core::{cmp, fmt};
28+
use core::hash::{Hash, Hasher};
2829
use core::marker::PhantomData;
2930

3031
use bitcoin::bech32;
@@ -362,6 +363,11 @@ impl<T: sealed::Context> Clone for Features<T> {
362363
}
363364
}
364365
}
366+
impl<T: sealed::Context> Hash for Features<T> {
367+
fn hash<H: Hasher>(&self, hasher: &mut H) {
368+
self.flags.hash(hasher);
369+
}
370+
}
365371
impl<T: sealed::Context> PartialEq for Features<T> {
366372
fn eq(&self, o: &Self) -> bool {
367373
self.flags.eq(&o.flags)

lightning/src/routing/network_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl_writeable_tlv_based!(ChannelInfo, {
533533

534534

535535
/// Fees for routing via a given channel or a node
536-
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
536+
#[derive(Eq, PartialEq, Copy, Clone, Debug, Hash)]
537537
pub struct RoutingFees {
538538
/// Flat routing fee in satoshis
539539
pub base_msat: u32,

lightning/src/routing/router.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use core::cmp;
2828
use core::ops::Deref;
2929

3030
/// A hop in a route
31-
#[derive(Clone, PartialEq)]
31+
#[derive(Clone, Hash, PartialEq, Eq)]
3232
pub struct RouteHop {
3333
/// The node_id of the node at this hop.
3434
pub pubkey: PublicKey,
@@ -60,7 +60,7 @@ impl_writeable_tlv_based!(RouteHop, {
6060

6161
/// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
6262
/// it can take multiple paths. Each path is composed of one or more hops through the network.
63-
#[derive(Clone, PartialEq)]
63+
#[derive(Clone, Hash, PartialEq, Eq)]
6464
pub struct Route {
6565
/// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
6666
/// last RouteHop in each path must be the same.
@@ -108,11 +108,11 @@ impl Readable for Route {
108108
}
109109

110110
/// A list of hops along a payment path terminating with a channel to the recipient.
111-
#[derive(Eq, PartialEq, Debug, Clone)]
111+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
112112
pub struct RouteHint(pub Vec<RouteHintHop>);
113113

114114
/// A channel descriptor for a hop along a payment path.
115-
#[derive(Eq, PartialEq, Debug, Clone)]
115+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
116116
pub struct RouteHintHop {
117117
/// The node_id of the non-target end of the route
118118
pub src_node_id: PublicKey,

0 commit comments

Comments
 (0)