diff --git a/db/statedb/txprocessors.go b/db/statedb/txprocessors.go index 2602a10..d6c8368 100644 --- a/db/statedb/txprocessors.go +++ b/db/statedb/txprocessors.go @@ -538,9 +538,16 @@ func (s *StateDB) applyTransfer(tx common.Tx, auxToIdx common.Idx) error { // increment nonce accSender.Nonce++ - // subtract amount to the sender - accSender.Balance = new(big.Int).Sub(accSender.Balance, tx.Amount) - // add amount to the receiver + 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) + 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) // update sender account in localStateDB @@ -653,7 +660,16 @@ func (s *StateDB) applyExit(exitTree *merkletree.MerkleTree, tx common.Tx) (*com if err != nil { 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) if err != nil { return nil, false, err diff --git a/db/statedb/txprocessors_test.go b/db/statedb/txprocessors_test.go index adfb97b..f657e16 100644 --- a/db/statedb/txprocessors_test.go +++ b/db/statedb/txprocessors_test.go @@ -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' acc, err = sdb.GetAccount(common.Idx(256)) assert.Nil(t, err) - assert.Equal(t, "73", acc.Balance.String()) + assert.Equal(t, "78", acc.Balance.String()) } /*