@@ -36,7 +36,7 @@ impl<const N: usize> Base32Iterable for [u8; N] {
36
36
impl < const N : usize > Base32Len for [ u8 ; N ] {
37
37
/// Calculate the base32 serialized length
38
38
fn base32_len ( & self ) -> usize {
39
- bytes_size_to_base32_size ( N )
39
+ bytes_size_to_base32_size ( N )
40
40
}
41
41
}
42
42
@@ -154,10 +154,13 @@ impl Display for Bolt11Invoice {
154
154
impl Display for SignedRawBolt11Invoice {
155
155
fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
156
156
let hrp = self . raw_invoice . hrp . to_hrp ( ) ;
157
- for ch in
158
- self . raw_invoice . data . fe_iter ( )
157
+ for ch in self
158
+ . raw_invoice
159
+ . data
160
+ . fe_iter ( )
159
161
. chain ( self . signature . fe_iter ( ) )
160
- . with_checksum :: < bech32:: Bech32 > ( & hrp) . chars ( )
162
+ . with_checksum :: < bech32:: Bech32 > ( & hrp)
163
+ . chars ( )
161
164
{
162
165
write ! ( f, "{}" , ch) ?;
163
166
}
@@ -259,9 +262,7 @@ impl Base32Iterable for RawTaggedField {
259
262
// Annoyingly, when we move to explicit types, we will need an
260
263
// explicit enum holding the two iterator variants.
261
264
match * self {
262
- RawTaggedField :: UnknownSemantics ( ref content) => {
263
- Box :: new ( content. iter ( ) . copied ( ) )
264
- } ,
265
+ RawTaggedField :: UnknownSemantics ( ref content) => Box :: new ( content. iter ( ) . copied ( ) ) ,
265
266
RawTaggedField :: KnownSemantics ( ref tagged_field) => tagged_field. fe_iter ( ) ,
266
267
}
267
268
}
@@ -330,37 +331,44 @@ impl Base32Len for MinFinalCltvExpiryDelta {
330
331
impl Base32Iterable for Fallback {
331
332
fn fe_iter < ' s > ( & ' s self ) -> Box < dyn Iterator < Item = Fe32 > + ' s > {
332
333
Box :: new ( match * self {
333
- Fallback :: SegWitProgram { version : v, program : ref p} => {
334
+ Fallback :: SegWitProgram { version : v, program : ref p } => {
334
335
let v = Fe32 :: try_from ( v. to_num ( ) ) . expect ( "valid version" ) ;
335
336
core:: iter:: once ( v) . chain ( p[ ..] . fe_iter ( ) )
336
- }
337
+ } ,
337
338
Fallback :: PubKeyHash ( ref hash) => {
338
339
// 17 '3'
339
340
core:: iter:: once ( Fe32 :: _3) . chain ( hash[ ..] . fe_iter ( ) )
340
- }
341
+ } ,
341
342
Fallback :: ScriptHash ( ref hash) => {
342
343
// 18 'J'
343
344
core:: iter:: once ( Fe32 :: J ) . chain ( hash[ ..] . fe_iter ( ) )
344
- }
345
+ } ,
345
346
} )
346
347
}
347
348
}
348
349
349
350
impl Base32Len for Fallback {
350
351
fn base32_len ( & self ) -> usize {
351
352
match * self {
352
- Fallback :: SegWitProgram { program : ref p, ..} => {
353
+ Fallback :: SegWitProgram { program : ref p, .. } => {
353
354
bytes_size_to_base32_size ( p. len ( ) ) + 1
354
355
} ,
355
- Fallback :: PubKeyHash ( _) | Fallback :: ScriptHash ( _) => {
356
- 33
357
- } ,
356
+ Fallback :: PubKeyHash ( _) | Fallback :: ScriptHash ( _) => 33 ,
358
357
}
359
358
}
360
359
}
361
360
362
361
// Shorthand type
363
- type RouteHintHopIter = iter:: Chain < iter:: Chain < iter:: Chain < iter:: Chain < array:: IntoIter < u8 , 33 > , array:: IntoIter < u8 , 8 > > , array:: IntoIter < u8 , 4 > > , array:: IntoIter < u8 , 4 > > , array:: IntoIter < u8 , 2 > > ;
362
+ type RouteHintHopIter = iter:: Chain <
363
+ iter:: Chain <
364
+ iter:: Chain <
365
+ iter:: Chain < array:: IntoIter < u8 , 33 > , array:: IntoIter < u8 , 8 > > ,
366
+ array:: IntoIter < u8 , 4 > ,
367
+ > ,
368
+ array:: IntoIter < u8 , 4 > ,
369
+ > ,
370
+ array:: IntoIter < u8 , 2 > ,
371
+ > ;
364
372
365
373
impl Base32Iterable for PrivateRoute {
366
374
fn fe_iter < ' s > ( & ' s self ) -> Box < dyn Iterator < Item = Fe32 > + ' s > {
@@ -390,8 +398,11 @@ impl Base32Iterable for TaggedField {
390
398
fn fe_iter < ' s > ( & ' s self ) -> Box < dyn Iterator < Item = Fe32 > + ' s > {
391
399
/// Writes a tagged field: tag, length and data. `tag` should be in `0..32` otherwise the
392
400
/// function will panic.
393
- fn write_tagged_field < ' s , P > ( tag : u8 , payload : & ' s P ) -> TaggedFieldIter < Box < dyn Iterator < Item = Fe32 > + ' s > >
394
- where P : Base32Iterable + Base32Len + ?Sized
401
+ fn write_tagged_field < ' s , P > (
402
+ tag : u8 , payload : & ' s P ,
403
+ ) -> TaggedFieldIter < Box < dyn Iterator < Item = Fe32 > + ' s > >
404
+ where
405
+ P : Base32Iterable + Base32Len + ?Sized ,
395
406
{
396
407
let len = payload. base32_len ( ) ;
397
408
assert ! ( len < 1024 , "Every tagged field data can be at most 1023 bytes long." ) ;
@@ -400,7 +411,9 @@ impl Base32Iterable for TaggedField {
400
411
Fe32 :: try_from ( tag) . expect ( "invalid tag, not in 0..32" ) ,
401
412
Fe32 :: try_from ( ( len / 32 ) as u8 ) . expect ( "< 32" ) ,
402
413
Fe32 :: try_from ( ( len % 32 ) as u8 ) . expect ( "< 32" ) ,
403
- ] . into_iter ( ) . chain ( payload. fe_iter ( ) )
414
+ ]
415
+ . into_iter ( )
416
+ . chain ( payload. fe_iter ( ) )
404
417
}
405
418
406
419
// we will also need a giant enum for this
@@ -446,9 +459,10 @@ impl Base32Iterable for Bolt11InvoiceSignature {
446
459
fn fe_iter < ' s > ( & ' s self ) -> Box < dyn Iterator < Item = Fe32 > + ' s > {
447
460
let ( recovery_id, signature) = self . 0 . serialize_compact ( ) ;
448
461
Box :: new (
449
- signature. into_iter ( )
462
+ signature
463
+ . into_iter ( )
450
464
. chain ( core:: iter:: once ( recovery_id. to_i32 ( ) as u8 ) )
451
- . bytes_to_fes ( )
465
+ . bytes_to_fes ( ) ,
452
466
)
453
467
}
454
468
}
@@ -485,7 +499,11 @@ mod test {
485
499
use bech32:: Fe32 ;
486
500
487
501
let input: u64 = 33764 ;
488
- let expected_out = [ 1 , 0 , 31 , 4 ] . iter ( ) . copied ( ) . map ( |v| Fe32 :: try_from ( v) . expect ( "<= 31" ) ) . collect :: < Vec < Fe32 > > ( ) ;
502
+ let expected_out = [ 1 , 0 , 31 , 4 ]
503
+ . iter ( )
504
+ . copied ( )
505
+ . map ( |v| Fe32 :: try_from ( v) . expect ( "<= 31" ) )
506
+ . collect :: < Vec < Fe32 > > ( ) ;
489
507
490
508
assert_eq ! ( expected_out, encode_int_be_base32( input) ) ;
491
509
}
0 commit comments