From 9c1c023f05e6b798d21db800bd542b3a4f66d7a9 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 16 Sep 2020 14:58:58 +0300 Subject: [PATCH] [#30] Update to latest neofs-api-go and fix conflicts Signed-off-by: Leonard Lyubich --- go.mod | 2 +- go.sum | 2 ++ pkg/core/object/address.go | 13 +++------- pkg/core/object/object.go | 27 +++++++++------------ pkg/local_object_storage/localstore/meta.go | 9 ++++++- pkg/services/accounting/morph/executor.go | 7 +----- 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 8082a68ec..42686c0cf 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/multiformats/go-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2 github.com/multiformats/go-multihash v0.0.13 // indirect github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78 - github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200911095622-47fd771ee4c5 + github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200916115135-ff325b877023 github.com/nspcc-dev/neofs-crypto v0.3.0 github.com/panjf2000/ants/v2 v2.3.0 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 86b76638d..2edcf1a54 100644 --- a/go.sum +++ b/go.sum @@ -271,6 +271,8 @@ github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200902121740-5a6dff8c83ba h1:S8YfqJ github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200902121740-5a6dff8c83ba/go.mod h1:f5Z4UggDgVgZXnDNr2ItdGwBpVYJBKlm5Yyu2XYEiAc= github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200911095622-47fd771ee4c5 h1:+/VTNh3tHfuBHF+Xyf/QVO/U7QTcWyJ0rPHl+b8i0kU= github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200911095622-47fd771ee4c5/go.mod h1:FsFd1z4YzoEgPlltsUgnqna9qhcF87RHYjot0pby2L4= +github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200916115135-ff325b877023 h1:tltnqudivH6TBzs4DEouLx9rwPUBuvn7bjm4EZyosUc= +github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200916115135-ff325b877023/go.mod h1:FsFd1z4YzoEgPlltsUgnqna9qhcF87RHYjot0pby2L4= 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/core/object/address.go b/pkg/core/object/address.go index 328e50ed8..905e10535 100644 --- a/pkg/core/object/address.go +++ b/pkg/core/object/address.go @@ -19,17 +19,12 @@ func (a *Address) MarshalStableV2() ([]byte, error) { } // AddressFromV2 converts v2 Address message to Address. -func AddressFromV2(aV2 *refs.Address) (*Address, error) { +func AddressFromV2(aV2 *refs.Address) *Address { if aV2 == nil { - return nil, nil - } - - a, err := object.AddressFromV2(aV2) - if err != nil { - return nil, err + return nil } return &Address{ - Address: a, - }, nil + Address: object.NewAddressFromV2(aV2), + } } diff --git a/pkg/core/object/object.go b/pkg/core/object/object.go index faffd1851..5aebab87c 100644 --- a/pkg/core/object/object.go +++ b/pkg/core/object/object.go @@ -3,6 +3,7 @@ package object import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" + "github.com/nspcc-dev/neofs-api-go/v2/refs" ) // Object represents the NeoFS object. @@ -17,12 +18,7 @@ type Object struct { // MarshalStableV2 marshals Object to v2 binary format. func (o *Object) MarshalStableV2() ([]byte, error) { if o != nil { - v2, err := o.ToV2(nil) // fixme: remove - if err != nil { - return nil, err - } - - return v2.StableMarshal(nil) + return o.ToV2().StableMarshal(nil) } return nil, nil @@ -31,8 +27,12 @@ func (o *Object) MarshalStableV2() ([]byte, error) { // Address returns address of the object. func (o *Object) Address() *Address { if o != nil { + aV2 := new(refs.Address) + aV2.SetObjectID(o.GetID().ToV2()) + aV2.SetContainerID(o.GetContainerID().ToV2()) + return &Address{ - Address: o.Object.Address(), + Address: object.NewAddressFromV2(aV2), } } @@ -40,19 +40,14 @@ func (o *Object) Address() *Address { } // FromV2 converts v2 Object message to Object. -func FromV2(oV2 *objectV2.Object) (*Object, error) { +func FromV2(oV2 *objectV2.Object) *Object { if oV2 == nil { - return nil, nil - } - - o, err := object.FromV2(oV2) - if err != nil { - return nil, err + return nil } return &Object{ - Object: o, - }, nil + Object: object.NewFromV2(oV2), + } } // FromBytes restores Object from binary format. diff --git a/pkg/local_object_storage/localstore/meta.go b/pkg/local_object_storage/localstore/meta.go index e270f84eb..27835d9c3 100644 --- a/pkg/local_object_storage/localstore/meta.go +++ b/pkg/local_object_storage/localstore/meta.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "io" + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/pkg/errors" ) @@ -44,8 +45,14 @@ func metaFromObject(o *object.Object) *ObjectMeta { // FIXME: remove hard-code meta := new(ObjectMeta) meta.savedAtEpoch = 10 + + raw := objectSDK.NewRaw() + raw.SetContainerID(o.GetContainerID()) + raw.SetOwnerID(o.GetOwnerID()) + // TODO: set other meta fields + meta.head = &object.Object{ - Object: o.CutPayload(), + Object: raw.Object(), } return meta diff --git a/pkg/services/accounting/morph/executor.go b/pkg/services/accounting/morph/executor.go index 9b6e73aaa..33384f1b8 100644 --- a/pkg/services/accounting/morph/executor.go +++ b/pkg/services/accounting/morph/executor.go @@ -20,12 +20,7 @@ func NewExecutor(client *wrapper.Wrapper) accountingSvc.ServiceExecutor { } func (s *morphExecutor) Balance(ctx context.Context, body *accounting.BalanceRequestBody) (*accounting.BalanceResponseBody, error) { - id, err := owner.IDFromV2(body.GetOwnerID()) - if err != nil { - return nil, err - } - - amount, err := s.client.BalanceOf(id) + amount, err := s.client.BalanceOf(owner.NewIDFromV2(body.GetOwnerID())) if err != nil { return nil, err }