fix: protect OpenSea instances with a mutex

This commit is contained in:
Dario Gabriel Lipicar 2023-06-27 10:11:41 -03:00 committed by dlipicar
parent b8b402da8d
commit afb9621f01
1 changed files with 4 additions and 0 deletions

View File

@ -46,6 +46,7 @@ func getbaseURL(chainID uint64) (string, error) {
}
var OpenseaClientInstances = make(map[uint64]*Client)
var OpenseaClientInstancesLock = sync.RWMutex{}
var OpenseaHTTPClient *HTTPClient = nil
type TraitValue string
@ -247,6 +248,9 @@ type Client struct {
// new opensea client.
func NewOpenseaClient(chainID uint64, apiKey string, feed *event.Feed) (*Client, error) {
OpenseaClientInstancesLock.Lock()
defer OpenseaClientInstancesLock.Unlock()
if OpenseaHTTPClient == nil {
OpenseaHTTPClient = newHTTPClient()
}