[#76] Add owner argument for accounting.balance command

With `--owner` argument user can look for balances of other
nodes by knowing their owner ID which is NEO3 compatible
address.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-12 17:31:00 +03:00 committed by Stanislav Bogatyrev
parent 945bb723ed
commit c2083d773c
2 changed files with 42 additions and 2 deletions

View file

@ -6,9 +6,14 @@ import (
"math"
"github.com/nspcc-dev/neofs-api-go/pkg/accounting"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/spf13/cobra"
)
var (
balanceOwner string
)
// accountingCmd represents the accounting command
var accountingCmd = &cobra.Command{
Use: "accounting",
@ -23,8 +28,10 @@ var accountingBalanceCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
var (
response *accounting.Decimal
oid *owner.ID
err error
ctx = context.Background()
ctx = context.Background()
)
cli, err := getSDKClient()
@ -32,7 +39,18 @@ var accountingBalanceCmd = &cobra.Command{
return err
}
response, err = cli.GetSelfBalance(ctx)
switch balanceOwner {
case "":
response, err = cli.GetSelfBalance(ctx)
default:
oid, err = ownerFromString(balanceOwner)
if err != nil {
return err
}
response, err = cli.GetBalance(ctx, oid)
}
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
@ -57,6 +75,8 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// accountingCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
accountingBalanceCmd.Flags().StringVar(&balanceOwner, "owner", "", "owner of balance account (omit to use owner from private key)")
}
func prettyPrintDecimal(decimal *accounting.Decimal) {