2021-11-26 12:19:20 +00:00
|
|
|
package subnetevents
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Delete represents a notification about NeoFS subnet removal.
|
2021-11-26 12:19:20 +00:00
|
|
|
// Generated by a contract when intending to delete a subnet.
|
|
|
|
type Delete interface {
|
2022-04-21 11:28:05 +00:00
|
|
|
// Contains the ID of the subnet to be removed.
|
2021-11-26 12:19:20 +00:00
|
|
|
eventWithID
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteValidator asserts intent to remove a subnet.
|
|
|
|
type DeleteValidator struct{}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Assert processes the attempt to remove a subnet. It approves the removal through nil return.
|
2021-11-26 12:19:20 +00:00
|
|
|
//
|
|
|
|
// All read errors of Delete are forwarded.
|
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// It returns an error on:
|
2021-11-26 12:19:20 +00:00
|
|
|
// * zero subnet creation;
|
|
|
|
// * empty ID or different from the one wired into info;
|
|
|
|
// * empty owner ID or different from the one wired into info.
|
|
|
|
func (x DeleteValidator) Assert(event Delete) error {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// read ID
|
|
|
|
var id subnetid.ID
|
|
|
|
if err = event.ReadID(&id); err != nil {
|
|
|
|
return fmt.Errorf("read ID: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// prevent zero subnet removal
|
|
|
|
if subnetid.IsZero(id) {
|
|
|
|
return zeroSubnetOp{
|
|
|
|
op: "removal",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|