forked from taikoxyz/taiko-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
76 lines (66 loc) · 2.26 KB
/
config.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
package driver
import (
"errors"
"fmt"
"net/url"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli/v2"
"github.com/taikoxyz/taiko-client/cmd/flags"
"github.com/taikoxyz/taiko-client/pkg/jwt"
"github.com/taikoxyz/taiko-client/pkg/rpc"
)
// Config contains the configurations to initialize a Taiko driver.
type Config struct {
*rpc.ClientConfig
P2PSyncVerifiedBlocks bool
P2PSyncTimeout time.Duration
RetryInterval time.Duration
MaxExponent uint64
BlobServerEndpoint *url.URL
}
// NewConfigFromCliContext creates a new config instance from
// the command line inputs.
func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
jwtSecret, err := jwt.ParseSecretFromFile(c.String(flags.JWTSecret.Name))
if err != nil {
return nil, fmt.Errorf("invalid JWT secret file: %w", err)
}
var (
p2pSyncVerifiedBlocks = c.Bool(flags.P2PSyncVerifiedBlocks.Name)
l2CheckPoint = c.String(flags.CheckPointSyncURL.Name)
)
if p2pSyncVerifiedBlocks && len(l2CheckPoint) == 0 {
return nil, errors.New("empty L2 check point URL")
}
if !c.IsSet(flags.L1BeaconEndpoint.Name) {
return nil, errors.New("empty L1 beacon endpoint")
}
var blobServerEndpoint *url.URL
if c.IsSet(flags.BlobServerEndpoint.Name) {
if blobServerEndpoint, err = url.Parse(
c.String(flags.BlobServerEndpoint.Name),
); err != nil {
return nil, err
}
}
var timeout = c.Duration(flags.RPCTimeout.Name)
return &Config{
ClientConfig: &rpc.ClientConfig{
L1Endpoint: c.String(flags.L1WSEndpoint.Name),
L1BeaconEndpoint: c.String(flags.L1BeaconEndpoint.Name),
L2Endpoint: c.String(flags.L2WSEndpoint.Name),
L2CheckPoint: l2CheckPoint,
TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)),
TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)),
L2EngineEndpoint: c.String(flags.L2AuthEndpoint.Name),
JwtSecret: string(jwtSecret),
Timeout: timeout,
},
RetryInterval: c.Duration(flags.BackOffRetryInterval.Name),
P2PSyncVerifiedBlocks: p2pSyncVerifiedBlocks,
P2PSyncTimeout: c.Duration(flags.P2PSyncTimeout.Name),
MaxExponent: c.Uint64(flags.MaxExponent.Name),
BlobServerEndpoint: blobServerEndpoint,
}, nil
}