@@ -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:: {
@@ -332,10 +333,10 @@ pub async fn handle_offline_wallet_subcommand(
332333 ) ?)
333334 }
334335 }
335-
336+
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,36 @@ 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+ #[ allow( unused_mut) ]
372+ let mut recipients: Vec < ( ScriptBuf , Amount ) > = recipients
369373 . into_iter ( )
370374 . map ( |( script, amount) | ( script, Amount :: from_sat ( amount) ) )
371375 . collect ( ) ;
376+
377+ #[ cfg( feature = "dns_payment" ) ]
378+ if let Some ( recip) = dns_recipients {
379+ let parsed_recip = parse_dns_recipients ( & recip)
380+ . await
381+ . map_err ( |pe| Error :: Generic ( format ! ( "Resolution failed: {pe}" ) ) ) ?;
382+
383+ // Validates if the amount the user wants to send is in the range of what the payment instructions returned
384+ parsed_recip. iter ( ) . try_for_each ( |( _, r) | {
385+ let amount = r. amount . to_sat ( ) ;
386+ if r. min_amount . map_or ( false , |min| amount < min. to_sat ( ) ) {
387+ return Err ( Error :: Generic ( "Amount lesser than min" . to_string ( ) ) ) ;
388+ }
389+ if r. max_amount . map_or ( false , |max| amount > max. to_sat ( ) ) {
390+ return Err ( Error :: Generic ( "Amount greater than max" . to_string ( ) ) ) ;
391+ }
392+ Ok ( ( ) )
393+ } ) ?;
394+
395+ let mut vec_recip = parsed_recip
396+ . iter ( )
397+ . map ( |recip| ( recip. 1 . address . script_pubkey ( ) , recip. 1 . amount ) )
398+ . collect :: < Vec < _ > > ( ) ;
399+ recipients. append ( & mut vec_recip) ;
400+ }
372401 tx_builder. set_recipients ( recipients) ;
373402 }
374403
@@ -1329,7 +1358,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
13291358 & wallet_opts,
13301359 & cli_opts,
13311360 offline_subcommand. clone ( ) ,
1332- ) ?
1361+ ) . await ?
13331362 } ;
13341363 Ok ( result)
13351364 }
0 commit comments