Skip to content

Commit

Permalink
Restructure inbound cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
swift1337 committed Nov 6, 2024
1 parent 45fc5b4 commit e01bd39
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
39 changes: 13 additions & 26 deletions cmd/zetaclientd/debug.go → cmd/zetaclientd/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"os"
"strconv"
"strings"

Expand All @@ -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")
}
Expand All @@ -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(),
)
Expand Down
39 changes: 23 additions & 16 deletions cmd/zetaclientd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -17,7 +16,7 @@ import (
var (
RootCmd = &cobra.Command{
Use: "zetaclientd",
Short: "ZetaClient CLI",
Short: "zetaclient cli & server",
}
VersionCmd = &cobra.Command{
Use: "version",
Expand Down Expand Up @@ -62,25 +61,27 @@ 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.
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() {
Expand All @@ -90,6 +91,7 @@ func init() {
setupGlobalOptions()
setupInitializeConfigOptions()
setupRelayerOptions()
setupInboundOptions()

// Define commands
RootCmd.AddCommand(VersionCmd)
Expand All @@ -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)
}
}
6 changes: 6 additions & 0 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"}
Expand Down

0 comments on commit e01bd39

Please sign in to comment.