Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Announcement/Launch ready #240

Merged
merged 5 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ init-infra-prod:
@echo "Initializing infra..."
curl https://api.art-peace.net/init-canvas -X POST
curl https://api.art-peace.net/init-quests -X POST -d "@configs/production-quests.config.json"

update-frontend-contracts:
cat onchain/target/dev/art_peace_ArtPeace.contract_class.json| jq -r '.abi' > frontend/src/contracts/art_peace.abi.json
cat onchain/target/dev/art_peace_CanvasNFT.contract_class.json| jq -r '.abi' > frontend/src/contracts/canvas_nft.abi.json
cat onchain/target/dev/art_peace_UsernameStore.contract_class.json| jq -r '.abi' > frontend/src/contracts/username_store.abi.json
10 changes: 10 additions & 0 deletions backend/config/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ type BackendScriptsConfig struct {
AddTemplateDevnet string `json:"add_template_devnet"`
ClaimTodayQuestDevnet string `json:"claim_today_quest_devnet"`
MintNFTDevnet string `json:"mint_nft_devnet"`
LikeNFTDevnet string `json:"like_nft_devnet"`
UnlikeNFTDevnet string `json:"unlike_nft_devnet"`
VoteColorDevnet string `json:"vote_color_devnet"`
NewUsernameDevnet string `json:"new_username_devnet"`
ChangeUsernameDevnet string `json:"change_username_devnet"`
IncreaseDayDevnet string `json:"increase_day_devnet"`
JoinChainFactionDevnet string `json:"join_chain_faction_devnet"`
JoinFactionDevnet string `json:"join_faction_devnet"`
LeaveFactionDevnet string `json:"leave_faction_devnet"`
}

