[#149] sdk/container: Add function to calculate identifier

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-17 13:08:04 +03:00 committed by Stanislav Bogatyrev
parent fea8cd48f2
commit f8e7a577de

View file

@ -1,6 +1,8 @@
package container
import (
"crypto/sha256"
"github.com/nspcc-dev/neofs-api-go/v2/container"
)
@ -53,3 +55,17 @@ func NewContainerFromV2(c *container.Container) *Container {
return cnr
}
// CalculateID calculates container identifier
// based on its structure.
func CalculateID(c *Container) *ID {
data, err := c.ToV2().StableMarshal(nil)
if err != nil {
panic(err)
}
id := NewID()
id.SetSHA256(sha256.Sum256(data))
return id
}