From 32828d2b907f34c058a482d5b85294f625239d04 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 25 May 2021 18:25:34 +0300 Subject: [PATCH] [#525] morph/container: Do not accept signature in Put function In previous implementation wrapper over the Container contract's client accepted the signature of the container in addition to itself. After recent changes in API Go lib container carries its signature. Thus, it is redundant to pass the container signature separately. Make `wrapper.Put` method to accept `Container` only. Signed-off-by: Leonard Lyubich --- pkg/morph/client/container/wrapper/container.go | 7 +++++-- pkg/services/container/morph/executor.go | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/morph/client/container/wrapper/container.go b/pkg/morph/client/container/wrapper/container.go index aa49a58e..c922cac3 100644 --- a/pkg/morph/client/container/wrapper/container.go +++ b/pkg/morph/client/container/wrapper/container.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" "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/owner" v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs" core "github.com/nspcc-dev/neofs-node/pkg/core/container" @@ -22,7 +23,7 @@ var ( // along with sig.Key() and sig.Sign(). // // Returns error if container is nil. -func Put(w *Wrapper, cnr *container.Container, sig *pkg.Signature) (*container.ID, error) { +func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) { if cnr == nil { return nil, errNilArgument } @@ -32,12 +33,14 @@ func Put(w *Wrapper, cnr *container.Container, sig *pkg.Signature) (*container.I return nil, fmt.Errorf("can't marshal container: %w", err) } + sig := cnr.Signature() + err = w.Put(data, sig.Key(), sig.Sign()) if err != nil { return nil, err } - id := container.NewID() + id := cid.New() id.SetSHA256(sha256.Sum256(data)) return id, nil diff --git a/pkg/services/container/morph/executor.go b/pkg/services/container/morph/executor.go index d17d6013..bda49b17 100644 --- a/pkg/services/container/morph/executor.go +++ b/pkg/services/container/morph/executor.go @@ -30,9 +30,11 @@ func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) return nil, fmt.Errorf("invalid format of the container structure: %w", err) } - sig := body.GetSignature() + cnr.SetSignature( + pkg.NewSignatureFromV2(body.GetSignature()), + ) - cid, err := wrapper.Put(s.wrapper, cnr, pkg.NewSignatureFromV2(sig)) + cid, err := wrapper.Put(s.wrapper, cnr) if err != nil { return nil, err }