2020-11-03 09:03:41 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2020-11-03 09:03:41 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
|
|
|
)
|
|
|
|
|
|
|
|
var errNilPolicy = errors.New("placement policy is nil")
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
// CheckFormat conducts an initial check of the v2 container data.
|
2020-11-03 09:03:41 +00:00
|
|
|
//
|
|
|
|
// It is expected that if a container fails this test,
|
|
|
|
// it will not be inner-ring approved.
|
|
|
|
func CheckFormat(c *container.Container) error {
|
2020-11-16 09:43:52 +00:00
|
|
|
if c.PlacementPolicy() == nil {
|
2020-11-03 09:03:41 +00:00
|
|
|
return errNilPolicy
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
if err := pkg.IsSupportedVersion(c.Version()); err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return fmt.Errorf("incorrect version: %w", err)
|
2020-11-03 09:03:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 08:51:49 +00:00
|
|
|
if ln := len(c.OwnerID().ToV2().GetValue()); ln != owner.NEO3WalletSize {
|
2021-05-18 08:12:51 +00:00
|
|
|
return fmt.Errorf("incorrect owner identifier: expected length %d != %d", owner.NEO3WalletSize, ln)
|
2020-11-03 09:03:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 10:20:20 +00:00
|
|
|
if _, err := c.NonceUUID(); err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return fmt.Errorf("incorrect nonce: %w", err)
|
2020-11-03 09:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|