From c0a4343282c7577e686af3aa15946980fbacfede Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 15 Oct 2020 11:45:00 +0300 Subject: [PATCH] [#25] Use api-go stringers and parsers for ID types in CLI Signed-off-by: Alex Vanin --- cmd/neofs-cli/modules/container.go | 21 ++++++--------------- cmd/neofs-cli/modules/root.go | 15 ++++----------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 483c746c..1b2f0973 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -2,7 +2,6 @@ package cmd import ( "context" - "crypto/sha256" "errors" "fmt" "io/ioutil" @@ -12,7 +11,6 @@ import ( "time" "github.com/google/uuid" - "github.com/mr-tron/base58" "github.com/nspcc-dev/neofs-api-go/pkg/acl" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" @@ -132,8 +130,7 @@ It will be stored in sidechain when inner ring will accepts it.`, return fmt.Errorf("rpc error: %w", err) } - // todo: use stringers after neofs-api-go#147 - fmt.Println("container ID:", base58.Encode(id.ToV2().GetValue())) + fmt.Println("container ID:", id) if containerAwait { fmt.Println("awaiting...") @@ -233,8 +230,7 @@ func init() { func prettyPrintContainerList(list []*container.ID) { for i := range list { - // todo: use stringers after neofs-api-go#147 - fmt.Println(base58.Encode(list[i].ToV2().GetValue())) + fmt.Println(list[i]) } } @@ -317,17 +313,12 @@ func parseNonce(nonce string) (uuid.UUID, error) { } func parseContainerID(cid string) (*container.ID, error) { - // todo: use decoders after neofs-api-go#147 - data, err := base58.Decode(cid) - if err != nil || len(data) != sha256.Size { + id := container.NewID() + + err := id.Parse(cid) + if err != nil { return nil, errors.New("can't decode container ID value") } - var buf [sha256.Size]byte - copy(buf[:], data) - - id := container.NewID() - id.SetSHA256(buf) - return id, nil } diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index c0d5801d..b5c5b33d 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -9,7 +9,6 @@ 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" @@ -165,20 +164,14 @@ func getSDKClient() (*client.Client, error) { // ownerFromString converts string with NEO3 wallet address to neofs owner ID. func ownerFromString(s string) (*owner.ID, error) { - var w owner.NEO3Wallet + result := owner.NewID() - // todo: move this into neofs-api-go `owner.NEO3WalletFromString` function - binaryWallet, err := base58.Decode(s) - if err != nil || len(binaryWallet) != len(w) { + err := result.Parse(s) + if err != nil { return nil, errors.New("can't decode owner ID wallet address") } - copy(w[:], binaryWallet) - - id := owner.NewID() - id.SetNeo3Wallet(&w) - - return id, nil + return result, nil } func printVerbose(format string, a ...interface{}) {