frostfs-node/pkg/morph/event/netmap/add_peer.go
Dmitrii Stepanov d00b1c0d29 [#280] ir: Add netmap processor unit tests
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-05-02 08:48:07 +00:00

56 lines
1.3 KiB
Go

package netmap
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
)
type AddPeer struct {
NodeBytes []byte
// For notary notifications only.
// Contains raw transactions of notary request.
Request *payload.P2PNotaryRequest
}
// MorphEvent implements Neo:Morph Event interface.
func (AddPeer) MorphEvent() {}
func (s AddPeer) Node() []byte {
return s.NodeBytes
}
// NotaryRequest returns raw notary request if notification
// was received via notary service. Otherwise, returns nil.
func (s AddPeer) NotaryRequest() *payload.P2PNotaryRequest {
return s.Request
}
const expectedItemNumAddPeer = 1
func ParseAddPeer(e *state.ContainedNotificationEvent) (event.Event, error) {
var (
ev AddPeer
err 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 != expectedItemNumAddPeer {
return nil, event.WrongNumberOfParameters(expectedItemNumAddPeer, ln)
}
ev.NodeBytes, err = client.BytesFromStackItem(params[0])
if err != nil {
return nil, fmt.Errorf("could not get raw nodeinfo: %w", err)
}
return ev, nil
}