-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from keep-starknet-strange/refactor-for-contri…
…butors Refactor and Docker integration
- Loading branch information
Showing
91 changed files
with
2,788 additions
and
979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,9 @@ node_modules/ | |
# Development | ||
**/TODO | ||
|
||
# TODO | ||
# Frontend | ||
build/ | ||
node_modules/ | ||
|
||
# Backend | ||
art-peace-backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM golang:1.21.7-alpine | ||
# TODO: Add psql to the image? | ||
# TODO: depends on in docker compose? | ||
|
||
RUN apk add --no-cache bash curl git jq | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
RUN curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v 2.6.3 | ||
RUN curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | bash | ||
# TODO: Source not working properly & requiring manual /root/.local/bin/ paths | ||
RUN source /root/.profile | ||
RUN /bin/bash /root/.local/bin/snfoundryup --version 0.20.0 | ||
|
||
# Copy over the configs | ||
WORKDIR /configs | ||
COPY ./configs/ . | ||
COPY ./configs/docker-database.config.json ./database.config.json | ||
COPY ./configs/docker-backend.config.json ./backend.config.json | ||
|
||
# Copy over the scripts | ||
WORKDIR /scripts | ||
COPY ./tests/integration/docker/ . | ||
|
||
# Copy over the app | ||
WORKDIR /app | ||
COPY ./backend/go.mod ./backend/go.sum ./ | ||
RUN go mod download | ||
COPY ./backend . | ||
|
||
# Build the app & run it | ||
RUN go build -o main . | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["./main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# art/peace Backend | ||
|
||
This directory contains the Go backend for `art/peace`, which provides routes for managing and retrieving `art/peace` info from the Redis and Postgres DBs. Also contains other utilities to do things like get the contract address, use devnet transaction invoke scripts for easy devnet testing, maintain websocket connections for pixel updates, and more. | ||
|
||
## Running | ||
|
||
``` | ||
go run main.go | ||
``` | ||
|
||
## Build | ||
|
||
``` | ||
go mod download | ||
go build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
) | ||
|
||
type BackendScriptsConfig struct { | ||
PlacePixelDevnet string `json:"place_pixel_devnet"` | ||
AddTemplateHashDevnet string `json:"add_template_hash_devnet"` | ||
} | ||
|
||
type BackendConfig struct { | ||
Host string `json:"host"` | ||
Port int `json:"port"` | ||
Scripts BackendScriptsConfig `json:"scripts"` | ||
} | ||
|
||
var DefaultBackendConfig = BackendConfig{ | ||
Host: "localhost", | ||
Port: 8080, | ||
Scripts: BackendScriptsConfig{ | ||
PlacePixelDevnet: "../scripts/place_pixel.sh", | ||
AddTemplateHashDevnet: "../scripts/add_template_hash.sh", | ||
}, | ||
} | ||
|
||
var DefaultBackendConfigPath = "../configs/backend.config.json" | ||
|
||
func LoadBackendConfig(backendConfigPath string) (*BackendConfig, error) { | ||
file, err := os.Open(backendConfigPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
|
||
decoder := json.NewDecoder(file) | ||
config := BackendConfig{} | ||
err = decoder.Decode(&config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package routes | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func InitContractRoutes() { | ||
http.HandleFunc("/getContractAddress", getContractAddress) | ||
http.HandleFunc("/setContractAddress", setContractAddress) | ||
} | ||
|
||
func getContractAddress(w http.ResponseWriter, r *http.Request) { | ||
contractAddress := os.Getenv("ART_PEACE_CONTRACT_ADDRESS") | ||
w.Write([]byte(contractAddress)) | ||
} | ||
|
||
func setContractAddress(w http.ResponseWriter, r *http.Request) { | ||
// TODO: Add authentication | ||
data, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
w.WriteHeader(http.StatusBadRequest) | ||
w.Write([]byte("Invalid request")) | ||
return | ||
} | ||
os.Setenv("ART_PEACE_CONTRACT_ADDRESS", string(data)) | ||
w.Write([]byte("Contract address set successfully")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.