mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add fees subtraction on TxProcessors
This commit is contained in:
@@ -538,9 +538,16 @@ func (s *StateDB) applyTransfer(tx common.Tx, auxToIdx common.Idx) error {
|
|||||||
// increment nonce
|
// increment nonce
|
||||||
accSender.Nonce++
|
accSender.Nonce++
|
||||||
|
|
||||||
// subtract amount to the sender
|
if !tx.IsL1 {
|
||||||
accSender.Balance = new(big.Int).Sub(accSender.Balance, tx.Amount)
|
// compute fee and subtract it from the accSender
|
||||||
// add amount to the receiver
|
fee := common.CalcFeeAmount(tx.Amount, *tx.Fee)
|
||||||
|
feeAndAmount := new(big.Int).Add(tx.Amount, fee)
|
||||||
|
accSender.Balance = new(big.Int).Sub(accSender.Balance, feeAndAmount)
|
||||||
|
// TODO send the fee to the Fee Idx of the Coordinator for the
|
||||||
|
// TokenID
|
||||||
|
}
|
||||||
|
|
||||||
|
// add amount-feeAmount to the receiver
|
||||||
accReceiver.Balance = new(big.Int).Add(accReceiver.Balance, tx.Amount)
|
accReceiver.Balance = new(big.Int).Add(accReceiver.Balance, tx.Amount)
|
||||||
|
|
||||||
// update sender account in localStateDB
|
// update sender account in localStateDB
|
||||||
@@ -653,7 +660,16 @@ func (s *StateDB) applyExit(exitTree *merkletree.MerkleTree, tx common.Tx) (*com
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
acc.Balance = new(big.Int).Sub(acc.Balance, tx.Amount)
|
|
||||||
|
if !tx.IsL1 {
|
||||||
|
// compute fee and subtract it from the accSender
|
||||||
|
fee := common.CalcFeeAmount(tx.Amount, *tx.Fee)
|
||||||
|
feeAndAmount := new(big.Int).Add(tx.Amount, fee)
|
||||||
|
acc.Balance = new(big.Int).Sub(acc.Balance, feeAndAmount)
|
||||||
|
// TODO send the fee to the Fee Idx of the Coordinator for the
|
||||||
|
// TokenID
|
||||||
|
}
|
||||||
|
|
||||||
p, err := s.UpdateAccount(tx.FromIdx, acc)
|
p, err := s.UpdateAccount(tx.FromIdx, acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func TestProcessTxsSynchronizer(t *testing.T) {
|
|||||||
assert.Equal(t, 2, len(exitInfos)) // 2, as previous batch was without L1UserTxs, and has pending the 'ForceExit(1) A: 5'
|
assert.Equal(t, 2, len(exitInfos)) // 2, as previous batch was without L1UserTxs, and has pending the 'ForceExit(1) A: 5'
|
||||||
acc, err = sdb.GetAccount(common.Idx(256))
|
acc, err = sdb.GetAccount(common.Idx(256))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "73", acc.Balance.String())
|
assert.Equal(t, "78", acc.Balance.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user