fix: comments fix 1

This commit is contained in:
Oleksandr Pravdyvyi
2025-07-24 16:05:27 +03:00
parent 95fec47897
commit 41b65521f9
6 changed files with 42 additions and 39 deletions
+31 -28
View File
@@ -4,9 +4,9 @@ use accounts::account_core::AccountAddress;
use anyhow::Result;
use common::{
block::{Block, HashableBlockData},
execution_input::PublicNativeTokenSend,
merkle_tree_public::TreeHashType,
nullifier::UTXONullifier,
public_transfer_receipts::PublicNativeTokenSend,
transaction::{AuthenticatedTransaction, Transaction, TransactionBody, TxKind},
utxo_commitment::UTXOCommitment,
};
@@ -177,33 +177,6 @@ impl SequencerCore {
);
}
//Balance check
if let Ok(native_transfer_action) =
serde_json::from_slice::<PublicNativeTokenSend>(execution_input)
{
let from_balance = self
.store
.acc_store
.get_account_balance(&native_transfer_action.from);
let to_balance = self
.store
.acc_store
.get_account_balance(&native_transfer_action.to);
if from_balance >= native_transfer_action.moved_balance {
self.store.acc_store.set_account_balance(
&native_transfer_action.from,
from_balance - native_transfer_action.moved_balance,
);
self.store.acc_store.set_account_balance(
&native_transfer_action.to,
to_balance + native_transfer_action.moved_balance,
);
} else {
return Err(TransactionMalformationErrorKind::BalanceMismatch { tx: tx_hash });
}
}
Ok(tx)
}
@@ -233,9 +206,12 @@ impl SequencerCore {
let TransactionBody {
ref utxo_commitments_created_hashes,
ref nullifier_created_hashes,
execution_input,
..
} = mempool_tx.auth_tx.transaction().body();
let tx_hash = *mempool_tx.auth_tx.hash();
for utxo_comm in utxo_commitments_created_hashes {
self.store
.utxo_commitments_store
@@ -252,6 +228,33 @@ impl SequencerCore {
.pub_tx_store
.add_tx(mempool_tx.auth_tx.transaction());
//Balance check
if let Ok(native_transfer_action) =
serde_json::from_slice::<PublicNativeTokenSend>(execution_input)
{
let from_balance = self
.store
.acc_store
.get_account_balance(&native_transfer_action.from);
let to_balance = self
.store
.acc_store
.get_account_balance(&native_transfer_action.to);
if from_balance >= native_transfer_action.balance_to_move {
self.store.acc_store.set_account_balance(
&native_transfer_action.from,
from_balance - native_transfer_action.balance_to_move,
);
self.store.acc_store.set_account_balance(
&native_transfer_action.to,
to_balance + native_transfer_action.balance_to_move,
);
} else {
return Err(TransactionMalformationErrorKind::BalanceMismatch { tx: tx_hash });
}
}
Ok(())
}
@@ -66,17 +66,17 @@ impl SequencerAccountsStore {
///Update `account_addr` balance,
///
/// returns 0, if account address not found, othervise returns previous balance
/// returns 0, if account address not found, otherwise returns previous balance
pub fn set_account_balance(&mut self, account_addr: &AccountAddress, new_balance: u64) -> u64 {
let acc_data = self.accounts.get_mut(account_addr);
acc_data
.map(|data| {
let old_bal = data.balance;
let old_balance = data.balance;
data.balance = new_balance;
old_bal
old_balance
})
.unwrap_or(0)
}