From a14e354cc79201290d07d4750b3ad1ed96ab1325 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 5 Apr 2024 16:35:35 +0800 Subject: [PATCH] feat: update flags --- cmd/flags/common.go | 12 ++++++++++++ cmd/flags/driver.go | 16 ---------------- cmd/flags/proposer.go | 2 ++ proposer/config.go | 8 ++++++++ 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/cmd/flags/common.go b/cmd/flags/common.go index 97f322ae0..95a37a01e 100644 --- a/cmd/flags/common.go +++ b/cmd/flags/common.go @@ -47,6 +47,18 @@ var ( Required: true, Category: commonCategory, } + L2AuthEndpoint = &cli.StringFlag{ + Name: "l2.auth", + Usage: "Authenticated HTTP RPC endpoint of a L2 taiko-geth execution engine", + Required: true, + Category: commonCategory, + } + JWTSecret = &cli.StringFlag{ + Name: "jwtSecret", + Usage: "Path to a JWT secret to use for authenticated RPC endpoints", + Required: true, + Category: commonCategory, + } TaikoL1Address = &cli.StringFlag{ Name: "taikoL1", Usage: "TaikoL1 contract `address`", diff --git a/cmd/flags/driver.go b/cmd/flags/driver.go index bfbfdb6a3..ef52c69fc 100644 --- a/cmd/flags/driver.go +++ b/cmd/flags/driver.go @@ -6,22 +6,6 @@ import ( "github.com/urfave/cli/v2" ) -// Flags used by driver. -var ( - L2AuthEndpoint = &cli.StringFlag{ - Name: "l2.auth", - Usage: "Authenticated HTTP RPC endpoint of a L2 taiko-geth execution engine", - Required: true, - Category: driverCategory, - } - JWTSecret = &cli.StringFlag{ - Name: "jwtSecret", - Usage: "Path to a JWT secret to use for authenticated RPC endpoints", - Required: true, - Category: driverCategory, - } -) - // Optional flags used by driver. var ( P2PSyncVerifiedBlocks = &cli.BoolFlag{ diff --git a/cmd/flags/proposer.go b/cmd/flags/proposer.go index 90e99fd70..80754460a 100644 --- a/cmd/flags/proposer.go +++ b/cmd/flags/proposer.go @@ -132,6 +132,8 @@ var ( // ProposerFlags All proposer flags. var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{ L2HTTPEndpoint, + L2AuthEndpoint, + JWTSecret, TaikoTokenAddress, L1ProposerPrivKey, L2SuggestedFeeRecipient, diff --git a/proposer/config.go b/proposer/config.go index 644b16df2..bd5215abb 100644 --- a/proposer/config.go +++ b/proposer/config.go @@ -15,6 +15,7 @@ import ( "github.com/taikoxyz/taiko-client/cmd/flags" pkgFlags "github.com/taikoxyz/taiko-client/pkg/flags" + "github.com/taikoxyz/taiko-client/pkg/jwt" "github.com/taikoxyz/taiko-client/pkg/rpc" ) @@ -47,6 +48,11 @@ type Config struct { // NewConfigFromCliContext initializes a Config instance from // command line flags. 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) + } + l1ProposerPrivKey, err := crypto.ToECDSA( common.Hex2Bytes(c.String(flags.L1ProposerPrivKey.Name)), ) @@ -84,6 +90,8 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { L2Endpoint: c.String(flags.L2HTTPEndpoint.Name), 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), TaikoTokenAddress: common.HexToAddress(c.String(flags.TaikoTokenAddress.Name)), Timeout: c.Duration(flags.RPCTimeout.Name), },