forked from Lilypad-Tech/lilypad-v0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (48 loc) · 1.25 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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"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 main() {
ctx := log.Logger.WithContext(context.Background())
lvl := zerolog.InfoLevel
if level, found := os.LookupEnv("LOG_LEVEL"); found {
var err error
lvl, err = zerolog.ParseLevel(level)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
}
zerolog.SetGlobalLevel(lvl)
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
defer cancel()
repo, err := bridge.NewSQLiteRepository(ctx, "lilypad.sqlite")
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())
}
}