frostfs-api-go/pkg/container/fmt.go
Evgenii Stratonikov 9ddfcdfbba [#277] go.mod: remove pkg/errors
Use stdlib `errors` instead.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-05-19 11:14:56 +03:00

28 lines
703 B
Go

package container
import (
"fmt"
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/v2/container"
)
// NewVerifiedFromV2 constructs Container from NeoFS API V2 Container message.
// Returns error if message does not meet NeoFS API V2 specification.
//
// Additionally checks if message carries supported version.
func NewVerifiedFromV2(cnrV2 *container.Container) (*Container, error) {
cnr := NewContainerFromV2(cnrV2)
// check version support
if err := pkg.IsSupportedVersion(cnr.Version()); err != nil {
return nil, err
}
// check nonce format
if _, err := cnr.NonceUUID(); err != nil {
return nil, fmt.Errorf("invalid nonce: %w", err)
}
return cnr, nil
}