/
maintainer.go
85 lines (74 loc) · 1.82 KB
/
maintainer.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package cmd
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/keep-network/keep-core/config"
"github.com/keep-network/keep-core/pkg/bitcoin/electrum"
"github.com/keep-network/keep-core/pkg/chain/ethereum"
"github.com/keep-network/keep-core/pkg/maintainer"
)
// MaintainerCommand contains the definition of the maintainer command-line
// subcommand.
var MaintainerCommand = &cobra.Command{
Use: "maintainer",
Short: `(experimental) Starts maintainers`,
Long: `(experimental) The maintainer command starts maintainers`,
PreRun: func(cmd *cobra.Command, args []string) {
if err := clientConfig.ReadConfig(
configFilePath,
cmd.Flags(),
config.MaintainerCategories...,
); err != nil {
logger.Fatalf("error reading config: %v", err)
}
},
RunE: maintainers,
}
func init() {
initFlags(
MaintainerCommand,
&configFilePath,
clientConfig,
config.MaintainerCategories...,
)
}
// maintainers initializes maintainer tasks specified by flags passed to the
// maintainer command.
func maintainers(cmd *cobra.Command, args []string) error {
ctx := context.Background()
btcChain, err := electrum.Connect(ctx, clientConfig.Bitcoin.Electrum)
if err != nil {
return fmt.Errorf("could not connect to Electrum chain: [%v]", err)
}
btcDiffChain, err := ethereum.ConnectBitcoinDifficulty(
ctx,
clientConfig.Ethereum,
clientConfig.Maintainer,
)
if err != nil {
return fmt.Errorf(
"could not connect to Bitcoin difficulty chain: [%v]",
err,
)
}
_, tbtcChain, _, _, _, err := ethereum.Connect(
ctx,
clientConfig.Ethereum,
)
if err != nil {
return fmt.Errorf(
"could not connect to tBTC chain: [%v]",
err,
)
}
maintainer.Initialize(
ctx,
clientConfig.Maintainer,
btcChain,
btcDiffChain,
tbtcChain,
)
<-ctx.Done()
return fmt.Errorf("unexpected context cancellation")
}