From d41beaea3f8bec1f2df2c3dd7b68154dd6ad17ae Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Thu, 16 Jan 2025 09:07:25 -0600 Subject: [PATCH] round number on indexer --- backend/routes/indexer/nft.go | 4 +++- backend/routes/indexer/pixel.go | 9 +++++++-- backend/routes/pixel.go | 9 +++++++-- backend/video/video.go | 4 +++- .../templates/consumer/consumer-configmap.yaml | 1 + infra/art-peace-infra/values.yaml | 1 + 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/backend/routes/indexer/nft.go b/backend/routes/indexer/nft.go index 7cfe7196..0403919a 100644 --- a/backend/routes/indexer/nft.go +++ b/backend/routes/indexer/nft.go @@ -90,7 +90,9 @@ func processNFTMintedEvent(event IndexerEvent) { // Load image from redis ctx := context.Background() - canvas, err := core.ArtPeaceBackend.Databases.Redis.Get(ctx, "canvas").Result() + roundNumber := core.ArtPeaceBackend.CanvasConfig.Round + canvasKey := fmt.Sprintf("canvas-%d", roundNumber) + canvas, err := core.ArtPeaceBackend.Databases.Redis.Get(ctx, canvasKey).Result() if err != nil { PrintIndexerError("processNFTMintedEvent", "Error getting canvas from redis", tokenIdLowHex, tokenIdHighHex, positionHex, widthHex, heightHex, nameHex, imageHashHex, blockNumberHex, minter) return diff --git a/backend/routes/indexer/pixel.go b/backend/routes/indexer/pixel.go index 5bfa6e01..51ebedf2 100644 --- a/backend/routes/indexer/pixel.go +++ b/backend/routes/indexer/pixel.go @@ -2,6 +2,7 @@ package indexer import ( "context" + "fmt" "strconv" "github.com/keep-starknet-strange/art-peace/backend/core" @@ -46,7 +47,9 @@ func processPixelPlacedEvent(event IndexerEvent) { pos := uint(position) * core.ArtPeaceBackend.CanvasConfig.ColorsBitWidth ctx := context.Background() - err = core.ArtPeaceBackend.Databases.Redis.BitField(ctx, "canvas", "SET", bitfieldType, pos, color).Err() + roundNumber := core.ArtPeaceBackend.CanvasConfig.Round + canvasKey := fmt.Sprintf("canvas-%d", roundNumber) + err = core.ArtPeaceBackend.Databases.Redis.BitField(ctx, canvasKey, "SET", bitfieldType, pos, color).Err() if err != nil { PrintIndexerError("processPixelPlacedEvent", "Error setting pixel in redis", address, posHex, dayIdxHex, colorHex) return @@ -98,7 +101,9 @@ func revertPixelPlacedEvent(event IndexerEvent) { pos := uint(position) * core.ArtPeaceBackend.CanvasConfig.ColorsBitWidth ctx := context.Background() - err = core.ArtPeaceBackend.Databases.Redis.BitField(ctx, "canvas", "SET", bitfieldType, pos, oldColor).Err() + roundNumber := core.ArtPeaceBackend.CanvasConfig.Round + canvasKey := fmt.Sprintf("canvas-%d", roundNumber) + err = core.ArtPeaceBackend.Databases.Redis.BitField(ctx, canvasKey, "SET", bitfieldType, pos, oldColor).Err() if err != nil { PrintIndexerError("revertPixelPlacedEvent", "Error resetting pixel in redis", address, posHex) return diff --git a/backend/routes/pixel.go b/backend/routes/pixel.go index 223e42fb..6b2bcd06 100644 --- a/backend/routes/pixel.go +++ b/backend/routes/pixel.go @@ -2,6 +2,7 @@ package routes import ( "context" + "fmt" "net/http" "os" "os/exec" @@ -39,7 +40,9 @@ func getPixel(w http.ResponseWriter, r *http.Request) { pos := uint(position) * core.ArtPeaceBackend.CanvasConfig.ColorsBitWidth ctx := context.Background() - val, err := core.ArtPeaceBackend.Databases.Redis.BitField(ctx, "canvas", "GET", bitfieldType, pos).Result() + roundNumber := core.ArtPeaceBackend.CanvasConfig.Round + canvasKey := fmt.Sprintf("canvas-%d", roundNumber) + val, err := core.ArtPeaceBackend.Databases.Redis.BitField(ctx, canvasKey, "GET", bitfieldType, pos).Result() if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Error getting pixel") return @@ -215,7 +218,9 @@ func placePixelRedis(w http.ResponseWriter, r *http.Request) { pos := position * core.ArtPeaceBackend.CanvasConfig.ColorsBitWidth ctx := context.Background() - err = core.ArtPeaceBackend.Databases.Redis.BitField(ctx, "canvas", "SET", bitfieldType, pos, color).Err() + roundNumber := core.ArtPeaceBackend.CanvasConfig.Round + canvasKey := fmt.Sprintf("canvas-%d", roundNumber) + err = core.ArtPeaceBackend.Databases.Redis.BitField(ctx, canvasKey, "SET", bitfieldType, pos, color).Err() if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Error setting pixel on redis") return diff --git a/backend/video/video.go b/backend/video/video.go index d98ded8f..b18da185 100644 --- a/backend/video/video.go +++ b/backend/video/video.go @@ -42,11 +42,13 @@ func GenerateImageFromCanvas(orderId int) { } generatedImage := image.NewRGBA(image.Rect(0, 0, canvasWidth, canvasHeight)) bitfieldType := "u" + strconv.Itoa(int(core.ArtPeaceBackend.CanvasConfig.ColorsBitWidth)) + roundNumber := core.ArtPeaceBackend.CanvasConfig.Round + canvasKey := fmt.Sprintf("canvas-%d", roundNumber) for y := 0; y < canvasHeight; y++ { for x := 0; x < canvasWidth; x++ { position := y*canvasWidth + x pos := position * int(colorWidth) - val, err := core.ArtPeaceBackend.Databases.Redis.BitField(ctx, "canvas", "GET", bitfieldType, pos).Result() + val, err := core.ArtPeaceBackend.Databases.Redis.BitField(ctx, canvasKey, "GET", bitfieldType, pos).Result() if err != nil { fmt.Println("Failed to get bitfield value. Error: ", err) return diff --git a/infra/art-peace-infra/templates/consumer/consumer-configmap.yaml b/infra/art-peace-infra/templates/consumer/consumer-configmap.yaml index ca138855..6dd73bcd 100644 --- a/infra/art-peace-infra/templates/consumer/consumer-configmap.yaml +++ b/infra/art-peace-infra/templates/consumer/consumer-configmap.yaml @@ -8,3 +8,4 @@ data: ART_PEACE_CONTRACT_ADDRESS: {{ .Values.contracts.artPeace }} USERNAME_STORE_CONTRACT_ADDRESS: {{ .Values.contracts.usernameStore }} POSTGRES_PASSWORD: {{ .Values.postgres.password }} + ROUND_NUMBER: {{ .Values.contracts.roundNumber }} diff --git a/infra/art-peace-infra/values.yaml b/infra/art-peace-infra/values.yaml index f9ff4169..84a8b77e 100644 --- a/infra/art-peace-infra/values.yaml +++ b/infra/art-peace-infra/values.yaml @@ -90,3 +90,4 @@ contracts: nft: 0x042dbc0bbdb0faaad99d0b116d0105f9e213ac0d2faf75c878f49d69b544befb host: "05bd7adfE8AfaA58300aDC72bF5584b191E236987Fe16A217b1a3e067869A0Aa" end: "1727769600" + roundNumber: "2"