41eaa1e246
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>
44 lines
1,021 B
Go
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
|
|
}
|