2020-09-03 14:04:04 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
type AddPeer struct {
|
2023-04-27 14:57:27 +00:00
|
|
|
NodeBytes []byte
|
2021-09-23 16:12:49 +00:00
|
|
|
|
|
|
|
// For notary notifications only.
|
|
|
|
// Contains raw transactions of notary request.
|
2023-04-27 14:57:27 +00:00
|
|
|
Request *payload.P2PNotaryRequest
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (AddPeer) MorphEvent() {}
|
|
|
|
|
|
|
|
func (s AddPeer) Node() []byte {
|
2023-04-27 14:57:27 +00:00
|
|
|
return s.NodeBytes
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-04-27 14:57:27 +00:00
|
|
|
return s.Request
|
2021-09-23 16:12:49 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-04-27 14:57:27 +00:00
|
|
|
ev.NodeBytes, 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
|
|
|
|
}
|