Skip to content

Commit

Permalink
refactor: make GetBalance a method for Account struct
Browse files Browse the repository at this point in the history
  • Loading branch information
kayano committed Sep 13, 2023
1 parent a3476bf commit 08469af
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func GetBalances(accounts []Account, rpcs map[string]string) []Account {

for i := 0; i < num; i++ {
go func(i int) {
account, err := GetBalance(accounts[i], rpcs)
err := accounts[i].GetBalance(rpcs)
if err != nil {
out <- Account{}

log.Error(err.Error(), zap.Any("account", accounts[i]))

return
}
out <- account
out <- accounts[i]
}(i)
}

Expand All @@ -49,23 +49,23 @@ func GetBalances(accounts []Account, rpcs map[string]string) []Account {
return accountsWithBalance
}

func GetBalance(account Account, rpcs map[string]string) (Account, error) {
func (a *Account) GetBalance(rpcs map[string]string) error {
chain, err := chain.PrepChain(chain.Info{
ChainID: account.ChainID,
RPCAddr: rpcs[account.ChainID],
ChainID: a.ChainID,
RPCAddr: rpcs[a.ChainID],
})
if err != nil {
return Account{}, err
return err
}

ctx := context.Background()

coins, err := chain.ChainProvider.QueryBalanceWithAddress(ctx, account.Address)
coins, err := chain.ChainProvider.QueryBalanceWithAddress(ctx, a.Address)
if err != nil {
return Account{}, err
return err
}

account.Balance = coins.AmountOf(account.Denom)
a.Balance = coins.AmountOf(a.Denom)

return account, nil
return nil
}

0 comments on commit 08469af

Please sign in to comment.