Skip to content

Commit 7642877

Browse files
committed
add a mutex
1 parent 010dfa6 commit 7642877

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/trapri/item_received_bid.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package trapri
33
import (
44
"math/big"
55
"strings"
6+
"sync"
67
"time"
78

89
"github.com/benleb/gloomberg/internal/gbl"
@@ -15,7 +16,10 @@ import (
1516
"github.com/ethereum/go-ethereum/common"
1617
)
1718

18-
var tokenTopBids = map[string]*models.ItemReceivedBid{}
19+
var (
20+
tokenTopBids = map[string]*models.ItemReceivedBid{}
21+
tokenTopBidsMutex = &sync.Mutex{}
22+
)
1923

2024
func HandleItemReceivedBid(gb *gloomberg.Gloomberg, event *models.ItemReceivedBid) {
2125
nftID := event.Payload.Item.NftID
@@ -34,9 +38,11 @@ func HandleItemReceivedBid(gb *gloomberg.Gloomberg, event *models.ItemReceivedBi
3438
highlightBid := false
3539

3640
// check if we already have a top bid for this token and if not, add it
41+
tokenTopBidsMutex.Lock()
3742
if topBid, ok := tokenTopBids[nftID.TID()]; !ok || topBid == nil {
3843
tokenTopBids[nftID.TID()] = event
3944
}
45+
tokenTopBidsMutex.Unlock()
4046

4147
// get the current top bid for this token
4248
topBid := tokenTopBids[nftID.TID()]

0 commit comments

Comments
 (0)