Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of github.com:filecoin-project/saturn-l2 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzo committed Jul 26, 2022
2 parents 71b26e6 + 0621741 commit e49d7ad
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
# Dependency directories (remove the comment below to include it)
# vendor/

dist/
# Resources directory
resources
!resources/resources.go
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ WebUI: http://localhost:52860/webui
```

If you want to connect to `WebUI`, also run `./scripts/download-webui.sh`.

Note that the the Saturn L2 node only binds to the **localhost** loopback network interface and so will only be reachable from the same machine.
In the above snippet, `52860` is the port that the Saturn L2 node binds to on the localhost interface. This port can be configured using the `PORT` environment variable as mentioned above.
Expand Down
33 changes: 28 additions & 5 deletions cmd/saturn-l2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -148,10 +149,10 @@ func mkConfig() (config, error) {
// parse FIL address
filAddr := os.Getenv(FIL_ADDRESS_VAR)
if filAddr == "" {
return config{}, errors.New("No FIL_WALLET_ADDRESS provided. Please set the environment variable.\n")
return config{}, fmt.Errorf("No %s provided. Please set the environment variable.\n", FIL_ADDRESS_VAR)
}
if _, err := address.NewFromString(filAddr); err != nil {
return config{}, fmt.Errorf("Invalid FIL_WALLET_ADDRESS format: %w", err)
return config{}, fmt.Errorf("Invalid %s format: %w", FIL_ADDRESS_VAR, err)
}

// parse max disk space
Expand All @@ -170,10 +171,11 @@ func mkConfig() (config, error) {
}
}

rootDirStr := os.Getenv(ROOT_DIR_ENV_VAR)
if rootDirStr == "" {
return config{}, errors.New("No ROOT_DIR provided. Please set the environment variable.")
rootDirStr, err := getRootDir()
if err != nil {
return config{}, err
}
fmt.Printf("Using root dir %s\n", rootDirStr)

return config{
Port: port,
Expand Down Expand Up @@ -283,3 +285,24 @@ func newDatastore(dir string) (ds.Batching, error) {
}
return dstore, nil
}

func getRootDir() (string, error) {
if dir := os.Getenv(ROOT_DIR_ENV_VAR); dir != "" {
abs, _ := filepath.Abs(dir)
return abs, nil
}

if runtime.GOOS == "windows" {
if localAppData := os.Getenv("LOCALAPPDATA"); localAppData != "" {
return localAppData + "/saturn", nil
}

return "", errors.New("invalid Windows environment: LOCALAPPDATA is not set")
}

if home := os.Getenv("HOME"); home != "" {
return home + "/.saturn", nil
}

return "", errors.New("invalid environment: HOME is not set")
}
2 changes: 1 addition & 1 deletion scripts/download-webui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ echo "⇣ Downloading webui dist to $OUTDIR ⇣"
mkdir -p $OUTDIR

# Downloads latest release
url=$(curl -s https://api.github.com/repos/filecoin-project/saturn-webui/releases/latest | \
url=$(curl -s https://api.github.com/repos/filecoin-saturn/saturn-webui/releases/latest | \
jq -r '.assets[] | select(.name|match("saturn-webui.tar.gz$")) | .browser_download_url')

curl -L $url | tar -zx -C $OUTDIR

0 comments on commit e49d7ad

Please sign in to comment.