2021-05-18 07:40:21 +00:00
|
|
|
package rolemanagement
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
2021-10-22 10:06:08 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
2021-05-18 07:40:21 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Designate represents designation event of the mainnet RoleManagement contract.
|
|
|
|
type Designate struct {
|
|
|
|
Role noderoles.Role
|
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (Designate) MorphEvent() {}
|
|
|
|
|
|
|
|
// ParseDesignate from notification into container event structure.
|
2021-10-22 10:06:08 +00:00
|
|
|
func ParseDesignate(e *subscriptions.NotificationEvent) (event.Event, error) {
|
|
|
|
params, err := event.ParseStackArray(e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not parse stack items from notify event: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-05-18 07:40:21 +00:00
|
|
|
if len(params) != 2 {
|
|
|
|
return nil, event.WrongNumberOfParameters(2, len(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
bi, err := params[0].TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid stackitem type: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Designate{Role: noderoles.Role(bi.Int64())}, nil
|
|
|
|
}
|