Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
feat!: better parsing endpoints and flags refactor (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id authored Jun 16, 2023
1 parent dc91cf2 commit 3f3692d
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 187 deletions.
12 changes: 6 additions & 6 deletions cmd/qgb/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func DefaultServicePath(serviceName string) (string, error) {
}

const (
FlagBootstrappers = "p2p-bootstrappers"
FlagP2PListenAddress = "p2p-listen-addr"
FlagP2PNickname = "p2p-nickname"
FlagBootstrappers = "p2p.bootstrappers"
FlagP2PListenAddress = "p2p.listen-addr"
FlagP2PNickname = "p2p.nickname"
)

func AddP2PNicknameFlag(cmd *cobra.Command) {
cmd.Flags().StringP(FlagP2PNickname, "p", "", "Nickname of the p2p private key to use (if not provided, an existing one from the p2p store or a newly generated one will be used)")
cmd.Flags().String(FlagP2PNickname, "", "Nickname of the p2p private key to use (if not provided, an existing one from the p2p store or a newly generated one will be used)")
}

func AddP2PListenAddressFlag(cmd *cobra.Command) {
cmd.Flags().StringP(FlagP2PListenAddress, "q", "/ip4/0.0.0.0/tcp/30000", "MultiAddr for the p2p peer to listen on")
cmd.Flags().String(FlagP2PListenAddress, "/ip4/0.0.0.0/tcp/30000", "MultiAddr for the p2p peer to listen on")
}

func AddBootstrappersFlag(cmd *cobra.Command) {
cmd.Flags().StringP(FlagBootstrappers, "b", "", "Comma-separated multiaddresses of p2p peers to connect to")
cmd.Flags().String(FlagBootstrappers, "", "Comma-separated multiaddresses of p2p peers to connect to")
}
2 changes: 1 addition & 1 deletion cmd/qgb/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Command() *cobra.Command {

encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)

querier := rpc.NewAppQuerier(logger, config.celesGRPC, encCfg)
querier := rpc.NewAppQuerier(logger, config.coreGRPC, encCfg)
err = querier.Start()
if err != nil {
return err
Expand Down
44 changes: 25 additions & 19 deletions cmd/qgb/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deploy

import (
"errors"
"fmt"

"github.com/celestiaorg/orchestrator-relayer/cmd/qgb/base"

Expand All @@ -10,30 +11,31 @@ import (
)

const (
FlagEVMAccAddress = "evm-address"
FlagEVMChainID = "evm-chain-id"
FlagCelesGRPC = "celes-grpc"
FlagEVMRPC = "evm-rpc"
FlagEVMAccAddress = "evm.address"
FlagEVMChainID = "evm.chain-id"
FlagEVMRPC = "evm.rpc"
FlagEVMGasLimit = "evm.gas-limit"
FlagCoreGRPCHost = "core.grpc.host"
FlagCoreGRPCPort = "core.grpc.port"
FlagStartingNonce = "starting-nonce"
FlagEVMGasLimit = "evm-gas-limit"
ServiceNameDeployer = "deployer"
)

func addDeployFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(FlagEVMAccAddress, "d", "", "Specify the EVM account address to use for signing (Note: the private key should be in the keystore)")
cmd.Flags().Uint64P(FlagEVMChainID, "z", 5, "Specify the evm chain id")
cmd.Flags().StringP(FlagCelesGRPC, "c", "localhost:9090", "Specify the grpc address")
cmd.Flags().StringP(FlagEVMRPC, "e", "http://localhost:8545", "Specify the ethereum rpc address")
cmd.Flags().StringP(
cmd.Flags().String(FlagEVMAccAddress, "", "Specify the EVM account address to use for signing (Note: the private key should be in the keystore)")
cmd.Flags().Uint64(FlagEVMChainID, 5, "Specify the evm chain id")
cmd.Flags().String(FlagCoreGRPCHost, "localhost", "Specify the grpc address host")
cmd.Flags().Uint(FlagCoreGRPCPort, 9090, "Specify the grpc address port")
cmd.Flags().String(FlagEVMRPC, "http://localhost:8545", "Specify the ethereum rpc address")
cmd.Flags().String(
FlagStartingNonce,
"n",
"latest",
"Specify the nonce to start the QGB contract from. "+
"\"earliest\": for genesis, "+
"\"latest\": for latest valset nonce, "+
"\"nonce\": for the latest valset before the provided nonce, provided nonce included.",
)
cmd.Flags().Uint64P(FlagEVMGasLimit, "l", evm.DefaultEVMGasLimit, "Specify the evm gas limit")
cmd.Flags().Uint64(FlagEVMGasLimit, evm.DefaultEVMGasLimit, "Specify the evm gas limit")
homeDir, err := base.DefaultServicePath(ServiceNameDeployer)
if err != nil {
panic(err)
Expand All @@ -46,11 +48,11 @@ func addDeployFlags(cmd *cobra.Command) *cobra.Command {

type deployConfig struct {
*base.Config
evmRPC, celesGRPC string
evmChainID uint64
evmAccAddress string
startingNonce string
evmGasLimit uint64
evmRPC, coreGRPC string
evmChainID uint64
evmAccAddress string
startingNonce string
evmGasLimit uint64
}

func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
Expand All @@ -65,7 +67,11 @@ func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
if err != nil {
return deployConfig{}, err
}
celesGRPC, err := cmd.Flags().GetString(FlagCelesGRPC)
coreGRPCHost, err := cmd.Flags().GetString(FlagCoreGRPCHost)
if err != nil {
return deployConfig{}, err
}
coreGRPCPort, err := cmd.Flags().GetUint(FlagCoreGRPCPort)
if err != nil {
return deployConfig{}, err
}
Expand Down Expand Up @@ -100,7 +106,7 @@ func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
return deployConfig{
evmAccAddress: evmAccAddr,
evmChainID: evmChainID,
celesGRPC: celesGRPC,
coreGRPC: fmt.Sprintf("%s:%d", coreGRPCHost, coreGRPCPort),
evmRPC: evmRPC,
startingNonce: startingNonce,
evmGasLimit: evmGasLimit,
Expand Down
4 changes: 2 additions & 2 deletions cmd/qgb/orchestrator/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func Start() *cobra.Command {
tmQuerier, appQuerier, p2pQuerier, retrier, evmKeyStore, acc, stopFuncs, err := common.InitBase(
ctx,
logger,
config.tendermintRPC,
config.celesGRPC,
config.coreRPC,
config.coreGRPC,
config.Home,
config.evmAccAddress,
config.EVMPassphrase,
Expand Down
36 changes: 24 additions & 12 deletions cmd/qgb/orchestrator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ package orchestrator

import (
"errors"
"fmt"

"github.com/celestiaorg/orchestrator-relayer/cmd/qgb/base"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)

const (
FlagCelestiaGRPC = "celes-grpc"
FlagEVMAccAddress = "evm-address"
FlagTendermintRPC = "celes-rpc"
FlagCoreGRPCHost = "core.grpc.host"
FlagCoreGRPCPort = "core.grpc.port"
FlagEVMAccAddress = "evm.address"
FlagCoreRPCHost = "core.rpc.host"
FlagCoreRPCPort = "core.rpc.port"
ServiceNameOrchestrator = "orchestrator"
)

func addOrchestratorFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(FlagTendermintRPC, "t", "tcp://localhost:26657", "Specify the rest rpc address")
cmd.Flags().StringP(FlagCelestiaGRPC, "c", "localhost:9090", "Specify the grpc address (without the protocol prefix)")
cmd.Flags().StringP(
cmd.Flags().String(FlagCoreRPCHost, "localhost", "Specify the rest rpc address host")
cmd.Flags().Uint(FlagCoreRPCPort, 26657, "Specify the rest rpc address port")
cmd.Flags().String(FlagCoreGRPCHost, "localhost", "Specify the grpc address host")
cmd.Flags().Uint(FlagCoreGRPCPort, 9090, "Specify the grpc address port")
cmd.Flags().String(
FlagEVMAccAddress,
"d",
"",
"Specify the EVM account address to use for signing (Note: the private key should be in the keystore)",
)
Expand All @@ -38,7 +42,7 @@ func addOrchestratorFlags(cmd *cobra.Command) *cobra.Command {

type StartConfig struct {
*base.Config
celesGRPC, tendermintRPC string
coreGRPC, coreRPC string
evmAccAddress string
bootstrappers, p2pListenAddr string
p2pNickname string
Expand All @@ -52,11 +56,19 @@ func parseOrchestratorFlags(cmd *cobra.Command) (StartConfig, error) {
if evmAccAddr == "" {
return StartConfig{}, errors.New("the evm account address should be specified")
}
tendermintRPC, err := cmd.Flags().GetString(FlagTendermintRPC)
coreRPCHost, err := cmd.Flags().GetString(FlagCoreRPCHost)
if err != nil {
return StartConfig{}, err
}
celesGRPC, err := cmd.Flags().GetString(FlagCelestiaGRPC)
coreRPCPort, err := cmd.Flags().GetUint(FlagCoreRPCPort)
if err != nil {
return StartConfig{}, err
}
coreGRPCHost, err := cmd.Flags().GetString(FlagCoreGRPCHost)
if err != nil {
return StartConfig{}, err
}
coreGRPCPort, err := cmd.Flags().GetUint(FlagCoreGRPCPort)
if err != nil {
return StartConfig{}, err
}
Expand Down Expand Up @@ -90,8 +102,8 @@ func parseOrchestratorFlags(cmd *cobra.Command) (StartConfig, error) {

return StartConfig{
evmAccAddress: evmAccAddr,
celesGRPC: celesGRPC,
tendermintRPC: tendermintRPC,
coreGRPC: fmt.Sprintf("%s:%d", coreGRPCHost, coreGRPCPort),
coreRPC: fmt.Sprintf("tcp://%s:%d", coreRPCHost, coreRPCPort),
bootstrappers: bootstrappers,
p2pNickname: p2pNickname,
p2pListenAddr: p2pListenAddress,
Expand Down
4 changes: 2 additions & 2 deletions cmd/qgb/query/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Signers() *cobra.Command {
}()

// create tm querier and app querier
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.tendermintRPC, config.celesGRPC)
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
Expand Down Expand Up @@ -358,7 +358,7 @@ func Signature() *cobra.Command {
}()

// create tm querier and app querier
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.tendermintRPC, config.celesGRPC)
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
Expand Down
38 changes: 25 additions & 13 deletions cmd/qgb/query/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package query

import (
"fmt"

"github.com/celestiaorg/orchestrator-relayer/cmd/qgb/relayer"
"github.com/spf13/cobra"
)
Expand All @@ -11,26 +13,36 @@ const (
)

func addFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(relayer.FlagCelesGRPC, "c", "localhost:9090", "Specify the grpc address")
cmd.Flags().StringP(relayer.FlagTendermintRPC, "t", "http://localhost:26657", "Specify the rest rpc address")
cmd.Flags().StringP(FlagP2PNode, "n", "", "P2P target node multiaddress (eg. /ip4/127.0.0.1/tcp/30000/p2p/12D3KooWBSMasWzRSRKXREhediFUwABNZwzJbkZcYz5rYr9Zdmfn)")
cmd.Flags().StringP(FlagOutputFile, "o", "", "Path to an output file path if the results need to be written to a json file. Leaving it as empty will result in printing the result to stdout")
cmd.Flags().String(relayer.FlagCoreGRPCHost, "localhost", "Specify the grpc address host")
cmd.Flags().Uint(relayer.FlagCoreGRPCPort, 9090, "Specify the grpc address port")
cmd.Flags().String(relayer.FlagCoreRPCHost, "localhost", "Specify the rest rpc address host")
cmd.Flags().Uint(relayer.FlagCoreRPCPort, 26657, "Specify the rest rpc address")
cmd.Flags().String(FlagP2PNode, "", "P2P target node multiaddress (eg. /ip4/127.0.0.1/tcp/30000/p2p/12D3KooWBSMasWzRSRKXREhediFUwABNZwzJbkZcYz5rYr9Zdmfn)")
cmd.Flags().String(FlagOutputFile, "", "Path to an output file path if the results need to be written to a json file. Leaving it as empty will result in printing the result to stdout")

return cmd
}

type Config struct {
celesGRPC, tendermintRPC string
targetNode string
outputFile string
coreGRPC, coreRPC string
targetNode string
outputFile string
}

func parseFlags(cmd *cobra.Command) (Config, error) {
tendermintRPC, err := cmd.Flags().GetString(relayer.FlagTendermintRPC)
coreRPCHost, err := cmd.Flags().GetString(relayer.FlagCoreRPCHost)
if err != nil {
return Config{}, err
}
coreRPCPort, err := cmd.Flags().GetUint(relayer.FlagCoreRPCPort)
if err != nil {
return Config{}, err
}
coreGRPCHost, err := cmd.Flags().GetString(relayer.FlagCoreGRPCHost)
if err != nil {
return Config{}, err
}
celesGRPC, err := cmd.Flags().GetString(relayer.FlagCelesGRPC)
coreGRPCPort, err := cmd.Flags().GetUint(relayer.FlagCoreGRPCPort)
if err != nil {
return Config{}, err
}
Expand All @@ -44,9 +56,9 @@ func parseFlags(cmd *cobra.Command) (Config, error) {
}

return Config{
celesGRPC: celesGRPC,
tendermintRPC: tendermintRPC,
targetNode: targetNode,
outputFile: outputFile,
coreGRPC: fmt.Sprintf("%s:%d", coreGRPCHost, coreGRPCPort),
coreRPC: fmt.Sprintf("tcp://%s:%d", coreRPCHost, coreRPCPort),
targetNode: targetNode,
outputFile: outputFile,
}, nil
}
4 changes: 2 additions & 2 deletions cmd/qgb/relayer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func Start() *cobra.Command {
tmQuerier, appQuerier, p2pQuerier, retrier, evmKeystore, acc, stopFuncs, err := common.InitBase(
ctx,
logger,
config.tendermintRPC,
config.celesGRPC,
config.coreRPC,
config.coreGRPC,
config.Home,
config.evmAccAddress,
config.EVMPassphrase,
Expand Down
Loading

0 comments on commit 3f3692d

Please sign in to comment.