@@ -13,7 +13,7 @@ use crate::cli::cmds::*;
1313use crate :: client:: { rpc, tx, utils} ;
1414
1515impl CliApi {
16- pub async fn handle_client_command < C , IO : Io + Send + Sync > (
16+ pub async fn handle_client_command < C , IO : Io + Clone + Send + Sync > (
1717 client : Option < C > ,
1818 cmd : cli:: NamadaClient ,
1919 io : IO ,
@@ -231,9 +231,23 @@ impl CliApi {
231231 } ) ;
232232 client. wait_until_node_is_synced ( & io) . await ?;
233233
234+ // Pre-extract data for the optional shielded-sync
235+ let extra_sync_vks = chain_ctx
236+ . wallet
237+ . get_viewing_keys ( )
238+ . into_iter ( )
239+ . map ( |( k, v) | {
240+ DatedViewingKey :: new (
241+ v,
242+ chain_ctx. wallet . find_birthday ( k) . copied ( ) ,
243+ )
244+ } )
245+ . collect :: < Vec < _ > > ( ) ;
246+ let shielded = std:: mem:: take ( & mut chain_ctx. shielded ) ;
247+
234248 let args = args. to_sdk ( & mut ctx) ?;
235- let namada = ctx. to_sdk ( client, io) ;
236- let args = args
249+ let namada = ctx. to_sdk ( client. clone ( ) , io. clone ( ) ) ;
250+ let mut args = args
237251 . into_ibc_transfer (
238252 & namada,
239253 |_route, min_amount, quote_amount| {
@@ -276,7 +290,34 @@ impl CliApi {
276290 )
277291 . await ?;
278292
279- tx:: submit_ibc_transfer ( & namada, args) . await ?;
293+ if args. source . spending_key ( ) . is_some ( ) {
294+ // Sync the shielded context
295+ let mut sync_args = std:: mem:: take (
296+ & mut args. shielded_sync ,
297+ )
298+ . expect ( "Missing required shielded-sync arguments" ) ;
299+ sync_args. viewing_keys . extend ( extra_sync_vks) ;
300+ let synced_shielded_ctx =
301+ crate :: client:: masp:: syncing (
302+ ShieldedContext :: new ( shielded) ,
303+ client. clone ( ) ,
304+ sync_args,
305+ & io,
306+ )
307+ . await ?;
308+
309+ let namada = namada
310+ . update_shielded_context ( synced_shielded_ctx)
311+ . await ;
312+ tx:: submit_ibc_transfer ( & namada, args) . await ?
313+ } else {
314+ let namada = namada
315+ . update_shielded_context ( ShieldedContext :: new (
316+ shielded,
317+ ) )
318+ . await ;
319+ tx:: submit_ibc_transfer ( & namada, args) . await ?
320+ }
280321 }
281322 Sub :: TxUpdateAccount ( TxUpdateAccount ( args) ) => {
282323 let chain_ctx = ctx. borrow_mut_chain_or_exit ( ) ;
0 commit comments