2020-11-03 12:03:41 +03:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-18 11:12:51 +03:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2020-11-03 12:03:41 +03: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 12:43:52 +03:00
|
|
|
// CheckFormat conducts an initial check of the v2 container data.
|
2020-11-03 12:03:41 +03: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 12:43:52 +03:00
|
|
|
if c.PlacementPolicy() == nil {
|
2020-11-03 12:03:41 +03:00
|
|
|
return errNilPolicy
|
|
|
|
}
|
|
|
|
|
2020-11-16 12:43:52 +03:00
|
|
|
if err := pkg.IsSupportedVersion(c.Version()); err != nil {
|
2021-05-18 11:12:51 +03:00
|
|
|
return fmt.Errorf("incorrect version: %w", err)
|
2020-11-03 12:03:41 +03:00
|
|
|
}
|
|
|
|
|
2020-11-17 11:51:49 +03:00
|
|
|
if ln := len(c.OwnerID().ToV2().GetValue()); ln != owner.NEO3WalletSize {
|
2021-05-18 11:12:51 +03:00
|
|
|
return fmt.Errorf("incorrect owner identifier: expected length %d != %d", owner.NEO3WalletSize, ln)
|
2020-11-03 12:03:41 +03:00
|
|
|
}
|
|
|
|
|
2020-12-24 13:20:20 +03:00
|
|
|
if _, err := c.NonceUUID(); err != nil {
|
2021-05-18 11:12:51 +03:00
|
|
|
return fmt.Errorf("incorrect nonce: %w", err)
|
2020-11-03 12:03:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|