Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit 30bc536

Browse files
committed
Consistently derive standard traits for all public structs
1 parent d2ec218 commit 30bc536

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/de.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl FromBase32 for Route {
568568
}
569569
}
570570

571-
#[derive(PartialEq, Debug)]
571+
#[derive(PartialEq, Debug, Clone)]
572572
pub enum ParseError {
573573
Bech32Error(bech32::Error),
574574
ParseAmountError(ParseIntError),
@@ -590,7 +590,7 @@ pub enum ParseError {
590590
Skip
591591
}
592592

593-
#[derive(PartialEq, Debug)]
593+
#[derive(PartialEq, Debug, Clone)]
594594
pub enum ParseOrSemanticError {
595595
ParseError(ParseError),
596596
SemanticError(::SemanticError),

src/lib.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub use de::{ParseError, ParseOrSemanticError};
5959
/// given field:
6060
/// * `D`: exactly one `Description` or `DescriptionHash`
6161
/// * `H`: exactly one `PaymentHash`
62+
#[derive(Eq, PartialEq, Debug, Clone)]
6263
pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool> {
6364
currency: Currency,
6465
amount: Option<u64>,
@@ -77,11 +78,12 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool> {
7778
/// 1. using `InvoiceBuilder`
7879
/// 2. using `Invoice::from_signed(SignedRawInvoice)`
7980
/// 3. using `str::parse::<Invoice>(&str)`
80-
#[derive(Eq, PartialEq, Debug)]
81+
#[derive(Eq, PartialEq, Debug, Clone)]
8182
pub struct Invoice {
8283
signed_invoice: SignedRawInvoice,
8384
}
8485

86+
#[derive(Eq, PartialEq, Debug, Clone)]
8587
pub enum InvoiceDescription<'f> {
8688
Direct(&'f Description),
8789
Hash(&'f Sha256)
@@ -92,7 +94,7 @@ pub enum InvoiceDescription<'f> {
9294
///
9395
/// # Invariants
9496
/// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
95-
#[derive(Eq, PartialEq, Debug)]
97+
#[derive(Eq, PartialEq, Debug, Clone)]
9698
pub struct SignedRawInvoice {
9799
/// The rawInvoice that the signature belongs to
98100
raw_invoice: RawInvoice,
@@ -113,7 +115,7 @@ pub struct SignedRawInvoice {
113115
/// Represents an syntactically correct Invoice for a payment on the lightning network,
114116
/// but without the signature information.
115117
/// De- and encoding should not lead to information loss but may lead to different hashes.
116-
#[derive(Eq, PartialEq, Debug)]
118+
#[derive(Eq, PartialEq, Debug, Clone)]
117119
pub struct RawInvoice {
118120
/// human readable part
119121
pub hrp: RawHrp,
@@ -123,7 +125,7 @@ pub struct RawInvoice {
123125
}
124126

125127
/// Data of the `RawInvoice` that is encoded in the human readable part
126-
#[derive(Eq, PartialEq, Debug)]
128+
#[derive(Eq, PartialEq, Debug, Clone)]
127129
pub struct RawHrp {
128130
/// The currency deferred from the 3rd and 4th character of the bech32 transaction
129131
pub currency: Currency,
@@ -136,7 +138,7 @@ pub struct RawHrp {
136138
}
137139

138140
/// Data of the `RawInvoice` that is encoded in the data part
139-
#[derive(Eq, PartialEq, Debug)]
141+
#[derive(Eq, PartialEq, Debug, Clone)]
140142
pub struct RawDataPart {
141143
// TODO: find better fitting type that only allows positive timestamps to avoid checks for negative timestamps when encoding
142144
/// generation time of the invoice as UNIX timestamp
@@ -187,7 +189,7 @@ pub enum Currency {
187189
}
188190

189191
/// Tagged field which may have an unknown tag
190-
#[derive(Eq, PartialEq, Debug)]
192+
#[derive(Eq, PartialEq, Debug, Clone)]
191193
pub enum RawTaggedField {
192194
/// Parsed tagged field with known tag
193195
KnownSemantics(TaggedField),
@@ -196,7 +198,7 @@ pub enum RawTaggedField {
196198
}
197199

198200
/// Tagged field with known tag
199-
#[derive(Eq, PartialEq, Debug)]
201+
#[derive(Eq, PartialEq, Debug, Clone)]
200202
pub enum TaggedField {
201203
PaymentHash(Sha256),
202204
Description(Description),
@@ -210,33 +212,33 @@ pub enum TaggedField {
210212

211213
// TODO: use struct from bitcoin_hashes
212214
/// SHA-256 hash
213-
#[derive(Eq, PartialEq, Debug)]
215+
#[derive(Eq, PartialEq, Debug, Clone)]
214216
pub struct Sha256(pub [u8; 32]);
215217

216218
/// Description string
217219
///
218220
/// # Invariants
219221
/// The description can be at most 639 __bytes__ long
220-
#[derive(Eq, PartialEq, Debug)]
222+
#[derive(Eq, PartialEq, Debug, Clone)]
221223
pub struct Description(String);
222224

223225
/// Payee public key
224-
#[derive(Eq, PartialEq, Debug)]
226+
#[derive(Eq, PartialEq, Debug, Clone)]
225227
pub struct PayeePubKey(pub PublicKey);
226228

227229
/// Positive duration that defines when (relatively to the timestamp) in the future the invoice expires
228-
#[derive(Eq, PartialEq, Debug)]
230+
#[derive(Eq, PartialEq, Debug, Clone)]
229231
pub struct ExpiryTime {
230232
pub seconds: u64
231233
}
232234

233235
/// `min_final_cltv_expiry` to use for the last HTLC in the route
234-
#[derive(Eq, PartialEq, Debug)]
236+
#[derive(Eq, PartialEq, Debug, Clone)]
235237
pub struct MinFinalCltvExpiry(pub u64);
236238

237239
// TODO: better types instead onf byte arrays
238240
/// Fallback address in case no LN payment is possible
239-
#[derive(Eq, PartialEq, Debug)]
241+
#[derive(Eq, PartialEq, Debug, Clone)]
240242
pub enum Fallback {
241243
SegWitProgram {
242244
version: u5,
@@ -247,18 +249,18 @@ pub enum Fallback {
247249
}
248250

249251
/// Recoverable signature
250-
#[derive(Eq, PartialEq, Debug)]
252+
#[derive(Eq, PartialEq, Debug, Clone)]
251253
pub struct Signature(pub RecoverableSignature);
252254

253255
/// Private routing information
254256
///
255257
/// # Invariants
256258
/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
257259
///
258-
#[derive(Eq, PartialEq, Debug)]
260+
#[derive(Eq, PartialEq, Debug, Clone)]
259261
pub struct Route(Vec<RouteHop>);
260262

261-
#[derive(Eq, PartialEq, Debug)]
263+
#[derive(Eq, PartialEq, Debug, Clone)]
262264
pub struct RouteHop {
263265
pub pubkey: PublicKey,
264266
pub short_channel_id: [u8; 8],
@@ -930,7 +932,7 @@ impl Deref for SignedRawInvoice {
930932
}
931933

932934
/// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
933-
#[derive(Eq, PartialEq, Debug)]
935+
#[derive(Eq, PartialEq, Debug, Clone)]
934936
pub enum CreationError {
935937
/// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
936938
DescriptionTooLong,
@@ -941,7 +943,7 @@ pub enum CreationError {
941943

942944
/// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
943945
/// requirements sections in BOLT #11
944-
#[derive(Eq, PartialEq, Debug)]
946+
#[derive(Eq, PartialEq, Debug, Clone)]
945947
pub enum SemanticError {
946948
NoPaymentHash,
947949
MultiplePaymentHashes,
@@ -955,6 +957,7 @@ pub enum SemanticError {
955957

956958
/// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
957959
/// may occur.
960+
#[derive(Eq, PartialEq, Debug, Clone)]
958961
pub enum SignOrCreationError<S> {
959962
SignError(S),
960963
CreationError(CreationError),

0 commit comments

Comments
 (0)