frostfs-node/pkg/morph/event/netmap/add_peer_notary.go
Dmitrii Stepanov d00b1c0d29
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
[#280] ir: Add netmap processor unit tests
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-05-02 08:48:07 +00:00

49 lines
1 KiB
Go

package netmap
import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
)
func (s *AddPeer) setNode(v []byte) {
if v != nil {
s.NodeBytes = v
}
}
const (
// AddPeerNotaryEvent is method name for netmap `addPeer` operation
// in `Netmap` contract. Is used as identificator for notary
// peer addition requests.
AddPeerNotaryEvent = "addPeer"
)
// ParseAddPeerNotary from NotaryEvent into netmap event structure.
func ParseAddPeerNotary(ne event.NotaryEvent) (event.Event, error) {
var (
ev AddPeer
currentOp opcode.Opcode
)
fieldNum := 0
for _, op := range ne.Params() {
currentOp = op.Code()
switch {
case opcode.PUSHDATA1 <= currentOp && currentOp <= opcode.PUSHDATA4:
if fieldNum == expectedItemNumAddPeer {
return nil, event.UnexpectedArgNumErr(AddPeerNotaryEvent)
}
ev.setNode(op.Param())
fieldNum++
default:
return nil, event.UnexpectedOpcode(AddPeerNotaryEvent, currentOp)
}
}
ev.Request = ne.Raw()
return ev, nil
}