type WebSocketConfig struct {
Expand Down Expand Up @@ -48,10 +53,15 @@ var DefaultBackendConfig = BackendConfig{
AddTemplateDevnet: "../scripts/add_template.sh",
ClaimTodayQuestDevnet: "../scripts/claim_today_quest.sh",
MintNFTDevnet: "../scripts/mint_nft.sh",
LikeNFTDevnet: "../scripts/like_nft.sh",
UnlikeNFTDevnet: "../scripts/unlike_nft.sh",
VoteColorDevnet: "../scripts/vote_color.sh",
NewUsernameDevnet: "../scripts/new_username.sh",
ChangeUsernameDevnet: "../scripts/change_username.sh",
IncreaseDayDevnet: "../scripts/increase_day_index.sh",
JoinChainFactionDevnet: "../scripts/join_chain_faction.sh",
JoinFactionDevnet: "../scripts/join_faction.sh",
LeaveFactionDevnet: "../scripts/leave_faction.sh",
},
Production: false,
WebSocket: WebSocketConfig{
Expand Down
31 changes: 31 additions & 0 deletions backend/quests/claim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package quests

import "github.com/keep-starknet-strange/art-peace/backend/core"

var QuestClaimData = map[int]func(*Quest, string) []int{
NFTMintQuestType: NFTMintQuestClaimData,
}

func (q *Quest) GetQuestClaimData(user string) []int {
if f, ok := QuestClaimData[q.Type]; ok {
return f(q, user)
}
return nil
}

func NFTMintQuestClaimData(q *Quest, user string) []int {
nftQuestInputs := NewNFTQuestInputs(q.InputData)
if nftQuestInputs.IsDaily {
tokenId, err := core.PostgresQueryOne[int]("SELECT token_id FROM NFTs WHERE minter = $1 AND day_index = $2", user, nftQuestInputs.ClaimDay)
if err != nil {
return nil
}
return []int{*tokenId}
} else {
tokenId, err := core.PostgresQueryOne[int]("SELECT token_id FROM NFTs WHERE minter = $1", user)
if err != nil {
return nil
}
return []int{*tokenId}
}
}
12 changes: 12 additions & 0 deletions backend/quests/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type HodlQuestInputs struct {
Amount int
}

type NFTQuestInputs struct {
IsDaily bool
ClaimDay uint32
}

func NewPixelQuestInputs(encodedInputs []int) *PixelQuestInputs {
return &PixelQuestInputs{
PixelsNeeded: uint32(encodedInputs[0]),
Expand All @@ -37,3 +42,10 @@ func NewHodlQuestInputs(encodedInputs []int) *HodlQuestInputs {
Amount: encodedInputs[0],
}
}

func NewNFTQuestInputs(encodedInputs []int) *NFTQuestInputs {
return &NFTQuestInputs{
IsDaily: encodedInputs[0] == 1,
ClaimDay: uint32(encodedInputs[1]),
}
}
22 changes: 12 additions & 10 deletions backend/quests/quests.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ const (
TemplateQuestType
UnruggableQuestType
VoteQuestType
ChainFactionQuestType
FactionQuestType
UsernameQuestType
)

var OnchainQuestTypes = map[string]int{
"AuthorityQuest": AuthorityQuestType,
"HodlQuest": HodlQuestType,
"NFTMintQuest": NFTMintQuestType,
"PixelQuest": PixelQuestType,
"RainbowQuest": RainbowQuestType,
"TemplateQuest": TemplateQuestType,
"UnruggableQuest": UnruggableQuestType,
"VoteQuest": VoteQuestType,
"FactionQuest": FactionQuestType,
"UsernameQuest": UsernameQuestType,
"AuthorityQuest": AuthorityQuestType,
"HodlQuest": HodlQuestType,
"NFTMintQuest": NFTMintQuestType,
"PixelQuest": PixelQuestType,
"RainbowQuest": RainbowQuestType,
"TemplateQuest": TemplateQuestType,
"UnruggableQuest": UnruggableQuestType,
"VoteQuest": VoteQuestType,
"ChainFactionQuest": ChainFactionQuestType,
"FactionQuest": FactionQuestType,
"UsernameQuest": UsernameQuestType,
}

type Quest struct {
Expand Down
48 changes: 33 additions & 15 deletions backend/quests/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
)

var QuestChecks = map[int]func(*Quest, string) (int, int){
AuthorityQuestType: CheckAuthorityStatus,
HodlQuestType: CheckHodlStatus,
NFTMintQuestType: CheckNftStatus,
PixelQuestType: CheckPixelStatus,
RainbowQuestType: CheckRainbowStatus,
TemplateQuestType: CheckTemplateStatus,
UnruggableQuestType: CheckUnruggableStatus,
VoteQuestType: CheckVoteStatus,
FactionQuestType: CheckFactionStatus,
UsernameQuestType: CheckUsernameStatus,
AuthorityQuestType: CheckAuthorityStatus,
HodlQuestType: CheckHodlStatus,
NFTMintQuestType: CheckNftStatus,
PixelQuestType: CheckPixelStatus,
RainbowQuestType: CheckRainbowStatus,
TemplateQuestType: CheckTemplateStatus,
UnruggableQuestType: CheckUnruggableStatus,
VoteQuestType: CheckVoteStatus,
FactionQuestType: CheckFactionStatus,
ChainFactionQuestType: CheckChainFactionStatus,
UsernameQuestType: CheckUsernameStatus,
}

func (q *Quest) CheckStatus(user string) (progress int, needed int) {
Expand All @@ -41,12 +42,20 @@ func CheckHodlStatus(q *Quest, user string) (progress int, needed int) {
}

func CheckNftStatus(q *Quest, user string) (progress int, needed int) {
nfts_minted_by_user, err := core.PostgresQueryOne[int]("SELECT COUNT(*) FROM NFTs WHERE minter = $1", user)

if err != nil {
return 0, 1
nftQuestInputs := NewNFTQuestInputs(q.InputData)
if nftQuestInputs.IsDaily {
nfts_minted_by_user, err := core.PostgresQueryOne[int]("SELECT COUNT(*) FROM NFTs WHERE minter = $1 AND day_index = $2", user, nftQuestInputs.ClaimDay)
if err != nil {
return 0, 1
}
return *nfts_minted_by_user, 1
} else {
nfts_minted_by_user, err := core.PostgresQueryOne[int]("SELECT COUNT(*) FROM NFTs WHERE minter = $1", user)
if err != nil {
return 0, 1
}
return *nfts_minted_by_user, 1
}
return *nfts_minted_by_user, 1
}

func CheckPixelStatus(q *Quest, user string) (progress int, needed int) {
Expand Down Expand Up @@ -95,6 +104,15 @@ func CheckVoteStatus(q *Quest, user string) (progress int, needed int) {
return *count, 1
}

func CheckChainFactionStatus(q *Quest, user string) (progress int, needed int) {
count, err := core.PostgresQueryOne[int]("SELECT COUNT(*) FROM ChainFactionMembersInfo WHERE user_address = $1", user)
if err != nil {
return 0, 1
}

return *count, 1
}

func CheckFactionStatus(q *Quest, user string) (progress int, needed int) {
count, err := core.PostgresQueryOne[int]("SELECT COUNT(*) FROM FactionMembersInfo WHERE user_address = $1", user)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions backend/routes/contract.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package routes

import (
"encoding/json"
"io"
"net/http"
"os"
"strconv"

"github.com/keep-starknet-strange/art-peace/backend/core"
routeutils "github.com/keep-starknet-strange/art-peace/backend/routes/utils"
)

func InitContractRoutes() {
http.HandleFunc("/get-contract-address", getContractAddress)
http.HandleFunc("/set-contract-address", setContractAddress)
http.HandleFunc("/get-game-data", getGameData)
}

func getContractAddress(w http.ResponseWriter, r *http.Request) {
Expand All @@ -33,3 +37,39 @@ func setContractAddress(w http.ResponseWriter, r *http.Request) {
os.Setenv("ART_PEACE_CONTRACT_ADDRESS", string(data))
routeutils.WriteResultJson(w, "Contract address set")
}

type GameData struct {
Day int `json:"day"`
EndTime int `json:"endTime"`
}

func getGameData(w http.ResponseWriter, r *http.Request) {
day, err := core.PostgresQueryOne[int](`SELECT day_index from days ORDER BY day_index DESC LIMIT 1`)
if err != nil {
routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to get day")
return
}

endTime := os.Getenv("ART_PEACE_END_TIME")
if endTime == "" {
routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to get end time")
return
}
endTimeInt, err := strconv.Atoi(endTime)
if err != nil {
routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to convert end time to int")
return
}

gameData := GameData{
Day: *day,
EndTime: endTimeInt,
}
jsonGameData, err := json.Marshal(gameData)
if err != nil {
routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to marshal game data")
return
}

routeutils.WriteDataJson(w, string(jsonGameData))
}
Loading