From c4f8c7a9b2f36eb76da15c5b9f44938595dff7d7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 7 Jun 2021 14:17:18 +0300 Subject: [PATCH] oracle/neofs: update neofs-api-go Update neofs-api-go to `v1.27.1`. Add `WithURIAddress` client option. Stop using `V2` abstractions outside of the `api-go` library. Signed-off-by: Pavel Karpy --- go.mod | 2 +- go.sum | 5 +++++ pkg/services/oracle/neofs/neofs.go | 18 ++++++------------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index daa944e09..026b389be 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/mr-tron/base58 v1.1.2 github.com/nspcc-dev/dbft v0.0.0-20210302103605-cc75991b7cfb - github.com/nspcc-dev/neofs-api-go v1.24.0 + github.com/nspcc-dev/neofs-api-go v1.27.1 github.com/nspcc-dev/rfc6979 v0.2.0 github.com/pierrec/lz4 v2.5.2+incompatible github.com/prometheus/client_golang v1.2.1 diff --git a/go.sum b/go.sum index b01d2974d..c948f8383 100644 --- a/go.sum +++ b/go.sum @@ -165,8 +165,13 @@ github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y= github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU= github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= github.com/nspcc-dev/neo-go v0.91.0/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc= +github.com/nspcc-dev/neo-go v0.95.1/go.mod h1:bW07ge1WFXsBgqrcPpLUr6OcyQxHqM26MZNesWMdH0c= github.com/nspcc-dev/neofs-api-go v1.24.0 h1:ZxROxsaCmIiv56sNHPf/FBeGHTT51fldp6uhDq0xwVE= github.com/nspcc-dev/neofs-api-go v1.24.0/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8= +github.com/nspcc-dev/neofs-api-go v1.27.0 h1:SiqD1wb50l/ahCNV8/D9R3ua/sFS8oRCJ5jV+ux6AzE= +github.com/nspcc-dev/neofs-api-go v1.27.0/go.mod h1:i0Cwgvcu9A4M4e58pydbXFisUhSxpfljmuWFPIp2btE= +github.com/nspcc-dev/neofs-api-go v1.27.1 h1:ONdKOnm0/hK6m38VTUliCHY6RTxg+IpAzY4G+BeOZG4= +github.com/nspcc-dev/neofs-api-go v1.27.1/go.mod h1:i0Cwgvcu9A4M4e58pydbXFisUhSxpfljmuWFPIp2btE= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM= diff --git a/pkg/services/oracle/neofs/neofs.go b/pkg/services/oracle/neofs/neofs.go index 199310569..a90bd4bde 100644 --- a/pkg/services/oracle/neofs/neofs.go +++ b/pkg/services/oracle/neofs/neofs.go @@ -1,7 +1,6 @@ package neofs import ( - "bytes" "context" "errors" "fmt" @@ -10,13 +9,11 @@ import ( "strings" "unicode/utf8" - "github.com/gogo/protobuf/jsonpb" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" - objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object" ) const ( @@ -50,7 +47,7 @@ func Get(ctx context.Context, priv *keys.PrivateKey, u *url.URL, addr string) ([ return nil, err } - c, err := client.New(&priv.PrivateKey, client.WithAddress(addr)) + c, err := client.New(client.WithDefaultPrivateKey(&priv.PrivateKey), client.WithURIAddress(addr, nil)) if err != nil { return nil, err } @@ -96,7 +93,7 @@ func parseNeoFSURL(u *url.URL) (*object.Address, []string, error) { return objectAddr, ps[2:], nil } -func getPayload(ctx context.Context, c *client.Client, addr *object.Address) ([]byte, error) { +func getPayload(ctx context.Context, c client.Client, addr *object.Address) ([]byte, error) { obj, err := c.GetObject(ctx, new(client.GetObjectParams).WithAddress(addr)) if err != nil { return nil, err @@ -104,7 +101,7 @@ func getPayload(ctx context.Context, c *client.Client, addr *object.Address) ([] return checkUTF8(obj.Payload()) } -func getRange(ctx context.Context, c *client.Client, addr *object.Address, ps ...string) ([]byte, error) { +func getRange(ctx context.Context, c client.Client, addr *object.Address, ps ...string) ([]byte, error) { if len(ps) == 0 { return nil, ErrInvalidRange } @@ -119,18 +116,15 @@ func getRange(ctx context.Context, c *client.Client, addr *object.Address, ps .. return checkUTF8(data) } -func getHeader(ctx context.Context, c *client.Client, addr *object.Address) ([]byte, error) { +func getHeader(ctx context.Context, c client.Client, addr *object.Address) ([]byte, error) { obj, err := c.GetObjectHeader(ctx, new(client.ObjectHeaderParams).WithAddress(addr)) if err != nil { return nil, err } - msg := objectv2.ObjectToGRPCMessage(obj.ToV2()).Header - b := bytes.NewBuffer(nil) - err = new(jsonpb.Marshaler).Marshal(b, msg) - return b.Bytes(), err + return obj.MarshalHeaderJSON() } -func getHash(ctx context.Context, c *client.Client, addr *object.Address, ps ...string) ([]byte, error) { +func getHash(ctx context.Context, c client.Client, addr *object.Address, ps ...string) ([]byte, error) { if len(ps) == 0 || ps[0] == "" { // hash of the full payload obj, err := c.GetObjectHeader(ctx, new(client.ObjectHeaderParams).WithAddress(addr)) if err != nil {