Skip to content

Commit

Permalink
fix: move tx verification to wallet sign
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed Jul 19, 2024
1 parent c5d1461 commit 12b7c4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 1 addition & 8 deletions sn_cli/src/bin/subcommands/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ use crate::get_stdin_response;

use bls::SecretKey;
use clap::Parser;
use color_eyre::{
eyre::{bail, eyre},
Result,
};
use color_eyre::{eyre::eyre, Result};
use dialoguer::Confirm;
use sn_client::transfers::{
HotWallet, MainPubkey, MainSecretKey, NanoTokens, Transfer, TransferError, UnsignedTransaction,
Expand Down Expand Up @@ -338,10 +335,6 @@ fn sign_transaction(tx: &str, root_dir: &Path, force: bool) -> Result<()> {
println!("Signing the transaction with local hot-wallet...");
let signed_tx = wallet.sign(unsigned_tx)?;

if let Err(err) = signed_tx.verify(wallet.key()) {
bail!("Signature or transaction generated is invalid: {err:?}");
}

println!(
"The transaction has been successfully signed:\n\n{}\n",
signed_tx.to_hex()?
Expand Down
15 changes: 13 additions & 2 deletions sn_transfers/src/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,20 @@ impl HotWallet {
}

pub fn sign(&self, unsigned_tx: UnsignedTransaction) -> Result<SignedTransaction> {
unsigned_tx
if let Err(err) = unsigned_tx.verify() {
return Err(Error::CouldNotSignTransaction(format!(
"Failed to verify unsigned transaction: {err:?}"
)));
}
let signed_tx = unsigned_tx
.sign(&self.key)
.map_err(|e| Error::CouldNotSignTransaction(e.to_string()))
.map_err(|e| Error::CouldNotSignTransaction(e.to_string()))?;
if let Err(err) = signed_tx.verify(&self.key) {
return Err(Error::CouldNotSignTransaction(format!(
"Failed to verify signed transaction: {err:?}"
)));
}
Ok(signed_tx)
}

/// Returns all available cash_notes and an exclusive access to the wallet so no concurrent processes can
Expand Down

0 comments on commit 12b7c4d

Please sign in to comment.