Skip to content

Commit

Permalink
Merge pull request #266 from keep-starknet-strange/feat/multi-canvas
Browse files Browse the repository at this point in the history
Feat: Multicanvas
  • Loading branch information
b-j-roberts authored Dec 4, 2024
2 parents d3a6b42 + 7025c23 commit b92f1a1
Show file tree
Hide file tree
Showing 73 changed files with 12,130 additions and 7,195 deletions.
1 change: 1 addition & 0 deletions backend/cmd/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func main() {
indexer.InitIndexerRoutes()
routes.InitWebsocketRoutes()
routes.InitNFTStaticRoutes()
routes.InitWorldsStaticRoutes()
indexer.StartMessageProcessor()

core.ArtPeaceBackend.Start(core.ArtPeaceBackend.BackendConfig.ConsumerPort)
Expand Down
16 changes: 16 additions & 0 deletions backend/config/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ type BackendScriptsConfig struct {
LeaveFactionDevnet string `json:"leave_faction_devnet"`
AddFactionTemplateDevnet string `json:"add_faction_template_devnet"`
RemoveFactionTemplateDevnet string `json:"remove_faction_template_devnet"`
CreateCanvasDevnet string `json:"create_canvas_devnet"`
FavoriteWorldDevnet string `json:"favorite_world_devnet"`
UnfavoriteWorldDevnet string `json:"unfavorite_world_devnet"`
PlaceWorldPixelDevnet string `json:"place_world_pixel_devnet"`
AddStencilDevnet string `json:"add_stencil_devnet"`
RemoveStencilDevnet string `json:"remove_stencil_devnet"`
FavoriteStencilDevnet string `json:"favorite_stencil_devnet"`
UnfavoriteStencilDevnet string `json:"unfavorite_stencil_devnet"`
}

type WebSocketConfig struct {
Expand Down Expand Up @@ -66,6 +74,14 @@ var DefaultBackendConfig = BackendConfig{
LeaveFactionDevnet: "../scripts/leave_faction.sh",
AddFactionTemplateDevnet: "../scripts/add_faction_template.sh",
RemoveFactionTemplateDevnet: "../scripts/remove_faction_template.sh",
CreateCanvasDevnet: "../scripts/create_canvas.sh",
FavoriteWorldDevnet: "../scripts/favorite_world.sh",
UnfavoriteWorldDevnet: "../scripts/unfavorite_world.sh",
PlaceWorldPixelDevnet: "../scripts/place_world_pixel.sh",
AddStencilDevnet: "../scripts/add_stencil.sh",
RemoveStencilDevnet: "../scripts/remove_stencil.sh",
FavoriteStencilDevnet: "../scripts/favorite_stencil.sh",
UnfavoriteStencilDevnet: "../scripts/unfavorite_stencil.sh",
},
Production: false,
WebSocket: WebSocketConfig{
Expand Down
25 changes: 25 additions & 0 deletions backend/routes/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routes

import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
Expand All @@ -14,6 +15,8 @@ import (
func InitContractRoutes() {
http.HandleFunc("/get-contract-address", getContractAddress)
http.HandleFunc("/set-contract-address", setContractAddress)
http.HandleFunc("/get-factory-contract-address", getFactoryContractAddress)
http.HandleFunc("/set-factory-contract-address", setFactoryContractAddress)
http.HandleFunc("/get-game-data", getGameData)
}

Expand All @@ -37,6 +40,28 @@ func setContractAddress(w http.ResponseWriter, r *http.Request) {
routeutils.WriteResultJson(w, "Contract address set")
}

func getFactoryContractAddress(w http.ResponseWriter, r *http.Request) {
contractAddress := os.Getenv("CANVAS_FACTORY_CONTRACT_ADDRESS")
routeutils.WriteDataJson(w, "\""+contractAddress+"\"")
}

func setFactoryContractAddress(w http.ResponseWriter, r *http.Request) {
// Only allow admin to set contract address
if routeutils.AdminMiddleware(w, r) {
return
}

data, err := io.ReadAll(r.Body)
if err != nil {
routeutils.WriteErrorJson(w, http.StatusBadRequest, "Failed to read request body")
return
}
fmt.Println("Setting factory contract address to: ", string(data))
os.Setenv("CANVAS_FACTORY_CONTRACT_ADDRESS", string(data))
fmt.Println("Factory contract address set to: ", os.Getenv("CANVAS_FACTORY_CONTRACT_ADDRESS"))
routeutils.WriteResultJson(w, "Factory contract address set")
}

type GameData struct {
Day int `json:"day"`
EndTime int `json:"endTime"`
Expand Down
2 changes: 1 addition & 1 deletion backend/routes/indexer/pixel.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func revertPixelPlacedEvent(event IndexerEvent) {
}

// Delete pixel from postgres ( last one )
_, err = core.ArtPeaceBackend.Databases.Postgres.Exec(context.Background(), "DELETE FROM Pixels WHERE address = $1 AND position = $2 ORDER BY time limit 1", address, position)
_, err = core.ArtPeaceBackend.Databases.Postgres.Exec(context.Background(), "DELETE FROM Pixels WHERE address = $1 AND position = $2 ORDER BY time DESC limit 1", address, position)
if err != nil {
PrintIndexerError("revertPixelPlacedEvent", "Error deleting pixel from postgres", address, posHex)
return
Expand Down
77 changes: 67 additions & 10 deletions backend/routes/indexer/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ const (
chainFactionTemplateAddedEvent = "0x00476f35ea27024c89c1fc05dfad873e9e93419e452ee781e8207e435289a39b"
chainFactionTemplateRemovedEvent = "0x0126718de7cb8b83dfa258eb095bc0ec7a3ef5a2258ebd1ed349551764856c6b"
hostAwardedPixelsEvent = "0x03cab98018a5e38e0cf717d8bed481983eb400f6a1d9ccd34f87050c0f36a32a"
canvasCreatedEvent = "0x0003fddf2e955d6c8fbd5ec6e98da32f7e9ebe7731b86b4ef7de342b165222e0"
canvasHostChangedEvent = "0x00569981649f1a25a7a012ccf216e9c0f807068f8ba4689ee58c2d55df22cc45"
canvasTimerChangedEvent = "0x02e1eccce24e49cc4ab3df0795f173bbe667dd4fddbc52c8af731b4e2ad78cf5"
canvasColorAddedEvent = "0x03e856f8abfe58c8841f552ce76651ebff20c1550d167b3a18b049b7552fe8a2"
canvasPixelPlacedEvent = "0x02adf9f56e1f4e16a3e116f34424bd26cb5fc45363498015b4c007835318f7bb"
canvasBasicPixelPlacedEvent = "0x03066baa9c37a42082799e6bc6426ff7d4dc8a635ed9dfc444d0d3c51e605a6b"
canvasExtraPixelsPlacedEvent = "0x01e42e4d6ca5843bfd4e86e344db6c418b295c23bed38831a7ec9b4a83148830"
canvasHostAwardedUserEvent = "0x01bf6ede8c6c232cee1830a5227fd638383f5af669701289d113492b1d41fda5"
canvasFavoritedEvent = "0x032105bd4f21a32bc92e45a49b30eab9355f7f89619d87e9801628e3acc5b502"
canvasUnfavoritedEvent = "0x014ee6480f95acb4b7286d3a7f95b6033299e66e502cfb4b207ccf088b5f601d"
stencilAddedEvent = "0x03384fcf8ff5c539c31feec6626511aa15ae53dba7459fd3a3c67af615ef6b5d"
stencilRemovedEvent = "0x023c933ed3ee3f94b5b82f8e2e570c8354e6f5036c3a079092ceeed15979e7fa"
stencilFavoritedEvent = "0x007cb4ae927fb597834e194e2c950a2d813461c72f372f78d0610ea246f53017"
stencilUnfavoritedEvent = "0x00a5477c7df6522316b652e56317e69e52429ab43a6772fb6f6c2a574f7e196f"
)

var eventProcessors = map[string](func(IndexerEvent)){
Expand Down Expand Up @@ -113,6 +127,20 @@ var eventProcessors = map[string](func(IndexerEvent)){
chainFactionTemplateAddedEvent: processChainFactionTemplateAddedEvent,
chainFactionTemplateRemovedEvent: processChainFactionTemplateRemovedEvent,
hostAwardedPixelsEvent: processHostAwardedPixelsEvent,
canvasCreatedEvent: processCanvasCreatedEvent,
canvasHostChangedEvent: processCanvasHostChangedEvent,
canvasTimerChangedEvent: processCanvasTimerChangedEvent,
canvasColorAddedEvent: processCanvasColorAddedEvent,
canvasPixelPlacedEvent: processCanvasPixelPlacedEvent,
canvasBasicPixelPlacedEvent: processCanvasBasicPixelPlacedEvent,
canvasExtraPixelsPlacedEvent: processCanvasExtraPixelsPlacedEvent,
canvasHostAwardedUserEvent: processCanvasHostAwardedUserEvent,
canvasFavoritedEvent: processCanvasFavoritedEvent,
canvasUnfavoritedEvent: processCanvasUnfavoritedEvent,
stencilAddedEvent: processStencilAddedEvent,
stencilRemovedEvent: processStencilRemovedEvent,
stencilFavoritedEvent: processStencilFavoritedEvent,
stencilUnfavoritedEvent: processStencilUnfavoritedEvent,
}

var eventReverters = map[string](func(IndexerEvent)){
Expand Down Expand Up @@ -144,18 +172,33 @@ var eventReverters = map[string](func(IndexerEvent)){
chainFactionTemplateAddedEvent: revertChainFactionTemplateAddedEvent,
chainFactionTemplateRemovedEvent: revertChainFactionTemplateRemovedEvent,
hostAwardedPixelsEvent: revertHostAwardedPixelsEvent,
canvasCreatedEvent: revertCanvasCreatedEvent,
canvasHostChangedEvent: revertCanvasHostChangedEvent,
canvasTimerChangedEvent: revertCanvasTimerChangedEvent,
canvasColorAddedEvent: revertCanvasColorAddedEvent,
canvasPixelPlacedEvent: revertCanvasPixelPlacedEvent,
canvasBasicPixelPlacedEvent: revertCanvasBasicPixelPlacedEvent,
canvasExtraPixelsPlacedEvent: revertCanvasExtraPixelsPlacedEvent,
canvasHostAwardedUserEvent: revertCanvasHostAwardedUserEvent,
canvasFavoritedEvent: revertCanvasFavoritedEvent,
canvasUnfavoritedEvent: revertCanvasUnfavoritedEvent,
stencilAddedEvent: revertStencilAddedEvent,
stencilRemovedEvent: revertStencilRemovedEvent,
stencilFavoritedEvent: revertStencilFavoritedEvent,
stencilUnfavoritedEvent: revertStencilUnfavoritedEvent,
}

// TODO: Rethink this ( & look at values before multicanvas PR )
var eventRequiresOrdering = map[string]bool{
newDayEvent: false,
newDayEvent: true,
colorAddedEvent: true,
pixelPlacedEvent: true,
basicPixelPlacedEvent: false,
factionPixelsPlacedEvent: false,
chainFactionPixelsPlacedEvent: false,
extraPixelsPlacedEvent: false,
dailyQuestClaimedEvent: false,
mainQuestClaimedEvent: false,
basicPixelPlacedEvent: true,
factionPixelsPlacedEvent: true,
chainFactionPixelsPlacedEvent: true,
extraPixelsPlacedEvent: true,
dailyQuestClaimedEvent: true,
mainQuestClaimedEvent: true,
voteColorEvent: true,
votableColorAddedEvent: true,
factionCreatedEvent: true,
Expand All @@ -164,17 +207,31 @@ var eventRequiresOrdering = map[string]bool{
factionLeftEvent: true,
chainFactionCreatedEvent: true,
chainFactionJoinedEvent: true,
nftMintedEvent: false,
nftMintedEvent: true,
nftLikedEvent: true,
nftUnlikedEvent: true,
usernameClaimedEvent: false,
usernameClaimedEvent: true,
usernameChangedEvent: true,
nftTransferEvent: true,
factionTemplateAddedEvent: true,
factionTemplateRemovedEvent: true,
chainFactionTemplateAddedEvent: true,
chainFactionTemplateRemovedEvent: true,
hostAwardedPixelsEvent: false,
hostAwardedPixelsEvent: true,
canvasCreatedEvent: true,
canvasHostChangedEvent: true,
canvasTimerChangedEvent: true,
canvasColorAddedEvent: true,
canvasPixelPlacedEvent: true,
canvasBasicPixelPlacedEvent: true,
canvasExtraPixelsPlacedEvent: true,
canvasHostAwardedUserEvent: true,
canvasFavoritedEvent: true,
canvasUnfavoritedEvent: true,
stencilAddedEvent: true,
stencilRemovedEvent: true,
stencilFavoritedEvent: true,
stencilUnfavoritedEvent: true,
}

const (
Expand Down
Loading

0 comments on commit b92f1a1

Please sign in to comment.