forked from TrueCloudLab/frostfs-node
[#950] cli: Refactor usage of NeoFS API client
The client needs of the CLI application are limited and change not often. Interface changes of the client library should not affect the operation of various application packages, if they do not change their requirements for the provided functionality. To localize the use of the base client and facilitate further support, an auxiliary package is implemented that will only be used by the CLI application. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
a3414b36dd
commit
bbc2b873ab
9 changed files with 1098 additions and 403 deletions
|
@ -1,12 +1,12 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/accounting"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -37,19 +37,11 @@ var accountingBalanceCmd = &cobra.Command{
|
|||
Short: "Get internal balance of NeoFS account",
|
||||
Long: `Get internal balance of NeoFS account`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
response *accounting.Decimal
|
||||
oid *owner.ID
|
||||
|
||||
ctx = context.Background()
|
||||
)
|
||||
var oid *owner.ID
|
||||
|
||||
key, err := getKey()
|
||||
exitOnErr(cmd, err)
|
||||
|
||||
cli, err := getSDKClient(key)
|
||||
exitOnErr(cmd, err)
|
||||
|
||||
if balanceOwner == "" {
|
||||
wallet, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
|
||||
exitOnErr(cmd, err)
|
||||
|
@ -60,11 +52,16 @@ var accountingBalanceCmd = &cobra.Command{
|
|||
exitOnErr(cmd, err)
|
||||
}
|
||||
|
||||
response, err = cli.GetBalance(ctx, oid, globalCallOptions()...)
|
||||
var prm internalclient.BalanceOfPrm
|
||||
|
||||
prepareAPIClientWithKey(cmd, key, &prm)
|
||||
prm.SetOwner(oid)
|
||||
|
||||
res, err := internalclient.BalanceOf(prm)
|
||||
exitOnErr(cmd, errf("rpc error: %w", err))
|
||||
|
||||
// print to stdout
|
||||
prettyPrintDecimal(cmd, response)
|
||||
prettyPrintDecimal(cmd, res.Balance())
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue