Skip to content

Commit

Permalink
refactor(zetaclient)!: cli improvements (#3122)
Browse files Browse the repository at this point in the history
* Consolidate files and logic within zetaclientd cli

* Update `init` command

* Consolidate TSS commands

* Drop HSM cli (#3118)

* Move p2p diagnostic to tss package

* Refactor relayer commands

* Rename init config

* Restructure inbound cmd

* Update changelog

* Drop p2p diagnostics

* lint & pr comments [1]

* Address pr comments [2]
  • Loading branch information
swift1337 authored Nov 7, 2024
1 parent 38fea4a commit 1629523
Show file tree
Hide file tree
Showing 21 changed files with 540 additions and 558 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* [2984](https://github.com/zeta-chain/node/pull/2984) - add Whitelist message ability to whitelist SPL tokens on Solana
* [3091](https://github.com/zeta-chain/node/pull/3091) - improve build reproducability. `make release{,-build-only}` checksums should now be stable.

### Refactor
* [3122](https://github.com/zeta-chain/node/pull/3122) - improve & refactor zetaclientd cli

### Tests
* [3075](https://github.com/zeta-chain/node/pull/3075) - ton: withdraw concurrent, deposit & revert.

Expand Down
12 changes: 0 additions & 12 deletions cmd/config.go

This file was deleted.

36 changes: 36 additions & 0 deletions cmd/cosmos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Package cmd provides cosmos constants for ZetaClient.
package cmd

import (
"sync"

cosmos "github.com/cosmos/cosmos-sdk/types"
)

const (
Bech32PrefixAccAddr = "zeta"
Bech32PrefixAccPub = "zetapub"
Bech32PrefixValAddr = "zetav"
Bech32PrefixValPub = "zetavpub"
Bech32PrefixConsAddr = "zetac"
Bech32PrefixConsPub = "zetacpub"
DenomRegex = `[a-zA-Z][a-zA-Z0-9:\\/\\\-\\_\\.]{2,127}`
ZetaChainHDPath string = `m/44'/60'/0'/0/0`
)

var setupConfig sync.Once

// SetupCosmosConfig configures basic Cosmos parameters.
// This function is required because some parts of ZetaClient rely on these constants.
func SetupCosmosConfig() {
setupConfig.Do(setupCosmosConfig)
}

func setupCosmosConfig() {
config := cosmos.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
config.SetFullFundraiserPath(ZetaChainHDPath)
cosmos.SetCoinDenomRegex(func() string { return DenomRegex })
}
47 changes: 0 additions & 47 deletions cmd/zetaclientd/encrypt_tss.go

This file was deleted.

40 changes: 0 additions & 40 deletions cmd/zetaclientd/gen_pre_params.go

This file was deleted.

153 changes: 0 additions & 153 deletions cmd/zetaclientd/import_relayer_keys.go

This file was deleted.

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 {
Node string
ChainID 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.Node, "node", "46.4.15.110", "zeta public ip address")
f.StringVar(&cfg.ChainID, "chain-id", "athens_7001-1", "zeta chain id")
}

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.Node,
"",
debugArgs.zetaChainID,
inboundOpts.ChainID,
zerolog.Nop(),
)
if err != nil {
Expand Down
Loading

0 comments on commit 1629523

Please sign in to comment.