Skip to content

Commit

Permalink
Factored out the submission of the reveal PK transaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed Jul 3, 2023
1 parent 3968108 commit 1654271
Showing 1 changed file with 38 additions and 201 deletions.
239 changes: 38 additions & 201 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,44 @@ use crate::wallet::{
gen_validator_keys, read_and_confirm_encryption_password,
};

pub async fn submit_custom<C: namada::ledger::queries::Client + Sync>(
// Build a transaction to reveal the signer of the given transaction.
pub async fn submit_reveal_aux<C: namada::ledger::queries::Client + Sync>(
client: &C,
ctx: &mut Context,
args: args::TxCustom,
args: &args::Tx,
addr: Option<Address>,
pk: common::PublicKey,
tx: &mut Tx,
) -> Result<(), tx::Error> {
let (mut tx, addr, pk) =
tx::build_custom(client, &mut ctx.wallet, args.clone()).await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
args::RevealPk { tx: args.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
tx::process_tx(client, &mut ctx.wallet, &args, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
signing::update_pow_challenge(client, &args, tx, &pk, false)
.await;
}
}
Ok(())
}

pub async fn submit_custom<C: namada::ledger::queries::Client + Sync>(
client: &C,
ctx: &mut Context,
args: args::TxCustom,
) -> Result<(), tx::Error> {
let (mut tx, addr, pk) =
tx::build_custom(client, &mut ctx.wallet, args.clone()).await?;
submit_reveal_aux(client, ctx, &args.tx, addr, pk.clone(), &mut tx).await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Ok(())
Expand All @@ -83,25 +95,7 @@ pub async fn submit_update_vp<C: namada::ledger::queries::Client + Sync>(
) -> Result<(), tx::Error> {
let (mut tx, addr, pk) =
tx::build_update_vp(client, &mut ctx.wallet, args.clone()).await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
submit_reveal_aux(client, ctx, &args.tx, addr, pk.clone(), &mut tx).await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Ok(())
Expand All @@ -114,25 +108,7 @@ pub async fn submit_init_account<C: namada::ledger::queries::Client + Sync>(
) -> Result<(), tx::Error> {
let (mut tx, addr, pk) =
tx::build_init_account(client, &mut ctx.wallet, args.clone()).await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
submit_reveal_aux(client, ctx, &args.tx, addr, pk.clone(), &mut tx).await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Ok(())
Expand Down Expand Up @@ -288,25 +264,7 @@ pub async fn submit_init_validator<
false,
)
.await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: tx_args.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &tx_args, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &tx_args, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &tx_args, &mut tx, &pk, false)
.await;
}
}
submit_reveal_aux(client, &mut ctx, &tx_args, addr, pk.clone(), &mut tx).await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &tx_args, &pk).await?;
let result = tx::process_tx(client, &mut ctx.wallet, &tx_args, tx).await?
.initialized_accounts();
Expand Down Expand Up @@ -722,25 +680,8 @@ pub async fn submit_init_proposal<C: namada::ledger::queries::Client + Sync>(
false,
)
.await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
submit_reveal_aux(client, &mut ctx, &args.tx, addr, pk.clone(), &mut tx)
.await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk)
.await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Expand Down Expand Up @@ -995,25 +936,7 @@ pub async fn submit_vote_proposal<C: namada::ledger::queries::Client + Sync>(
false,
)
.await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
submit_reveal_aux(client, &mut ctx, &args.tx, addr, pk.clone(), &mut tx).await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk)
.await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Expand Down Expand Up @@ -1100,26 +1023,9 @@ pub async fn submit_bond<C: namada::ledger::queries::Client + Sync>(
ctx: &mut Context,
args: args::Bond,
) -> Result<(), tx::Error> {
let (mut tx, addr, pk) = tx::build_bond::<C, _>(client, &mut ctx.wallet, args.clone()).await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
let (mut tx, addr, pk) =
tx::build_bond::<C, _>(client, &mut ctx.wallet, args.clone()).await?;
submit_reveal_aux(client, ctx, &args.tx, addr, pk.clone(), &mut tx).await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Ok(())
Expand All @@ -1132,25 +1038,7 @@ pub async fn submit_unbond<C: namada::ledger::queries::Client + Sync>(
) -> Result<(), tx::Error> {
let (mut tx, addr, pk, latest_withdrawal_pre) =
tx::build_unbond(client, &mut ctx.wallet, args.clone()).await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
#[cfg(not(feature = "mainnet"))]
// Update the stateful PoW challenge of the outer transaction
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
submit_reveal_aux(client, ctx, &args.tx, addr, pk.clone(), &mut tx).await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
tx::query_unbonds(client, args.clone(), latest_withdrawal_pre).await?;
Expand All @@ -1162,27 +1050,10 @@ pub async fn submit_withdraw<C: namada::ledger::queries::Client + Sync>(
mut ctx: Context,
args: args::Withdraw,
) -> Result<(), tx::Error> {
let (mut tx, addr, pk) = tx::build_withdraw(client, &mut ctx.wallet, args.clone())
let (mut tx, addr, pk) =
tx::build_withdraw(client, &mut ctx.wallet, args.clone()).await?;
submit_reveal_aux(client, &mut ctx, &args.tx, addr, pk.clone(), &mut tx)
.await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Ok(())
Expand All @@ -1199,25 +1070,8 @@ pub async fn submit_validator_commission_change<
let (mut tx, addr, pk) =
tx::build_validator_commission_change(client, &mut ctx.wallet, arg)
.await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
submit_reveal_aux(client, &mut ctx, &args.tx, addr, pk.clone(), &mut tx)
.await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Ok(())
Expand All @@ -1233,25 +1087,8 @@ pub async fn submit_unjail_validator<
let (mut tx, addr, pk) =
tx::build_unjail_validator(client, &mut ctx.wallet, args.clone())
.await?;
// Build a transaction to reveal the signer of this transaction
if let Some(Address::Implicit(_)) = addr {
let reveal_pk = tx::build_reveal_pk(
client,
&mut ctx.wallet,
args::RevealPk { tx: args.tx.clone(), public_key: pk.clone() },
).await?;
if let Some((mut rtx, _, pk)) = reveal_pk {
// Sign the reveal public key transaction with the fee payer
signing::sign_tx(&mut ctx.wallet, &mut rtx, &args.tx, &pk)
.await?;
// Submit the reveal public key transaction first
tx::process_tx(client, &mut ctx.wallet, &args.tx, rtx).await?;
// Update the stateful PoW challenge of the outer transaction
#[cfg(not(feature = "mainnet"))]
signing::update_pow_challenge(client, &args.tx, &mut tx, &pk, false)
.await;
}
}
submit_reveal_aux(client, &mut ctx, &args.tx, addr, pk.clone(), &mut tx)
.await?;
signing::sign_tx(&mut ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
Ok(())
Expand Down

0 comments on commit 1654271

Please sign in to comment.