2020-09-03 14:04:04 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-07-28 16:22:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2021-09-23 16:12:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
2020-09-03 14:04:04 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AddPeer struct {
|
|
|
|
node []byte
|
2021-09-23 16:12:49 +00:00
|
|
|
|
|
|
|
// For notary notifications only.
|
|
|
|
// Contains raw transactions of notary request.
|
|
|
|
notaryRequest *payload.P2PNotaryRequest
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (AddPeer) MorphEvent() {}
|
|
|
|
|
|
|
|
func (s AddPeer) Node() []byte {
|
|
|
|
return s.node
|
|
|
|
}
|
|
|
|
|
2021-09-23 16:12:49 +00:00
|
|
|
// NotaryRequest returns raw notary request if notification
|
|
|
|
// was received via notary service. Otherwise, returns nil.
|
|
|
|
func (s AddPeer) NotaryRequest() *payload.P2PNotaryRequest {
|
|
|
|
return s.notaryRequest
|
|
|
|
}
|
|
|
|
|
2021-09-08 13:54:45 +00:00
|
|
|
const expectedItemNumAddPeer = 1
|
|
|
|
|
2022-07-28 16:22:32 +00:00
|
|
|
func ParseAddPeer(e *state.ContainedNotificationEvent) (event.Event, error) {
|
2020-09-03 14:04:04 +00:00
|
|
|
var (
|
|
|
|
ev AddPeer
|
|
|
|
err 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)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ln := len(params); ln != expectedItemNumAddPeer {
|
2021-09-08 13:54:45 +00:00
|
|
|
return nil, event.WrongNumberOfParameters(expectedItemNumAddPeer, ln)
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 10:06:08 +00:00
|
|
|
ev.node, err = client.BytesFromStackItem(params[0])
|
2020-09-03 14:04:04 +00:00
|
|
|
if err != nil {
|
2021-08-09 17:09:16 +00:00
|
|
|
return nil, fmt.Errorf("could not get raw nodeinfo: %w", err)
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ev, nil
|
|
|
|
}
|