forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a668a6
commit 81a69f7
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package bank | ||
|
||
import ( | ||
tmctypes "github.com/cometbft/cometbft/rpc/core/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/forbole/bdjuno/v4/types" | ||
juno "github.com/forbole/juno/v5/types" | ||
) | ||
|
||
func (m *Module) HandleBlock( | ||
_ *tmctypes.ResultBlock, _ *tmctypes.ResultBlockResults, txs []*juno.Tx, _ *tmctypes.ResultValidators, | ||
) error { | ||
height, err := m.db.GetLastBlockHeight() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var addresses []string | ||
addrMap := make(map[string]bool) | ||
|
||
for _, tx := range txs { | ||
for _, message := range tx.Body.Messages { | ||
var stdMsg sdk.Msg | ||
err := m.cdc.UnpackAny(message, &stdMsg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
addresses, _ := m.messageParser(m.cdc, stdMsg) | ||
for _, address := range addresses { | ||
addrMap[address] = true | ||
} | ||
} | ||
} | ||
|
||
for addr, _ := range addrMap { | ||
addresses = append(addresses, addr) | ||
} | ||
|
||
balances, err := m.keeper.GetBalances(addresses, height) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bankBalances := make([]banktypes.Balance, len(balances)) | ||
for i, balance := range balances { | ||
bankBalances[i] = convertBalance(balance) | ||
} | ||
|
||
return m.db.SaveAccountBalances(height, bankBalances) | ||
} | ||
|
||
func convertBalance(balance types.AccountBalance) banktypes.Balance { | ||
return banktypes.Balance{ | ||
Address: balance.Address, | ||
Coins: balance.Balance, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters