[#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

@ -7,7 +7,9 @@ import (
"os"
"github.com/mitchellh/go-homedir"
"github.com/mr-tron/base58"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/network"
"github.com/spf13/cobra"
@ -132,3 +134,21 @@ func getSDKClient() (*client.Client, error) {
return client.New(key, client.WithAddress(ipAddr))
}
// ownerFromString converts string with NEO3 wallet address to neofs owner ID.
func ownerFromString(s string) (*owner.ID, error) {
var w owner.NEO3Wallet
// todo: move this into neofs-api-go `owner.NEO3WalletFromString` function
binaryWallet, err := base58.Decode(s)
if err != nil || len(binaryWallet) != len(w) {
return nil, errors.New("can't decode owner ID wallet address")
}
copy(w[:], binaryWallet)
id := owner.NewID()
id.SetNeo3Wallet(&w)
return id, nil
}