Skip to content

Commit 597df8c

Browse files
committed
Refactors signing of custom transactions
1 parent 167a642 commit 597df8c

File tree

3 files changed

+43
-48
lines changed

3 files changed

+43
-48
lines changed

crates/apps_lib/src/client/tx.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ where
335335
let (mut tx, signing_data) = args.build(namada).await?;
336336

337337
if matches!(args.tx.dump_tx, Some(args::DumpTx::Wrapper)) {
338-
// FIXME: here we attach the inner signatures when dumping the wrapper
339338
// Attach the provided inner signatures to the tx (if any)
340339
let signatures = args
341340
.signatures
@@ -354,22 +353,12 @@ where
354353
return tx::dump_tx(namada.io(), dump_tx, args.tx.output_folder, tx);
355354
}
356355

357-
if let Some(signing_data) = signing_data {
358-
let owners = args
359-
.owner
360-
.map_or_else(Default::default, |owner| vec![owner]);
361-
let refs: Vec<&Address> = owners.iter().collect();
362-
batch_opt_reveal_pk_and_submit(
363-
namada,
364-
&args.tx,
365-
&refs,
366-
(tx, signing_data),
367-
)
356+
let owners = args
357+
.owner
358+
.map_or_else(Default::default, |owner| vec![owner]);
359+
let refs: Vec<&Address> = owners.iter().collect();
360+
batch_opt_reveal_pk_and_submit(namada, &args.tx, &refs, (tx, signing_data))
368361
.await?;
369-
} else {
370-
// Just submit without the need for signing
371-
namada.submit(tx, &args.tx).await?;
372-
}
373362

374363
Ok(())
375364
}

crates/sdk/src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl TxCustom {
231231
pub async fn build(
232232
&self,
233233
context: &impl Namada,
234-
) -> crate::error::Result<(namada_tx::Tx, Option<SigningData>)> {
234+
) -> crate::error::Result<(namada_tx::Tx, SigningData)> {
235235
tx::build_custom(context, self).await
236236
}
237237
}

crates/sdk/src/tx.rs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ pub async fn process_tx(
277277
// We use this to determine when the wrapper tx makes it on-chain
278278
let tx_hash = tx.header_hash().to_string();
279279
let cmts = tx.commitments().clone();
280+
// FIXME: add a check to avoid submitting raw txs? Yes
280281
let wrapper_hash = tx.wrapper_hash();
281282
// We use this to determine when the inner tx makes it
282283
// on-chain
@@ -5009,7 +5010,7 @@ pub async fn build_custom(
50095010
signatures,
50105011
wrapper_signature,
50115012
}: &args::TxCustom,
5012-
) -> Result<(Tx, Option<SigningData>)> {
5013+
) -> Result<(Tx, SigningData)> {
50135014
let mut tx = if let Some(serialized_tx) = serialized_tx {
50145015
Tx::try_from_json_bytes(serialized_tx.as_ref()).map_err(|_| {
50155016
Error::Other(
@@ -5048,49 +5049,44 @@ pub async fn build_custom(
50485049
// 2. If only the inner sigs were provided we generate a SigningData that
50495050
// will attach them and then sign the wrapper online
50505051
// 3. If the wrapper signature was provided then we also expect the inner
5051-
// signature(s) to have been provided, in this case we attach all the
5052-
// signatures here and return no SigningData
5053-
let signing_data = if let Some(wrapper_signature) = &wrapper_signature {
5052+
// signature(s) to have been provided, in this case we generate a
5053+
// SigningData to attach all these signatures
5054+
let signing_data = if wrapper_signature.is_some() {
50545055
if tx.header.wrapper().is_none() {
50555056
return Err(Error::Other(
50565057
"A wrapper signature was provided but the transaction is not \
50575058
a wrapper"
50585059
.to_string(),
50595060
));
50605061
}
5061-
// Attach the provided signatures to the tx without the need to produce
5062-
// any more signatures
5063-
// FIXME: don't we attach the signatures when we dump the tx?
5064-
let signatures = signatures.iter().try_fold(
5065-
vec![],
5066-
|mut acc, bytes| -> Result<Vec<_>> {
5067-
let sig = SignatureIndex::try_from_json_bytes(bytes).map_err(
5068-
|err| Error::Encode(EncodingError::Serde(err.to_string())),
5069-
)?;
5070-
acc.push(sig);
5071-
Ok(acc)
5072-
},
5073-
)?;
5074-
tx.add_signatures(signatures)
5075-
.add_section(Section::Authorization(
5076-
serde_json::from_slice(wrapper_signature).map_err(|err| {
5077-
Error::Encode(EncodingError::Serde(err.to_string()))
5078-
})?,
5079-
));
5080-
None
5062+
5063+
SigningData::Wrapper(
5064+
signing::aux_signing_data(
5065+
context,
5066+
tx_args,
5067+
owner.clone(),
5068+
owner.clone(),
5069+
vec![],
5070+
// The wrapper signature is provided so no need to generate a
5071+
// disposable address anyway
5072+
false,
5073+
signatures.to_owned(),
5074+
wrapper_signature.to_owned(),
5075+
)
5076+
.await?,
5077+
)
50815078
} else {
50825079
let signing_data = signing::aux_signing_data(
50835080
context,
50845081
tx_args,
50855082
owner.clone(),
50865083
owner.clone(),
50875084
vec![],
5088-
// FIXME: is this correct? Probably not I should chech the owner
5085+
// The possible masp fee paying transaction has already been
5086+
// produced so no need to generate a disposable address anyway
50895087
false,
50905088
signatures.to_owned(),
5091-
// FIXME: actually can't we unify the two branches and pass the
5092-
// wrapper signatures here?
5093-
None,
5089+
wrapper_signature.to_owned(),
50945090
)
50955091
.await?;
50965092

@@ -5106,10 +5102,20 @@ pub async fn build_custom(
51065102
fee_payer,
51075103
wrap_tx.gas_limit,
51085104
);
5105+
SigningData::Wrapper(signing_data)
5106+
} else {
5107+
SigningData::Inner(
5108+
signing::aux_inner_signing_data(
5109+
context,
5110+
tx_args,
5111+
owner.clone(),
5112+
owner.clone(),
5113+
vec![],
5114+
signatures.to_owned(),
5115+
)
5116+
.await?,
5117+
)
51095118
}
5110-
// FIXME: what if we want to load a raw tx, sign the inner and nothing
5111-
// else? No wrapping
5112-
Some(SigningData::Wrapper(signing_data))
51135119
};
51145120

51155121
Ok((tx, signing_data))

0 commit comments

Comments
 (0)