[#149] sdk/container: Add function to calculate identifier
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
fea8cd48f2
commit
f8e7a577de
1 changed files with 16 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue