[#505] morph/container: Do not return ID from Wrapper.Put method

`Put` method of the wrapper over the Container contract's client does not
modify passed binary container, so it makes no sense to calculate the
identifier.

`Put` method returns the error only from now. Function `Put` calculates
identifier itself since it is still required by function signature.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2021-05-19 18:39:05 +03:00 committed by Alex Vanin
parent 565ad51b42
commit 3a5849fadb
1 changed files with 13 additions and 8 deletions

View File

@ -32,7 +32,15 @@ func Put(w *Wrapper, cnr *container.Container, sig *pkg.Signature) (*container.I
return nil, fmt.Errorf("can't marshal container: %w", err)
}
return w.Put(data, sig.Key(), sig.Sign())
err = w.Put(data, sig.Key(), sig.Sign())
if err != nil {
return nil, err
}
id := container.NewID()
id.SetSHA256(sha256.Sum256(data))
return id, nil
}
// Put saves binary container with its key and signature
@ -40,9 +48,9 @@ func Put(w *Wrapper, cnr *container.Container, sig *pkg.Signature) (*container.I
//
// Returns calculated container identifier and any error
// encountered that caused the saving to interrupt.
func (w *Wrapper) Put(cnr, key, sig []byte) (*container.ID, error) {
func (w *Wrapper) Put(cnr, key, sig []byte) error {
if len(sig) == 0 || len(key) == 0 {
return nil, errNilArgument
return errNilArgument
}
var args client.PutArgs
@ -53,13 +61,10 @@ func (w *Wrapper) Put(cnr, key, sig []byte) (*container.ID, error) {
err := w.client.Put(args)
if err != nil {
return nil, err
return err
}
id := container.NewID()
id.SetSHA256(sha256.Sum256(cnr))
return id, nil
return nil
}
// Get reads the container from NeoFS system by identifier