From 932210c1b9ee4e9c8c13ee6e680c5b2fd4cd738e Mon Sep 17 00:00:00 2001 From: Dmitry S <11892559+swift1337@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:01:45 +0100 Subject: [PATCH] lint & pr comments [1] --- cmd/zetaclientd/main.go | 2 +- cmd/zetaclientd/relayer.go | 64 +++++++++++++++++++------------------- cmd/zetaclientd/tss.go | 1 + 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/cmd/zetaclientd/main.go b/cmd/zetaclientd/main.go index 7b51e0086d..b3113f4035 100644 --- a/cmd/zetaclientd/main.go +++ b/cmd/zetaclientd/main.go @@ -44,7 +44,7 @@ var ( RunE: TSSEncryptFile, } TSSGeneratePreParamsCmd = &cobra.Command{ - Use: "tss gen-pre-params [path]", + Use: "gen-pre-params [path]", Short: "Generate pre parameters for TSS", Args: cobra.ExactArgs(1), RunE: TSSGeneratePreParams, diff --git a/cmd/zetaclientd/relayer.go b/cmd/zetaclientd/relayer.go index 29df9016ea..bd2596bceb 100644 --- a/cmd/zetaclientd/relayer.go +++ b/cmd/zetaclientd/relayer.go @@ -16,10 +16,10 @@ import ( "github.com/zeta-chain/node/zetaclient/keys" ) -// privateKey is the struct that holds arguments for the relayer commands +// relayerOptions is the struct that holds arguments for the relayer commands type relayerOptions struct { privateKey string - network uint32 + network int32 password string relayerKeyPath string } @@ -32,7 +32,7 @@ func setupRelayerOptions() { // resolve default relayer key path defaultKeyPath := fmt.Sprintf("%s/%s", app.DefaultNodeHome, config.DefaultRelayerDir) - f.Uint32Var(&cfg.network, "network", 7, "network id, (7:solana)") + f.Int32Var(&cfg.network, "network", 7, "network id, (7:solana)") f.StringVar(&cfg.password, "password", "", "the password to decrypt the relayer private key") f.StringVar(&cfg.relayerKeyPath, "key-path", defaultKeyPath, "path to relayer keys") @@ -41,6 +41,35 @@ func setupRelayerOptions() { f.StringVar(&cfg.privateKey, "private-key", "", "the relayer private key to import") } +// RelayerShowAddress shows the relayer address +func RelayerShowAddress(_ *cobra.Command, _ []string) error { + // try loading the relayer key if present + network := chains.Network(relayerOpts.network) + relayerKey, err := keys.LoadRelayerKey(relayerOpts.relayerKeyPath, network, relayerOpts.password) + if err != nil { + return errors.Wrap(err, "failed to load relayer key") + } + + // relayer key does not exist, return error + if relayerKey == nil { + return fmt.Errorf( + "relayer key not found for network %d in path: %s", + relayerOpts.network, + relayerOpts.relayerKeyPath, + ) + } + + // resolve the relayer address + networkName, address, err := relayerKey.ResolveAddress(network) + if err != nil { + return errors.Wrap(err, "failed to resolve relayer address") + } + + fmt.Printf("relayer address (%s): %s\n", networkName, address) + + return nil +} + // RelayerImportKey imports a relayer private key func RelayerImportKey(_ *cobra.Command, _ []string) error { // validate private key and password @@ -90,32 +119,3 @@ func RelayerImportKey(_ *cobra.Command, _ []string) error { return nil } - -// RelayerShowAddress shows the relayer address -func RelayerShowAddress(_ *cobra.Command, _ []string) error { - // try loading the relayer key if present - network := chains.Network(relayerOpts.network) - relayerKey, err := keys.LoadRelayerKey(relayerOpts.relayerKeyPath, network, relayerOpts.password) - if err != nil { - return errors.Wrap(err, "failed to load relayer key") - } - - // relayer key does not exist, return error - if relayerKey == nil { - return fmt.Errorf( - "relayer key not found for network %d in path: %s", - relayerOpts.network, - relayerOpts.relayerKeyPath, - ) - } - - // resolve the relayer address - networkName, address, err := relayerKey.ResolveAddress(network) - if err != nil { - return errors.Wrap(err, "failed to resolve relayer address") - } - - fmt.Printf("relayer address (%s): %s\n", networkName, address) - - return nil -} diff --git a/cmd/zetaclientd/tss.go b/cmd/zetaclientd/tss.go index 0b20234b75..cf16131100 100644 --- a/cmd/zetaclientd/tss.go +++ b/cmd/zetaclientd/tss.go @@ -21,6 +21,7 @@ func TSSEncryptFile(_ *cobra.Command, args []string) error { password = args[1] ) + // #nosec G304 -- this is a config file data, err := os.ReadFile(filePath) if err != nil { return err