Skip to content
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
18 changes: 12 additions & 6 deletions cmd/nitewatch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ func main() {
os.Exit(1)
}

configPath := os.Getenv("NITEWATCH_CONFIG")
if configPath == "" {
configPath = "config.yaml"
}

conf, err := config.Load(configPath)
conf, err := loadConfig()
if err != nil {
slog.Error("Failed to load configuration", "error", err)
os.Exit(1)
Expand All @@ -37,3 +32,14 @@ func main() {
os.Exit(1)
}
}

func loadConfig() (*config.Config, error) {
if raw := os.Getenv("NITEWATCH_CONFIG"); raw != "" {
return config.LoadFromEnv(raw)
}
configPath := os.Getenv("NITEWATCH_CONFIG_PATH")
if configPath == "" {
configPath = "config.yaml"
}
return config.Load(configPath)
}
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ func Load(path string) (*Config, error) {
if err != nil {
return nil, fmt.Errorf("read config file: %w", err)
}
return parse(data)
}

func LoadFromEnv(data string) (*Config, error) {
return parse([]byte(data))
}

func parse(data []byte) (*Config, error) {
expanded := os.ExpandEnv(string(data))

var cfg Config
Expand Down
4 changes: 3 additions & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"sync/atomic"
"time"

Expand Down Expand Up @@ -107,7 +108,8 @@ func NewWithBackend(conf config.Config, client custody.EthBackend) (*Service, er
return nil, fmt.Errorf("failed to get chain ID: %w", err)
}

key, err := crypto.HexToECDSA(conf.Blockchain.PrivateKey)
pk := strings.TrimPrefix(conf.Blockchain.PrivateKey, "0x")
key, err := crypto.HexToECDSA(pk)
if err != nil {
return nil, fmt.Errorf("failed to parse private key: %w", err)
}
Expand Down