Fixed concurrent write to blockchain status map

This commit is contained in:
Ivan Belyakov 2023-06-28 15:39:13 +02:00 committed by IvanBelyakoff
parent b058ab41da
commit 1efecbf73b
1 changed files with 5 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package wallet
import ( import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"sync"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -59,7 +60,11 @@ func NewService(
Publisher: walletFeed, Publisher: walletFeed,
} }
blockchainStatus := make(map[uint64]string) blockchainStatus := make(map[uint64]string)
mutex := sync.Mutex{}
rpcClient.SetWalletNotifier(func(chainID uint64, message string) { rpcClient.SetWalletNotifier(func(chainID uint64, message string) {
mutex.Lock()
defer mutex.Unlock()
if len(blockchainStatus) == 0 { if len(blockchainStatus) == 0 {
networks, err := rpcClient.NetworkManager.Get(false) networks, err := rpcClient.NetworkManager.Get(false)
if err != nil { if err != nil {