2021-05-18 07:40:21 +00:00
|
|
|
package rolemanagement
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/morph/event"
|
2021-05-18 07:40:21 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
2022-07-28 16:22:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2021-11-10 11:05:51 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2021-05-18 07:40:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Designate represents designation event of the mainnet RoleManagement contract.
|
|
|
|
type Designate struct {
|
|
|
|
Role noderoles.Role
|
2021-11-10 11:05:51 +00:00
|
|
|
|
|
|
|
// TxHash is used in notary environmental
|
|
|
|
// for calculating unique but same for
|
|
|
|
// all notification receivers values.
|
|
|
|
TxHash util.Uint256
|
2021-05-18 07:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (Designate) MorphEvent() {}
|
|
|
|
|
|
|
|
// ParseDesignate from notification into container event structure.
|
2022-07-28 16:22:32 +00:00
|
|
|
func ParseDesignate(e *state.ContainedNotificationEvent) (event.Event, error) {
|
2021-10-22 10:06:08 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-11-10 11:05:51 +00:00
|
|
|
return Designate{
|
|
|
|
Role: noderoles.Role(bi.Int64()),
|
|
|
|
TxHash: e.Container,
|
|
|
|
}, nil
|
2021-05-18 07:40:21 +00:00
|
|
|
}
|