arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Add fees subtraction on TxProcessors
arnaucube root@arnaucube.com
Fri, 23 Oct 2020 18:10:28 +0200
commit

1e71d7f19e973d772bdaaff5bfaf4dccc3d3ae8e

parent

e76cc98e4c0c319a9fb87aaef3ef36f34556ed0a

2 files changed, 21 insertions(+), 5 deletions(-)

jump to
M db/statedb/txprocessors.go → db/statedb/txprocessors.go

@@ -538,9 +538,16 @@

// 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 @@ acc, err := s.GetAccount(tx.FromIdx)

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
M db/statedb/txprocessors_test.go → db/statedb/txprocessors_test.go

@@ -74,7 +74,7 @@

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()) } /*