-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
70 lines (59 loc) · 1.62 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/lilypad/pkg/bridge"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func EnvOrDefault(env, defaultValue string) (value string) {
value, found := os.LookupEnv(env)
if !found {
value = defaultValue
}
return
}
func main() {
logType, err := logger.ParseLogMode(EnvOrDefault("LOG_MODE", "default"))
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
logger.ConfigureLogging(logType)
lvl, err := zerolog.ParseLevel(EnvOrDefault("LOG_LEVEL", "INFO"))
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
zerolog.SetGlobalLevel(lvl)
ctx := log.Logger.WithContext(context.Background())
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
defer cancel()
sqliteFileLocation := EnvOrDefault("SQLITE_FILE_LOCATION", "lilypad.sqlite")
repo, err := bridge.NewSQLiteRepository(ctx, sqliteFileLocation)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
addr := common.HexToAddress(os.Getenv("DEPLOYED_CONTRACT_ADDRESS"))
privKey, err := crypto.HexToECDSA(os.Getenv("WALLET_PRIVATE_KEY"))
if err != nil {
fmt.Fprintln(os.Stderr, "WALLET_PRIVATE_KEY: "+err.Error())
return
}
contract, err := bridge.NewContract(addr, privKey)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
workflow := bridge.NewWorkflow(bridge.NewJobRunner(), contract, repo)
err = workflow.Start(ctx)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
}