Skip to content

Commit

Permalink
update balance of txs
Browse files Browse the repository at this point in the history
  • Loading branch information
neitdung committed Feb 13, 2025
1 parent 810b5af commit 8b2c59b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions modules/bank/handle_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
func (m *Module) HandleBlock(
block *tmctypes.ResultBlock, res *tmctypes.ResultBlockResults, _ []*juno.Transaction, _ *tmctypes.ResultValidators,
) error {
m.updateBalanceByTxEvent(block.Block.Height, res.TxsResults)

// Remove expired fee grant allowances
err := m.updateBalanceByEvent(block.Block.Height, res.FinalizeBlockEvents)
if err != nil {
fmt.Printf("Error when removing expired fee grant allowance, error: %s", err)
fmt.Printf("Error when update balance by end block: %s", err)
}

return nil
}

Expand Down Expand Up @@ -76,13 +77,26 @@ func (m *Module) updateBalanceByEvent(height int64, events []abci.Event) error {
for address := range setAddr {
addresses = append(addresses, address)
}

if len(addresses) == 0 {
return nil
}
return m.UpdateBalance(addresses, height)
}

// removeExpiredFeeGrantAllowances removes fee grant allowances in database that have expired
func (m *Module) updateBalanceByTxEvent(height int64, txs []*abci.ExecTxResult) {
log.Debug().Str("module", "bank").Int64("height", height).
Msg("updating balance by tx event")

for _, tx := range txs {
events := tx.Events
err := m.updateBalanceByEvent(height, events)
if err != nil {
fmt.Printf("Error when update balance inside tx events: %s", err)
}
}
}

func (m *Module) UpdateBalance(addresses []string, height int64) error {
log.Trace().Str("module", "bank").Str("operation", "account balance").
Msg("updating account balance")
Expand Down

0 comments on commit 8b2c59b

Please sign in to comment.