frostfs-node/pkg/innerring/processors/subnet/delete.go
Leonard Lyubich 41eaa1e246 [#973] ir: Listen and process Put/Delete events of Subnet contract
Define notification events, implement parsers. Add morph client of
Subnet contract. Listen, verify and approve events in Inner Ring app.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-11-28 16:15:18 +03:00

44 lines
1,021 B
Go

package subnetevents
import (
"fmt"
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
)
// Delete represents notification about NeoFS subnet removal.
// Generated by a contract when intending to delete a subnet.
type Delete interface {
// Contains ID of the subnet to be removed.
eventWithID
}
// DeleteValidator asserts intent to remove a subnet.
type DeleteValidator struct{}
// Assert processes the attempt to remove a subnet. Approves the removal through nil return.
//
// All read errors of Delete are forwarded.
//
// Returns an error on:
// * 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
}