-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize inscriber and indexing for lock request
- Loading branch information
1 parent
085ba3b
commit 5f71429
Showing
29 changed files
with
493 additions
and
78 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 |
---|---|---|
|
@@ -10,3 +10,6 @@ dist-ssr | |
server/dist | ||
public/dist | ||
TODO | ||
inscriptions/ | ||
*.key | ||
account/ |
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,30 @@ | ||
FROM golang:1.23.1-alpine | ||
|
||
RUN apk add --no-cache bash curl git jq yq ncurses | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
# RUN curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v 2.9.1 | ||
RUN curl https://get.starkli.sh | sh && \ | ||
source /root/.starkli/env && \ | ||
starkliup | ||
ENV PATH="$PATH:/root/.local/bin:/root/.starkli/bin" | ||
|
||
# Copy over the configs | ||
WORKDIR /configs | ||
COPY ./apps/backend/configs/docker.config.yaml /configs/config.yaml | ||
COPY ./apps/backend/configs/docker.script-config.yaml /configs/script-config.yaml | ||
|
||
# Copy over the scripts | ||
WORKDIR /scripts | ||
COPY ./packages/scripts /scripts | ||
|
||
# Copy over the app | ||
WORKDIR /app | ||
COPY ./apps/backend/go.mod ./apps/backend/go.sum ./ | ||
RUN go mod download | ||
COPY ./apps/backend . | ||
|
||
# Build the app & run it | ||
RUN go build -o inscriber ./cmd/inscriber/main.go | ||
|
||
CMD ["./inscriber"] |
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,58 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/keep-starknet-strange/broly/backend/internal/config" | ||
"github.com/keep-starknet-strange/broly/backend/internal/scripts" | ||
"github.com/keep-starknet-strange/broly/backend/routes" | ||
routeutils "github.com/keep-starknet-strange/broly/backend/routes/utils" | ||
) | ||
|
||
func InscriberLockingService() { | ||
for { | ||
sleepTime := 10 | ||
time.Sleep(time.Duration(sleepTime) * time.Second) | ||
|
||
// Query the backend for open inscription requests | ||
backendUrl := "http://" + config.Conf.Api.Host + ":" + strconv.Itoa(config.Conf.Api.Port) + "/inscriptions/get-open-requests" | ||
response, err := http.Get(backendUrl) // TODO: Use pagination | ||
if err != nil { | ||
fmt.Println("Error while querying the backend for open inscription requests") | ||
continue | ||
} | ||
|
||
// Parse the response as Json | ||
responseJson, err := routeutils.ReadJsonDataResponse[[]routes.InscriptionRequest](response) | ||
if err != nil { | ||
fmt.Println("Error while parsing the response as Json") | ||
continue | ||
} | ||
|
||
if len(responseJson.Data) == 0 { | ||
fmt.Println("No open inscription requests") | ||
continue | ||
} | ||
|
||
// TODO: Determine which requests to use | ||
// Lock the inscription request | ||
fmt.Println("Locking inscription request: ", responseJson.Data[0]) | ||
txHash := "0x1234567890" // TODO | ||
err = scripts.LockInscriptionInvokeScript(responseJson.Data[0].InscriptionId, txHash) | ||
if err != nil { | ||
fmt.Println("Error while invoking the lockInscription script") | ||
continue | ||
} | ||
} | ||
} | ||
|
||
func main() { | ||
config.InitConfig() | ||
scripts.InitScriptConfig() | ||
|
||
// TODO: To go routine and run in parallel with InscriberSubmitService | ||
InscriberLockingService() | ||
} |
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 @@ | ||
LockInscriptionScript: /scripts/lock_request.sh |
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 @@ | ||
LockInscriptionScript: ../../packages/scripts/lock_request.sh |
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 @@ | ||
LockInscriptionScript: ../../packages/scripts/lock_request.sh |
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
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,48 @@ | ||
package scripts | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type ScriptConfig struct { | ||
LockInscriptionScript string `yaml:"LockInscriptionScript"` | ||
} | ||
|
||
var Conf *ScriptConfig | ||
|
||
func InitScriptConfig() { | ||
configPath, ok := os.LookupEnv("SCRIPT_CONFIG_PATH") | ||
if !ok { | ||
configPath = "configs/script-config.yaml" | ||
fmt.Println("SCRIPT_CONFIG_PATH not set, using default script-config.yaml") | ||
} | ||
|
||
yamlFile, err := os.ReadFile(configPath) | ||
if err != nil { | ||
fmt.Println("Error reading config file: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = yaml.Unmarshal(yamlFile, &Conf) | ||
if err != nil { | ||
fmt.Println("Error parsing config file: ", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func LockInscriptionInvokeScript(inscriptionId int, txHash string) error { | ||
shellCmd := Conf.LockInscriptionScript | ||
|
||
cmd := exec.Command(shellCmd, strconv.Itoa(inscriptionId), txHash) | ||
_, err := cmd.Output() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return 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
Oops, something went wrong.