Skip to content

Commit

Permalink
Avoid using iterator when getting spendable coins (#1626)
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen authored May 4, 2024
1 parent f98716a commit 3fc8d42
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions x/evm/state/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ func (s *DBImpl) AddBalance(evmAddr common.Address, amt *big.Int, reason tracing

func (s *DBImpl) GetBalance(evmAddr common.Address) *big.Int {
s.k.PrepareReplayedAddr(s.ctx, evmAddr)
usei := s.k.BankKeeper().SpendableCoins(s.ctx, s.getSeiAddress(evmAddr)).AmountOf(s.k.GetBaseDenom(s.ctx))
wei := s.k.BankKeeper().GetWeiBalance(s.ctx, s.getSeiAddress(evmAddr))
seiAddr := s.getSeiAddress(evmAddr)
denom := s.k.GetBaseDenom(s.ctx)
allUsei := s.k.BankKeeper().GetBalance(s.ctx, seiAddr, denom).Amount
lockedUsei := s.k.BankKeeper().LockedCoins(s.ctx, seiAddr).AmountOf(denom) // LockedCoins doesn't use iterators
usei := allUsei.Sub(lockedUsei)
wei := s.k.BankKeeper().GetWeiBalance(s.ctx, seiAddr)
return usei.Mul(SdkUseiToSweiMultiplier).Add(wei).BigInt()
}

Expand Down

0 comments on commit 3fc8d42

Please sign in to comment.