From c4f8c7a9b2f36eb76da15c5b9f44938595dff7d7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 7 Jun 2021 14:17:18 +0300 Subject: [PATCH 1/3] 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 { From 874c56c77b40bb62034ed4cf99f49188265b2522 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 7 Jun 2021 14:20:21 +0300 Subject: [PATCH 2/3] oracle/neofs: stop using deprecated types Signed-off-by: Pavel Karpy --- pkg/services/oracle/neofs/neofs.go | 4 ++-- pkg/services/oracle/neofs/neofs_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/services/oracle/neofs/neofs.go b/pkg/services/oracle/neofs/neofs.go index a90bd4bde..372a3b2c6 100644 --- a/pkg/services/oracle/neofs/neofs.go +++ b/pkg/services/oracle/neofs/neofs.go @@ -12,7 +12,7 @@ import ( "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" + cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" "github.com/nspcc-dev/neofs-api-go/pkg/object" ) @@ -77,7 +77,7 @@ func parseNeoFSURL(u *url.URL) (*object.Address, []string, error) { return nil, nil, ErrMissingObject } - containerID := container.NewID() + containerID := cid.New() if err := containerID.Parse(ps[0]); err != nil { return nil, nil, fmt.Errorf("%w: %v", ErrInvalidContainer, err) } diff --git a/pkg/services/oracle/neofs/neofs_test.go b/pkg/services/oracle/neofs/neofs_test.go index 82b25d4be..002ab9ea2 100644 --- a/pkg/services/oracle/neofs/neofs_test.go +++ b/pkg/services/oracle/neofs/neofs_test.go @@ -5,7 +5,7 @@ import ( "net/url" "testing" - "github.com/nspcc-dev/neofs-api-go/pkg/container" + cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/stretchr/testify/require" ) @@ -37,8 +37,8 @@ func TestParseRange(t *testing.T) { func TestParseNeoFSURL(t *testing.T) { cStr := "C3swfg8MiMJ9bXbeFG6dWJTCoHp9hAEZkHezvbSwK1Cc" - cid := container.NewID() - require.NoError(t, cid.Parse(cStr)) + containerID := cid.New() + require.NoError(t, containerID.Parse(cStr)) oStr := "3nQH1L8u3eM9jt2mZCs6MyjzdjerdSzBkXCYYj4M4Znk" oid := object.NewID() @@ -46,7 +46,7 @@ func TestParseNeoFSURL(t *testing.T) { validPrefix := "neofs:" + cStr + "/" + oStr objectAddr := object.NewAddress() - objectAddr.SetContainerID(cid) + objectAddr.SetContainerID(containerID) objectAddr.SetObjectID(oid) testCases := []struct { From 32948180fbe00e404650b900dc62d15993840e3f Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 10 Jun 2021 16:15:33 +0300 Subject: [PATCH 3/3] execute `go mod tidy` Signed-off-by: Pavel Karpy --- go.mod | 1 - go.sum | 4 ---- 2 files changed, 5 deletions(-) diff --git a/go.mod b/go.mod index 026b389be..9a784e170 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/btcsuite/btcd v0.20.1-beta github.com/dgraph-io/badger/v2 v2.0.3 github.com/go-redis/redis v6.10.2+incompatible - github.com/gogo/protobuf v1.1.1 github.com/gorilla/websocket v1.4.2 github.com/hashicorp/golang-lru v0.5.4 github.com/mr-tron/base58 v1.1.2 diff --git a/go.sum b/go.sum index c948f8383..771128fe8 100644 --- a/go.sum +++ b/go.sum @@ -85,7 +85,6 @@ github.com/go-redis/redis v6.10.2+incompatible h1:SLbqrO/Ik1nhXA5/cbEs1P5MUBo1Qq github.com/go-redis/redis v6.10.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= -github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -166,10 +165,7 @@ github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkP 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=