@@ -19,6 +19,7 @@ use crate::utils::*;
1919#[ cfg( feature = "redb" ) ]
2020use bdk_redb:: Store as RedbStore ;
2121use bdk_wallet:: bip39:: { Language , Mnemonic } ;
22+ use bdk_wallet:: bitcoin:: ScriptBuf ;
2223use bdk_wallet:: bitcoin:: base64:: Engine ;
2324use bdk_wallet:: bitcoin:: base64:: prelude:: BASE64_STANDARD ;
2425use bdk_wallet:: bitcoin:: {
@@ -330,7 +331,7 @@ pub async fn handle_offline_wallet_subcommand(
330331 }
331332
332333 ResolveDnsRecipient { hrn, amount } => {
333- let resolved = resolve_dns_recipient ( & hrn, Amount :: from_sat ( amount) , Network :: Bitcoin )
334+ let resolved = resolve_dns_recipient ( & hrn, Amount :: from_sat ( amount) , wallet . network ( ) )
334335 . await
335336 . map_err ( |e| Error :: Generic ( format ! ( "{:?}" , e) ) ) ?;
336337
@@ -344,6 +345,7 @@ pub async fn handle_offline_wallet_subcommand(
344345
345346 CreateTx {
346347 recipients,
348+ dns_recipients,
347349 send_all,
348350 enable_rbf,
349351 offline_signer,
@@ -360,10 +362,34 @@ pub async fn handle_offline_wallet_subcommand(
360362 if send_all {
361363 tx_builder. drain_wallet ( ) . drain_to ( recipients[ 0 ] . 0 . clone ( ) ) ;
362364 } else {
363- let recipients = recipients
365+ let mut recipients: Vec < ( ScriptBuf , Amount ) > = recipients
364366 . into_iter ( )
365367 . map ( |( script, amount) | ( script, Amount :: from_sat ( amount) ) )
366368 . collect ( ) ;
369+
370+ if let Some ( recip) = dns_recipients {
371+ let parsed_recip = parse_dns_recipients ( & recip)
372+ . await
373+ . map_err ( |pe| Error :: Generic ( format ! ( "Resolution failed: {pe}" ) ) ) ?;
374+
375+ // Validates if the amount the user wants to send is in the range of what the payment instructions returned
376+ parsed_recip. iter ( ) . try_for_each ( |( _, r) | {
377+ let amount = r. amount . to_sat ( ) ;
378+ if r. min_amount . map_or ( false , |min| amount < min. to_sat ( ) ) {
379+ return Err ( Error :: Generic ( "Amount lesser than min" . to_string ( ) ) ) ;
380+ }
381+ if r. max_amount . map_or ( false , |max| amount > max. to_sat ( ) ) {
382+ return Err ( Error :: Generic ( "Amount greater than max" . to_string ( ) ) ) ;
383+ }
384+ Ok ( ( ) )
385+ } ) ?;
386+
387+ let mut vec_recip = parsed_recip
388+ . iter ( )
389+ . map ( |recip| ( recip. 1 . address . script_pubkey ( ) , recip. 1 . amount ) )
390+ . collect :: < Vec < _ > > ( ) ;
391+ recipients. append ( & mut vec_recip) ;
392+ }
367393 tx_builder. set_recipients ( recipients) ;
368394 }
369395
0 commit comments