Skip to content

Commit fac08f3

Browse files
committed
Shielded-sync for osmosis swaps
1 parent 47bdd82 commit fac08f3

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

crates/apps_lib/src/cli/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl CliClient for HttpClient {
3333
}
3434
}
3535

36+
#[derive(Copy, Clone)]
3637
pub struct CliIo;
3738

3839
#[async_trait::async_trait(?Send)]

crates/apps_lib/src/cli/client.rs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::cli::cmds::*;
1313
use crate::client::{rpc, tx, utils};
1414

1515
impl 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();

crates/node/src/shell/testing/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ lazy_static! {
7171
AtomicBuffer(std::sync::Arc::new(std::sync::Mutex::new(vec![])));
7272
}
7373

74+
#[derive(Copy, Clone)]
7475
pub struct TestingIo;
7576

7677
#[async_trait::async_trait(?Send)]

0 commit comments

Comments
 (0)