2021-11-26 12:19:20 +00:00
|
|
|
package subnetevents
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-07-28 16:22:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2021-11-26 12:19:20 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Delete structures information about the notification generated by Delete method of Subnet contract.
|
|
|
|
type Delete struct {
|
|
|
|
txHash util.Uint256
|
|
|
|
|
|
|
|
id []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (Delete) MorphEvent() {}
|
|
|
|
|
|
|
|
// ID returns identifier of the removed subnet in a binary format of NeoFS API protocol.
|
|
|
|
func (x Delete) ID() []byte {
|
|
|
|
return x.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// TxHash returns hash of the transaction which thrown the notification event.
|
2021-11-28 09:43:03 +00:00
|
|
|
// Makes sense only in notary environments.
|
2021-11-26 12:19:20 +00:00
|
|
|
func (x Delete) TxHash() util.Uint256 {
|
|
|
|
return x.txHash
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseDelete parses the notification about the removal of a subnet which has been thrown
|
|
|
|
// by the appropriate method of the Subnet contract.
|
|
|
|
//
|
|
|
|
// Resulting event is of Delete type.
|
2022-07-28 16:22:32 +00:00
|
|
|
func ParseDelete(e *state.ContainedNotificationEvent) (event.Event, error) {
|
2021-11-26 12:19:20 +00:00
|
|
|
var (
|
|
|
|
ev Delete
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
items, err := event.ParseStackArray(e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("parse stack array: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-11-28 09:31:09 +00:00
|
|
|
const itemNumDelete = 1
|
|
|
|
|
2021-11-26 12:19:20 +00:00
|
|
|
if ln := len(items); ln != itemNumDelete {
|
|
|
|
return nil, event.WrongNumberOfParameters(itemNumDelete, ln)
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse ID
|
|
|
|
ev.id, err = client.BytesFromStackItem(items[0])
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("id item: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.txHash = e.Container
|
|
|
|
|
|
|
|
return ev, nil
|
|
|
|
}
|