From e01bd39d8e0e7ba3391e9f36a2ca64b4a8513df9 Mon Sep 17 00:00:00 2001 From: Dmitry S <11892559+swift1337@users.noreply.github.com> Date: Wed, 6 Nov 2024 21:07:49 +0100 Subject: [PATCH] Restructure inbound cmd --- cmd/zetaclientd/{debug.go => inbound.go} | 39 ++++++++---------------- cmd/zetaclientd/main.go | 39 ++++++++++++++---------- cmd/zetaclientd/start.go | 6 ++++ 3 files changed, 42 insertions(+), 42 deletions(-) rename cmd/zetaclientd/{debug.go => inbound.go} (84%) diff --git a/cmd/zetaclientd/debug.go b/cmd/zetaclientd/inbound.go similarity index 84% rename from cmd/zetaclientd/debug.go rename to cmd/zetaclientd/inbound.go index a897fdea65..00f37080df 100644 --- a/cmd/zetaclientd/debug.go +++ b/cmd/zetaclientd/inbound.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "os" "strconv" "strings" @@ -26,36 +25,24 @@ import ( "github.com/zeta-chain/node/zetaclient/zetacore" ) -var debugArgs = debugArguments{} - -type debugArguments struct { - zetaCoreHome string - zetaNode string - zetaChainID string +type inboundOptions struct { + zetaNode string + zetaChainID string } -func init() { - defaultHomeDir := os.ExpandEnv("$HOME/.zetacored") +var inboundOpts inboundOptions - cmd := DebugCmd() - cmd.Flags().StringVar(&debugArgs.zetaCoreHome, "core-home", defaultHomeDir, "zetacore home directory") - cmd.Flags().StringVar(&debugArgs.zetaNode, "node", "46.4.15.110", "public ip address") - cmd.Flags().StringVar(&debugArgs.zetaChainID, "chain-id", "athens_7001-1", "pre-params file path") +func setupInboundOptions() { + f, cfg := InboundCmd.PersistentFlags(), &inboundOpts - RootCmd.AddCommand(cmd) + f.StringVar(&cfg.zetaNode, "node", "46.4.15.110", "public ip address") + f.StringVar(&cfg.zetaChainID, "chain-id", "athens_7001-1", "pre-params file path") } -func DebugCmd() *cobra.Command { - return &cobra.Command{ - Use: "get-inbound-ballot [inboundHash] [chainID]", - Short: "provide txHash and chainID to get the ballot status for the txHash", - RunE: debugCmd, - } -} - -func debugCmd(_ *cobra.Command, args []string) error { +func InboundGetBallot(_ *cobra.Command, args []string) error { cobra.ExactArgs(2) - cfg, err := config.Load(debugArgs.zetaCoreHome) + + cfg, err := config.Load(globalOpts.ZetacoreHome) if err != nil { return errors.Wrap(err, "failed to load config") } @@ -70,9 +57,9 @@ func debugCmd(_ *cobra.Command, args []string) error { // create a new zetacore client client, err := zetacore.NewClient( &keys.Keys{OperatorAddress: sdk.MustAccAddressFromBech32(sample.AccAddress())}, - debugArgs.zetaNode, + inboundOpts.zetaNode, "", - debugArgs.zetaChainID, + inboundOpts.zetaChainID, false, zerolog.Nop(), ) diff --git a/cmd/zetaclientd/main.go b/cmd/zetaclientd/main.go index 86c6c3b481..7b51e0086d 100644 --- a/cmd/zetaclientd/main.go +++ b/cmd/zetaclientd/main.go @@ -5,7 +5,6 @@ import ( "fmt" "os" - ecdsakeygen "github.com/bnb-chain/tss-lib/ecdsa/keygen" tmcli "github.com/cometbft/cometbft/libs/cli" "github.com/spf13/cobra" @@ -17,7 +16,7 @@ import ( var ( RootCmd = &cobra.Command{ Use: "zetaclientd", - Short: "ZetaClient CLI", + Short: "zetaclient cli & server", } VersionCmd = &cobra.Command{ Use: "version", @@ -62,6 +61,13 @@ var ( Short: "Show relayer address", RunE: RelayerShowAddress, } + + InboundCmd = &cobra.Command{Use: "inbound", Short: "Inbound transactions"} + InboundGetBallotCmd = &cobra.Command{ + Use: "get-ballot [inboundHash] [chainID]", + Short: "Get the ballot status for the tx hash", + RunE: InboundGetBallot, + } ) // globalOptions defines the global options for all commands. @@ -69,18 +75,13 @@ type globalOptions struct { ZetacoreHome string } -var ( - preParams *ecdsakeygen.LocalPreParams - globalOpts globalOptions -) +var globalOpts globalOptions -func main() { - ctx := context.Background() +func setupGlobalOptions() { + globals := RootCmd.PersistentFlags() - if err := RootCmd.ExecuteContext(ctx); err != nil { - fmt.Printf("Error: %s. Exit code 1\n", err) - os.Exit(1) - } + globals.StringVar(&globalOpts.ZetacoreHome, tmcli.HomeFlag, app.DefaultNodeHome, "home path") + // add more options here (e.g. verbosity, etc...) } func init() { @@ -90,6 +91,7 @@ func init() { setupGlobalOptions() setupInitializeConfigOptions() setupRelayerOptions() + setupInboundOptions() // Define commands RootCmd.AddCommand(VersionCmd) @@ -103,11 +105,16 @@ func init() { RootCmd.AddCommand(RelayerCmd) RelayerCmd.AddCommand(RelayerImportKeyCmd) RelayerCmd.AddCommand(RelayerShowAddressCmd) + + RootCmd.AddCommand(InboundCmd) + InboundCmd.AddCommand(InboundGetBallotCmd) } -func setupGlobalOptions() { - globals := RootCmd.PersistentFlags() +func main() { + ctx := context.Background() - globals.StringVar(&globalOpts.ZetacoreHome, tmcli.HomeFlag, app.DefaultNodeHome, "home path") - // add more options here (e.g. verbosity, etc...) + if err := RootCmd.ExecuteContext(ctx); err != nil { + fmt.Printf("Error: %s. Exit code 1\n", err) + os.Exit(1) + } } diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 244f135026..cde4113598 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -12,6 +12,7 @@ import ( "syscall" "time" + ecdsakeygen "github.com/bnb-chain/tss-lib/ecdsa/keygen" "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/libp2p/go-libp2p/core/peer" maddr "github.com/multiformats/go-multiaddr" @@ -35,6 +36,11 @@ import ( "github.com/zeta-chain/node/zetaclient/zetacore" ) +// todo revamp +// https://github.com/zeta-chain/node/issues/3119 +// https://github.com/zeta-chain/node/issues/3112 +var preParams *ecdsakeygen.LocalPreParams + func Start(_ *cobra.Command, _ []string) error { // Prompt for Hotkey, TSS key-share and relayer key passwords titles := []string{"HotKey", "TSS", "Solana Relayer Key"}