From 8b2c59b52ce6eebf0341a6f709ea5c34ac692965 Mon Sep 17 00:00:00 2001 From: Dzung Do Date: Thu, 13 Feb 2025 23:43:39 +0700 Subject: [PATCH] update balance of txs --- modules/bank/handle_block.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/bank/handle_block.go b/modules/bank/handle_block.go index 069aa3120..99e5cc66b 100644 --- a/modules/bank/handle_block.go +++ b/modules/bank/handle_block.go @@ -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 } @@ -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")