@@ -21,6 +21,7 @@ use crate::utils::*;
2121#[ cfg( feature = "redb" ) ]
2222use bdk_redb:: Store as RedbStore ;
2323use bdk_wallet:: bip39:: { Language , Mnemonic } ;
24+ use bdk_wallet:: bitcoin:: ScriptBuf ;
2425use bdk_wallet:: bitcoin:: base64:: Engine ;
2526use bdk_wallet:: bitcoin:: base64:: prelude:: BASE64_STANDARD ;
2627use bdk_wallet:: bitcoin:: {
@@ -335,7 +336,7 @@ pub async fn handle_offline_wallet_subcommand(
335336
336337 #[ cfg( feature = "dns_payment" ) ]
337338 ResolveDnsRecipient { hrn, amount } => {
338- let resolved = resolve_dns_recipient ( & hrn, Amount :: from_sat ( amount) , Network :: Bitcoin )
339+ let resolved = resolve_dns_recipient ( & hrn, Amount :: from_sat ( amount) , wallet . network ( ) )
339340 . await
340341 . map_err ( |e| Error :: Generic ( format ! ( "{:?}" , e) ) ) ?;
341342
@@ -349,6 +350,8 @@ pub async fn handle_offline_wallet_subcommand(
349350
350351 CreateTx {
351352 recipients,
353+ #[ cfg( feature = "dns_payment" ) ]
354+ dns_recipients,
352355 send_all,
353356 enable_rbf,
354357 offline_signer,
@@ -365,10 +368,37 @@ pub async fn handle_offline_wallet_subcommand(
365368 if send_all {
366369 tx_builder. drain_wallet ( ) . drain_to ( recipients[ 0 ] . 0 . clone ( ) ) ;
367370 } else {
368- let recipients = recipients
371+
372+ #[ allow( unused_mut) ]
373+ let mut recipients: Vec < ( ScriptBuf , Amount ) > = recipients
369374 . into_iter ( )
370375 . map ( |( script, amount) | ( script, Amount :: from_sat ( amount) ) )
371376 . collect ( ) ;
377+
378+ #[ cfg( feature = "dns_payment" ) ]
379+ if let Some ( recip) = dns_recipients {
380+ let parsed_recip = parse_dns_recipients ( & recip)
381+ . await
382+ . map_err ( |pe| Error :: Generic ( format ! ( "Resolution failed: {pe}" ) ) ) ?;
383+
384+ // Validates if the amount the user wants to send is in the range of what the payment instructions returned
385+ parsed_recip. iter ( ) . try_for_each ( |( _, r) | {
386+ let amount = r. amount . to_sat ( ) ;
387+ if r. min_amount . map_or ( false , |min| amount < min. to_sat ( ) ) {
388+ return Err ( Error :: Generic ( "Amount lesser than min" . to_string ( ) ) ) ;
389+ }
390+ if r. max_amount . map_or ( false , |max| amount > max. to_sat ( ) ) {
391+ return Err ( Error :: Generic ( "Amount greater than max" . to_string ( ) ) ) ;
392+ }
393+ Ok ( ( ) )
394+ } ) ?;
395+
396+ let mut vec_recip = parsed_recip
397+ . iter ( )
398+ . map ( |recip| ( recip. 1 . address . script_pubkey ( ) , recip. 1 . amount ) )
399+ . collect :: < Vec < _ > > ( ) ;
400+ recipients. append ( & mut vec_recip) ;
401+ }
372402 tx_builder. set_recipients ( recipients) ;
373403 }
374404
0 commit comments