@@ -80,7 +80,7 @@ impl PaymentMethod {
8080 pub fn amount ( & self ) -> Option < Amount > {
8181 match self {
8282 PaymentMethod :: LightningBolt11 ( invoice) => {
83- invoice. amount_milli_satoshis ( ) . map ( |a| Amount :: from_milli_sats ( a ) )
83+ invoice. amount_milli_satoshis ( ) . map ( Amount :: from_milli_sats)
8484 } ,
8585 PaymentMethod :: LightningBolt12 ( offer) => match offer. amount ( ) {
8686 Some ( offer:: Amount :: Bitcoin { amount_msats } ) => {
@@ -220,7 +220,7 @@ impl PaymentInstructions {
220220 /// * the `description` field in a lightning BOLT 11 invoice
221221 /// * the `description` field in a lightning BOLT 12 offer
222222 pub fn recipient_description ( & self ) -> Option < & str > {
223- self . recipient_description . as_ref ( ) . map ( |x| & * * x )
223+ self . recipient_description . as_ref ( ) . map ( |d| d . as_str ( ) )
224224 }
225225
226226 /// Fetches the proof-of-payment callback URI.
@@ -230,7 +230,7 @@ impl PaymentInstructions {
230230 /// not-yet-defined for lightning BOLT 12 invoices) must be appended to this URI and the URI
231231 /// opened with the default system URI handler.
232232 pub fn pop_callback ( & self ) -> Option < & str > {
233- self . pop_callback . as_ref ( ) . map ( |x| & * * x )
233+ self . pop_callback . as_ref ( ) . map ( |c| c . as_str ( ) )
234234 }
235235
236236 /// Fetches the [`HumanReadableName`] which was resolved, if the resolved payment instructions
@@ -301,12 +301,12 @@ fn un_percent_encode(encoded: &str) -> Result<String, ParseError> {
301301 let err = "A Proof of Payment URI was not properly %-encoded in a BIP 321 bitcoin: URI" ;
302302 while let Some ( b) = iter. next ( ) {
303303 if b == b'%' {
304- let high = iter. next ( ) . ok_or ( ParseError :: InvalidInstructions ( err) ) ? as u8 ;
304+ let high = iter. next ( ) . ok_or ( ParseError :: InvalidInstructions ( err) ) ?;
305305 let low = iter. next ( ) . ok_or ( ParseError :: InvalidInstructions ( err) ) ?;
306- if high > b'9' || high < b'0' || low > b'9' || low < b'0' {
306+ if ! ( b'0' ..= b'9' ) . contains ( & high ) || ! ( b'0' ..= b'9' ) . contains ( & low) {
307307 return Err ( ParseError :: InvalidInstructions ( err) ) ;
308308 }
309- res. push ( ( high - b'0' ) << 4 | ( low - b'0' ) ) ;
309+ res. push ( ( ( high - b'0' ) << 4 ) | ( low - b'0' ) ) ;
310310 } else {
311311 res. push ( b) ;
312312 }
@@ -337,7 +337,7 @@ fn parse_resolved_instructions(
337337 let mut recipient_description = None ;
338338 let mut pop_callback = None ;
339339 if !body. is_empty ( ) {
340- let addr = Address :: from_str ( body) . map_err ( |e| ParseError :: InvalidOnChain ( e ) ) ?;
340+ let addr = Address :: from_str ( body) . map_err ( ParseError :: InvalidOnChain ) ?;
341341 let address = addr. require_network ( network) . map_err ( |_| ParseError :: WrongNetwork ) ?;
342342 methods. push ( PaymentMethod :: OnChain { amount : None , address } ) ;
343343 }
@@ -355,7 +355,7 @@ fn parse_resolved_instructions(
355355 return Err ( ParseError :: InvalidInstructions ( err) ) ;
356356 }
357357 let addr = Address :: from_str ( address_string)
358- . map_err ( |e| ParseError :: InvalidOnChain ( e ) ) ?;
358+ . map_err ( ParseError :: InvalidOnChain ) ?;
359359 let address =
360360 addr. require_network ( network) . map_err ( |_| ParseError :: WrongNetwork ) ?;
361361 methods. push ( PaymentMethod :: OnChain { amount : None , address } ) ;
@@ -368,7 +368,7 @@ fn parse_resolved_instructions(
368368 {
369369 if let Some ( invoice_string) = v {
370370 let invoice = Bolt11Invoice :: from_str ( invoice_string)
371- . map_err ( |e| ParseError :: InvalidBolt11 ( e ) ) ?;
371+ . map_err ( ParseError :: InvalidBolt11 ) ?;
372372 let ( desc, method_iter) = instructions_from_bolt11 ( invoice, network) ?;
373373 if let Some ( desc) = desc {
374374 recipient_description = Some ( desc) ;
@@ -538,7 +538,7 @@ fn parse_resolved_instructions(
538538 // Though there is no specification, lightning: URIs generally only include BOLT 11
539539 // invoices.
540540 let invoice = Bolt11Invoice :: from_str ( & instructions[ LN_URI_PFX_LEN ..] )
541- . map_err ( |e| ParseError :: InvalidBolt11 ( e ) ) ?;
541+ . map_err ( ParseError :: InvalidBolt11 ) ?;
542542 let ( recipient_description, method_iter) = instructions_from_bolt11 ( invoice, network) ?;
543543 Ok ( PaymentInstructions {
544544 recipient_description,
@@ -547,42 +547,40 @@ fn parse_resolved_instructions(
547547 hrn,
548548 hrn_proof,
549549 } )
550- } else {
551- if let Ok ( addr) = Address :: from_str ( instructions) {
552- let address = addr. require_network ( network) . map_err ( |_| ParseError :: WrongNetwork ) ?;
553- Ok ( PaymentInstructions {
554- recipient_description : None ,
555- methods : vec ! [ PaymentMethod :: OnChain { amount: None , address } ] ,
556- pop_callback : None ,
557- hrn,
558- hrn_proof,
559- } )
560- } else if let Ok ( invoice) = Bolt11Invoice :: from_str ( instructions) {
561- let ( recipient_description, method_iter) = instructions_from_bolt11 ( invoice, network) ?;
562- Ok ( PaymentInstructions {
563- recipient_description,
564- methods : method_iter. collect ( ) ,
565- pop_callback : None ,
566- hrn,
567- hrn_proof,
568- } )
569- } else if let Ok ( offer) = Offer :: from_str ( instructions) {
570- if !offer. supports_chain ( network. chain_hash ( ) ) {
571- return Err ( ParseError :: WrongNetwork ) ;
572- }
573- if let Some ( expiry) = offer. absolute_expiry ( ) {
574- check_expiry ( expiry) ?;
575- }
576- Ok ( PaymentInstructions {
577- recipient_description : offer. description ( ) . map ( |s| s. 0 . to_owned ( ) ) ,
578- methods : vec ! [ PaymentMethod :: LightningBolt12 ( offer) ] ,
579- pop_callback : None ,
580- hrn,
581- hrn_proof,
582- } )
583- } else {
584- Err ( ParseError :: UnknownPaymentInstructions )
550+ } else if let Ok ( addr) = Address :: from_str ( instructions) {
551+ let address = addr. require_network ( network) . map_err ( |_| ParseError :: WrongNetwork ) ?;
552+ Ok ( PaymentInstructions {
553+ recipient_description : None ,
554+ methods : vec ! [ PaymentMethod :: OnChain { amount: None , address } ] ,
555+ pop_callback : None ,
556+ hrn,
557+ hrn_proof,
558+ } )
559+ } else if let Ok ( invoice) = Bolt11Invoice :: from_str ( instructions) {
560+ let ( recipient_description, method_iter) = instructions_from_bolt11 ( invoice, network) ?;
561+ Ok ( PaymentInstructions {
562+ recipient_description,
563+ methods : method_iter. collect ( ) ,
564+ pop_callback : None ,
565+ hrn,
566+ hrn_proof,
567+ } )
568+ } else if let Ok ( offer) = Offer :: from_str ( instructions) {
569+ if !offer. supports_chain ( network. chain_hash ( ) ) {
570+ return Err ( ParseError :: WrongNetwork ) ;
571+ }
572+ if let Some ( expiry) = offer. absolute_expiry ( ) {
573+ check_expiry ( expiry) ?;
585574 }
575+ Ok ( PaymentInstructions {
576+ recipient_description : offer. description ( ) . map ( |s| s. 0 . to_owned ( ) ) ,
577+ methods : vec ! [ PaymentMethod :: LightningBolt12 ( offer) ] ,
578+ pop_callback : None ,
579+ hrn,
580+ hrn_proof,
581+ } )
582+ } else {
583+ Err ( ParseError :: UnknownPaymentInstructions )
586584 }
587585}
588586
0 commit comments