@@ -123,43 +123,43 @@ impl Offer {
123
123
self . signature . as_ref ( )
124
124
}
125
125
126
- fn to_tlv_stream ( & self ) -> OfferTlvStream {
127
- let ( currency, amount) = match self . amount . clone ( ) {
126
+ fn as_tlv_stream ( & self ) -> reference :: OfferTlvStream {
127
+ let ( currency, amount) = match & self . amount {
128
128
None => ( None , None ) ,
129
129
Some ( Amount :: Bitcoin { amount_msats } ) => (
130
- None , Some ( HighZeroBytesDroppedVarInt ( amount_msats) )
130
+ None , Some ( HighZeroBytesDroppedVarInt ( * amount_msats) )
131
131
) ,
132
132
Some ( Amount :: Currency { iso4217_code, amount } ) => (
133
- Some ( WithoutLength ( iso4217_code) ) , Some ( HighZeroBytesDroppedVarInt ( amount) )
133
+ Some ( WithoutLength ( iso4217_code) ) , Some ( HighZeroBytesDroppedVarInt ( * amount) )
134
134
) ,
135
135
} ;
136
136
137
- let ( paths, node_id) = match self . destination . clone ( ) {
137
+ let ( paths, node_id) = match & self . destination {
138
138
Destination :: NodeId ( node_id) => ( None , Some ( node_id) ) ,
139
139
Destination :: Paths ( paths) => ( Some ( WithoutLength ( paths) ) , None ) ,
140
140
} ;
141
141
142
- let ( send_invoice, refund_for) = match self . send_invoice . clone ( ) {
142
+ let ( send_invoice, refund_for) = match & self . send_invoice {
143
143
None => ( None , None ) ,
144
- Some ( SendInvoice { refund_for } ) => ( Some ( ( ) ) , refund_for) ,
144
+ Some ( SendInvoice { refund_for } ) => ( Some ( & ( ) ) , refund_for. as_ref ( ) ) ,
145
145
} ;
146
146
147
- OfferTlvStream {
148
- chains : self . chains . clone ( ) . map ( |chains| WithoutLength ( chains) ) ,
147
+ reference :: OfferTlvStream {
148
+ chains : self . chains . as_ref ( ) . map ( |chains| WithoutLength ( chains) ) ,
149
149
currency,
150
150
amount,
151
- description : Some ( WithoutLength ( self . description . clone ( ) ) ) ,
152
- features : self . features . clone ( ) ,
151
+ description : Some ( WithoutLength ( & self . description ) ) ,
152
+ features : self . features . as_ref ( ) ,
153
153
absolute_expiry : self . absolute_expiry . map ( |d| HighZeroBytesDroppedVarInt ( d. as_secs ( ) ) ) ,
154
154
paths,
155
- issuer : self . issuer . clone ( ) . map ( |issuer| WithoutLength ( issuer) ) ,
155
+ issuer : self . issuer . as_ref ( ) . map ( |issuer| WithoutLength ( issuer) ) ,
156
156
quantity_min : self . quantity_min . map ( |quantity| HighZeroBytesDroppedVarInt ( quantity) ) ,
157
157
quantity_max : self . quantity_max . map ( |quantity| HighZeroBytesDroppedVarInt ( quantity) ) ,
158
- recurrence : self . recurrence . clone ( ) ,
158
+ recurrence : self . recurrence . as_ref ( ) ,
159
159
node_id,
160
160
send_invoice,
161
161
refund_for,
162
- signature : self . signature ,
162
+ signature : self . signature . as_ref ( ) ,
163
163
}
164
164
}
165
165
}
@@ -208,43 +208,22 @@ pub struct SendInvoice {
208
208
refund_for : Option < PaymentHash > ,
209
209
}
210
210
211
- /// An `offer` TLV stream without any semantic checks, apart from any checks performed when parsing
212
- /// the underlying types.
213
- #[ derive( Debug ) ]
214
- struct OfferTlvStream {
215
- chains : Option < WithoutLength < Vec < BlockHash > > > ,
216
- currency : Option < WithoutLength < String > > ,
217
- amount : Option < HighZeroBytesDroppedVarInt < u64 > > ,
218
- description : Option < WithoutLength < String > > ,
219
- features : Option < OfferFeatures > ,
220
- absolute_expiry : Option < HighZeroBytesDroppedVarInt < u64 > > ,
221
- paths : Option < WithoutLength < Vec < BlindedPath > > > ,
222
- issuer : Option < WithoutLength < String > > ,
223
- quantity_min : Option < HighZeroBytesDroppedVarInt < u64 > > ,
224
- quantity_max : Option < HighZeroBytesDroppedVarInt < u64 > > ,
225
- recurrence : Option < Recurrence > ,
226
- node_id : Option < XOnlyPublicKey > ,
227
- send_invoice : Option < ( ) > ,
228
- refund_for : Option < PaymentHash > ,
229
- signature : Option < Signature > ,
230
- }
231
-
232
- impl_writeable_tlv_stream ! ( OfferTlvStream , {
233
- ( 2 , chains, option) ,
234
- ( 6 , currency, option) ,
235
- ( 8 , amount, option) ,
236
- ( 10 , description, option) ,
237
- ( 12 , features, option) ,
238
- ( 14 , absolute_expiry, option) ,
239
- ( 16 , paths, option) ,
240
- ( 20 , issuer, option) ,
241
- ( 22 , quantity_min, option) ,
242
- ( 24 , quantity_max, option) ,
243
- ( 26 , recurrence, option) ,
244
- ( 30 , node_id, option) ,
245
- ( 34 , refund_for, option) ,
246
- ( 54 , send_invoice, option) ,
247
- ( 240 , signature, option) ,
211
+ tlv_stream ! ( struct OfferTlvStream {
212
+ ( 2 , chains: Vec <BlockHash >) ,
213
+ ( 6 , currency: String ) ,
214
+ ( 8 , amount: u64 ) ,
215
+ ( 10 , description: String ) ,
216
+ ( 12 , features: OfferFeatures ) ,
217
+ ( 14 , absolute_expiry: u64 ) ,
218
+ ( 16 , paths: Vec <BlindedPath >) ,
219
+ ( 20 , issuer: String ) ,
220
+ ( 22 , quantity_min: u64 ) ,
221
+ ( 24 , quantity_max: u64 ) ,
222
+ ( 26 , recurrence: Recurrence ) ,
223
+ ( 30 , node_id: XOnlyPublicKey ) ,
224
+ ( 34 , refund_for: PaymentHash ) ,
225
+ ( 54 , send_invoice: Empty ) ,
226
+ ( 240 , signature: Signature ) ,
248
227
} ) ;
249
228
250
229
#[ derive( Clone , Debug ) ]
@@ -273,6 +252,8 @@ struct Recurrence {
273
252
274
253
impl_writeable ! ( Recurrence , { time_unit, period } ) ;
275
254
255
+ type Empty = ( ) ;
256
+
276
257
/// An offer parsed from a bech32-encoded string as a TLV stream and the corresponding bytes. The
277
258
/// latter is used for signature verification.
278
259
struct ParsedOffer ( OfferTlvStream , Vec < u8 > ) ;
@@ -477,16 +458,10 @@ impl FromStr for ParsedOffer {
477
458
}
478
459
479
460
impl core:: fmt:: Display for Offer {
480
- fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
481
- self . to_tlv_stream ( ) . fmt ( f)
482
- }
483
- }
484
-
485
- impl core:: fmt:: Display for OfferTlvStream {
486
461
fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
487
462
use util:: ser:: Writeable ;
488
463
let mut buffer = Vec :: new ( ) ;
489
- self . write ( & mut buffer) . unwrap ( ) ;
464
+ self . as_tlv_stream ( ) . write ( & mut buffer) . unwrap ( ) ;
490
465
491
466
use bitcoin:: bech32:: ToBase32 ;
492
467
let data = buffer. to_base32 ( ) ;
0 commit comments