[#156] frostfs-adm: Make dumpBalances() pass linter checks

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-03-21 17:36:14 +03:00 committed by Gitea
parent 8014fdb21a
commit 484ac502ca

View file

@ -44,7 +44,6 @@ const (
notaryEnabled = true notaryEnabled = true
) )
// nolint: funlen, gocognit
func dumpBalances(cmd *cobra.Command, _ []string) error { func dumpBalances(cmd *cobra.Command, _ []string) error {
var ( var (
dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag) dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag)
@ -84,6 +83,27 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
printBalances(cmd, "Inner ring nodes balances:", irList) printBalances(cmd, "Inner ring nodes balances:", irList)
if dumpStorage { if dumpStorage {
if err := printStorageNodeBalances(cmd, inv, nmHash); err != nil {
return err
}
}
if dumpProxy {
if err := printProxyContractBalance(cmd, inv, nnsCs.Hash); err != nil {
return err
}
}
if dumpAlphabet {
if err := printAlphabetContractBalances(cmd, c, inv, len(irList), nnsCs.Hash); err != nil {
return err
}
}
return nil
}
func printStorageNodeBalances(cmd *cobra.Command, inv *invoker.Invoker, nmHash util.Uint160) error {
arr, err := unwrap.Array(inv.Call(nmHash, "netmap")) arr, err := unwrap.Array(inv.Call(nmHash, "netmap"))
if err != nil { if err != nil {
return errors.New("can't fetch the list of storage nodes") return errors.New("can't fetch the list of storage nodes")
@ -113,11 +133,13 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
if err := fetchBalances(inv, gas.Hash, snList); err != nil { if err := fetchBalances(inv, gas.Hash, snList); err != nil {
return err return err
} }
printBalances(cmd, "\nStorage node balances:", snList) printBalances(cmd, "\nStorage node balances:", snList)
return nil
} }
if dumpProxy { func printProxyContractBalance(cmd *cobra.Command, inv *invoker.Invoker, nnsHash util.Uint160) error {
h, err := nnsResolveHash(inv, nnsCs.Hash, proxyContract+".frostfs") h, err := nnsResolveHash(inv, nnsHash, proxyContract+".frostfs")
if err != nil { if err != nil {
return fmt.Errorf("can't get hash of the proxy contract: %w", err) return fmt.Errorf("can't get hash of the proxy contract: %w", err)
} }
@ -126,15 +148,17 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
if err := fetchBalances(inv, gas.Hash, proxyList); err != nil { if err := fetchBalances(inv, gas.Hash, proxyList); err != nil {
return err return err
} }
printBalances(cmd, "\nProxy contract balance:", proxyList) printBalances(cmd, "\nProxy contract balance:", proxyList)
return nil
} }
if dumpAlphabet { func printAlphabetContractBalances(cmd *cobra.Command, c Client, inv *invoker.Invoker, count int, nnsHash util.Uint160) error {
alphaList := make([]accBalancePair, len(irList)) alphaList := make([]accBalancePair, count)
w := io.NewBufBinWriter() w := io.NewBufBinWriter()
for i := range alphaList { for i := range alphaList {
emit.AppCall(w.BinWriter, nnsCs.Hash, "resolve", callflag.ReadOnly, emit.AppCall(w.BinWriter, nnsHash, "resolve", callflag.ReadOnly,
getAlphabetNNSDomain(i), getAlphabetNNSDomain(i),
int64(nns.TXT)) int64(nns.TXT))
} }
@ -158,9 +182,8 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
if err := fetchBalances(inv, gas.Hash, alphaList); err != nil { if err := fetchBalances(inv, gas.Hash, alphaList); err != nil {
return err return err
} }
printBalances(cmd, "\nAlphabet contracts balances:", alphaList)
}
printBalances(cmd, "\nAlphabet contracts balances:", alphaList)
return nil return nil
} }