2020-07-10 14:17:51 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-10-22 10:06:08 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
2020-07-24 13:54:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
2020-07-10 14:17:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewEpoch is a new epoch Neo:Morph event.
|
|
|
|
type NewEpoch struct {
|
|
|
|
num uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (NewEpoch) MorphEvent() {}
|
|
|
|
|
|
|
|
// EpochNumber returns new epoch number.
|
|
|
|
func (s NewEpoch) EpochNumber() uint64 {
|
|
|
|
return s.num
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseNewEpoch is a parser of new epoch notification event.
|
|
|
|
//
|
|
|
|
// Result is type of NewEpoch.
|
2021-10-22 10:06:08 +00:00
|
|
|
func ParseNewEpoch(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)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ln := len(params); ln != 1 {
|
2020-07-10 14:17:51 +00:00
|
|
|
return nil, event.WrongNumberOfParameters(1, ln)
|
|
|
|
}
|
|
|
|
|
2021-10-22 10:06:08 +00:00
|
|
|
prmEpochNum, err := client.IntFromStackItem(params[0])
|
2020-07-10 14:17:51 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get integer epoch number: %w", err)
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NewEpoch{
|
|
|
|
num: uint64(prmEpochNum),
|
|
|
|
}, nil
|
|
|
|
}
|