From beb9d80e348330855c5a943645b666f70004d690 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 1 Feb 2024 16:38:20 +0300 Subject: [PATCH] [#932] adm: Move command `dump-balances` to package `balance` Signed-off-by: Anton Nikiforov --- .../modules/morph/{ => balance}/balance.go | 4 +-- .../internal/modules/morph/balance/root.go | 28 +++++++++++++++++++ .../internal/modules/morph/dump_hashes.go | 4 +-- .../modules/morph/initialize_deploy.go | 2 +- .../internal/modules/morph/initialize_nns.go | 7 +---- .../internal/modules/morph/root.go | 21 ++------------ .../internal/modules/morph/util/util.go | 5 ++++ 7 files changed, 41 insertions(+), 30 deletions(-) rename cmd/frostfs-adm/internal/modules/morph/{ => balance}/balance.go (99%) create mode 100644 cmd/frostfs-adm/internal/modules/morph/balance/root.go diff --git a/cmd/frostfs-adm/internal/modules/morph/balance.go b/cmd/frostfs-adm/internal/modules/morph/balance/balance.go similarity index 99% rename from cmd/frostfs-adm/internal/modules/morph/balance.go rename to cmd/frostfs-adm/internal/modules/morph/balance/balance.go index 451d57954..9d16ada46 100644 --- a/cmd/frostfs-adm/internal/modules/morph/balance.go +++ b/cmd/frostfs-adm/internal/modules/morph/balance/balance.go @@ -1,4 +1,4 @@ -package morph +package balance import ( "crypto/elliptic" @@ -157,7 +157,7 @@ func printAlphabetContractBalances(cmd *cobra.Command, c morphUtil.Client, inv * w := io.NewBufBinWriter() for i := range alphaList { emit.AppCall(w.BinWriter, nnsHash, "resolve", callflag.ReadOnly, - getAlphabetNNSDomain(i), + morphUtil.GetAlphabetNNSDomain(i), int64(nns.TXT)) } if w.Err != nil { diff --git a/cmd/frostfs-adm/internal/modules/morph/balance/root.go b/cmd/frostfs-adm/internal/modules/morph/balance/root.go new file mode 100644 index 000000000..757637e5d --- /dev/null +++ b/cmd/frostfs-adm/internal/modules/morph/balance/root.go @@ -0,0 +1,28 @@ +package balance + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var DumpCmd = &cobra.Command{ + Use: "dump-balances", + Short: "Dump GAS balances", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + }, + RunE: dumpBalances, +} + +func initDumpBalancesCmd() { + DumpCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) + DumpCmd.Flags().BoolP(dumpBalancesStorageFlag, "s", false, "Dump balances of storage nodes from the current netmap") + DumpCmd.Flags().BoolP(dumpBalancesAlphabetFlag, "a", false, "Dump balances of alphabet contracts") + DumpCmd.Flags().BoolP(dumpBalancesProxyFlag, "p", false, "Dump balances of the proxy contract") + DumpCmd.Flags().Bool(dumpBalancesUseScriptHashFlag, false, "Use script-hash format for addresses") +} + +func init() { + initDumpBalancesCmd() +} diff --git a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go b/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go index d33311a8b..c92c25690 100644 --- a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go +++ b/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go @@ -54,7 +54,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { irSize := 0 for ; irSize < lastGlagoliticLetter; irSize++ { - ok, err := morphUtil.NNSIsAvailable(c, cs.Hash, getAlphabetNNSDomain(irSize)) + ok, err := morphUtil.NNSIsAvailable(c, cs.Hash, morphUtil.GetAlphabetNNSDomain(irSize)) if err != nil { return err } else if ok { @@ -68,7 +68,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { bw.Reset() for i := 0; i < irSize; i++ { emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly, - getAlphabetNNSDomain(i), + morphUtil.GetAlphabetNNSDomain(i), int64(nns.TXT)) } diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go index 5cd7b3ba0..50427c93f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go @@ -215,7 +215,7 @@ func deployAlphabetAccounts(c *morphUtil.InitializeContext, nnsHash util.Uint160 // alphabet contracts should be deployed by individual nodes to get different hashes. for i, acc := range c.Accounts { - ctrHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, nnsHash, getAlphabetNNSDomain(i)) + ctrHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, nnsHash, morphUtil.GetAlphabetNNSDomain(i)) if err != nil { return nil, fmt.Errorf("can't resolve hash for contract update: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go b/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go index 8e5223098..53435e67b 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "errors" "fmt" - "strconv" "git.frostfs.info/TrueCloudLab/frostfs-contract/nns" morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" @@ -48,7 +47,7 @@ func setNNS(c *morphUtil.InitializeContext) error { for i, acc := range c.Accounts { alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name) - domain := getAlphabetNNSDomain(i) + domain := morphUtil.GetAlphabetNNSDomain(i) if err := nnsRegisterDomain(c, nnsCs.Hash, alphaCs.Hash, domain); err != nil { return err } @@ -93,10 +92,6 @@ func updateNNSGroup(c *morphUtil.InitializeContext, nnsHash util.Uint160, pub *k return c.SendCommitteeTx(script, true) } -func getAlphabetNNSDomain(i int) string { - return morphUtil.AlphabetContract + strconv.FormatUint(uint64(i), 10) + ".frostfs" -} - // wrapRegisterScriptWithPrice wraps a given script with `getPrice`/`setPrice` calls for NNS. // It is intended to be used for a single transaction, and not as a part of other scripts. // It is assumed that script already contains static slot initialization code, the first one diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index 7eb41ddc2..ac757428a 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -2,6 +2,7 @@ package morph import ( "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/ape" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/balance" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/frostfsid" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/policy" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/proxy" @@ -151,15 +152,6 @@ var ( RunE: dumpNetworkConfig, } - dumpBalancesCmd = &cobra.Command{ - Use: "dump-balances", - Short: "Dump GAS balances", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - }, - RunE: dumpBalances, - } - updateContractsCmd = &cobra.Command{ Use: "update-contracts", Short: "Update FrostFS contracts", @@ -230,7 +222,7 @@ func init() { initDumpContractHashesCmd() initDumpNetworkConfigCmd() initSetConfigCmd() - initDumpBalancesCmd() + RootCmd.AddCommand(balance.DumpCmd) initUpdateContractsCmd() initDumpContainersCmd() initRestoreContainersCmd() @@ -301,15 +293,6 @@ func initUpdateContractsCmd() { updateContractsCmd.MarkFlagsMutuallyExclusive(util.ContractsInitFlag, util.ContractsURLFlag) } -func initDumpBalancesCmd() { - RootCmd.AddCommand(dumpBalancesCmd) - dumpBalancesCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) - dumpBalancesCmd.Flags().BoolP(dumpBalancesStorageFlag, "s", false, "Dump balances of storage nodes from the current netmap") - dumpBalancesCmd.Flags().BoolP(dumpBalancesAlphabetFlag, "a", false, "Dump balances of alphabet contracts") - dumpBalancesCmd.Flags().BoolP(dumpBalancesProxyFlag, "p", false, "Dump balances of the proxy contract") - dumpBalancesCmd.Flags().Bool(dumpBalancesUseScriptHashFlag, false, "Use script-hash format for addresses") -} - func initSetConfigCmd() { RootCmd.AddCommand(setConfig) setConfig.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) diff --git a/cmd/frostfs-adm/internal/modules/morph/util/util.go b/cmd/frostfs-adm/internal/modules/morph/util/util.go index 4a963d3d8..a6f94049b 100644 --- a/cmd/frostfs-adm/internal/modules/morph/util/util.go +++ b/cmd/frostfs-adm/internal/modules/morph/util/util.go @@ -8,6 +8,7 @@ import ( "io" "os" "path/filepath" + "strconv" "strings" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config" @@ -157,3 +158,7 @@ func readContractsFromArchive(file io.Reader, names []string) (map[string]*Contr } return m, nil } + +func GetAlphabetNNSDomain(i int) string { + return AlphabetContract + strconv.FormatUint(uint64(i), 10) + ".frostfs" +}