Skip to content

Commit

Permalink
round number on indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
b-j-roberts committed Jan 16, 2025
1 parent e0f3ab6 commit d41beae
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion backend/routes/indexer/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions backend/routes/indexer/pixel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package indexer

import (
"context"
"fmt"
"strconv"

"github.com/keep-starknet-strange/art-peace/backend/core"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions backend/routes/pixel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routes

import (
"context"
"fmt"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion backend/video/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
1 change: 1 addition & 0 deletions infra/art-peace-infra/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ contracts:
nft: 0x042dbc0bbdb0faaad99d0b116d0105f9e213ac0d2faf75c878f49d69b544befb
host: "05bd7adfE8AfaA58300aDC72bF5584b191E236987Fe16A217b1a3e067869A0Aa"
end: "1727769600"
roundNumber: "2"

0 comments on commit d41beae

Please sign in to comment.