From 305b52099460ee76073e75d49b36156814f1b54c Mon Sep 17 00:00:00 2001 From: Anthony Laibe <491074+alaibe@users.noreply.github.com> Date: Thu, 5 Oct 2023 13:55:28 +0200 Subject: [PATCH] fix: token balance --- services/wallet/token/token.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/wallet/token/token.go b/services/wallet/token/token.go index 8c718417e..668460d7f 100644 --- a/services/wallet/token/token.go +++ b/services/wallet/token/token.go @@ -783,7 +783,10 @@ func (tm *Manager) GetBalancesAtByChain(parent context.Context, clients map[uint mu.Unlock() } - for _, client := range clients { + for clientIdx := range clients { + // Keep the reference to the client. DO NOT USE A LOOP, the client will be overridden in the coroutine + client := clients[clientIdx] + ethScanContract, availableAtBlock, err := tm.contractMaker.NewEthScan(client.NetworkID()) if err != nil { log.Error("error scanning contract", "err", err) @@ -832,9 +835,12 @@ func (tm *Manager) GetBalancesAtByChain(parent context.Context, clients map[uint } for accountIdx := range accounts { + // Keep the reference to the account. DO NOT USE A LOOP, the account will be overridden in the coroutine account := accounts[accountIdx] for idx := range tokenChunks { + // Keep the reference to the chunk. DO NOT USE A LOOP, the chunk will be overridden in the coroutine chunk := tokenChunks[idx] + group.Add(func(parent context.Context) error { ctx, cancel := context.WithTimeout(parent, requestTimeout) defer cancel() @@ -855,7 +861,6 @@ func (tm *Manager) GetBalancesAtByChain(parent context.Context, clients map[uint } for idx, token := range chunk { - if !res[idx].Success { continue }