Skip to content

Commit ff3fbb9

Browse files
committed
Make the client submit unbatched transactions when the hardware wallet is used.
1 parent fd48b22 commit ff3fbb9

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

crates/apps_lib/src/client/tx.rs

+29-11
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ async fn batch_opt_reveal_pk_and_submit<N: Namada>(
258258
namada: &N,
259259
args: &args::Tx,
260260
owners: &[&Address],
261-
tx_data: (Tx, SigningTxData),
261+
mut tx_data: (Tx, SigningTxData),
262262
) -> Result<ProcessTxResponse, error::Error>
263263
where
264264
<N::Client as namada_sdk::io::Client>::Error: std::fmt::Display,
@@ -272,15 +272,33 @@ where
272272
batched_tx_data.push(reveal_pk_tx_data);
273273
}
274274
}
275-
batched_tx_data.push(tx_data);
276275

277-
let (mut batched_tx, batched_signing_data) =
278-
namada_sdk::tx::build_batch(batched_tx_data)?;
279-
for sig_data in batched_signing_data {
280-
sign(namada, &mut batched_tx, args, sig_data).await?;
276+
// Since hardware wallets do not yet support batched transactions, use a
277+
// different logic in order to achieve compatibility
278+
if args.use_device {
279+
// Sign each transaction separately
280+
for (tx, sig_data) in &mut batched_tx_data {
281+
sign(namada, tx, args, sig_data.clone()).await?;
282+
}
283+
sign(namada, &mut tx_data.0, args, tx_data.1).await?;
284+
// Then submit each transaction separately
285+
for (tx, _sig_data) in batched_tx_data {
286+
namada.submit(tx, args).await?;
287+
}
288+
// The result of submitting this function's argument is what is returned
289+
namada.submit(tx_data.0, args).await
290+
} else {
291+
// Otherwise complete the batch with this function's argument
292+
batched_tx_data.push(tx_data);
293+
let (mut batched_tx, batched_signing_data) =
294+
namada_sdk::tx::build_batch(batched_tx_data)?;
295+
// Sign the batch with the union of the signers required for each part
296+
for sig_data in batched_signing_data {
297+
sign(namada, &mut batched_tx, args, sig_data).await?;
298+
}
299+
// Then finally submit everything in one go
300+
namada.submit(batched_tx, args).await
281301
}
282-
283-
namada.submit(batched_tx, args).await
284302
}
285303

286304
pub async fn submit_bridge_pool_tx<N: Namada>(
@@ -1202,7 +1220,7 @@ pub async fn submit_shielded_transfer(
12021220
MAX_HW_OUTPUT,
12031221
&args.tx,
12041222
)
1205-
.await?;
1223+
.await?;
12061224
let (mut tx, signing_data) =
12071225
args.clone().build(namada, &mut bparams).await?;
12081226
masp_sign(&mut tx, &args.tx, &signing_data, shielded_hw_keys).await?;
@@ -1378,7 +1396,7 @@ where
13781396
MAX_HW_OUTPUT,
13791397
&args.tx,
13801398
)
1381-
.await?;
1399+
.await?;
13821400
let (mut tx, signing_data, _) = args.build(namada, &mut bparams).await?;
13831401
masp_sign(&mut tx, &args.tx, &signing_data, shielded_hw_keys).await?;
13841402

@@ -1396,7 +1414,7 @@ where
13961414
&[&args.source.effective_address()],
13971415
(tx, signing_data),
13981416
)
1399-
.await?;
1417+
.await?;
14001418

14011419
if let Some(masp_section) = opt_masp_section {
14021420
pre_cache_masp_data_on_tx_result(namada, &res, &masp_section).await;

crates/tests/src/e2e/ibc_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ fn transfer_on_chain(
14031403
&rpc,
14041404
]);
14051405
tx_args.extend_from_slice(extra_args);
1406-
let mut client = run!(test, Bin::Client, tx_args, Some(120))?;
1406+
let mut client = run!(test, Bin::Client, tx_args, Some(240))?;
14071407
client.exp_string(TX_APPLIED_SUCCESS)?;
14081408
client.assert_success();
14091409

0 commit comments

Comments
 (0)