forked from TrueCloudLab/frostfs-node
[#815] morph/event/netmap: Add addPeer
notary notification support
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
01df4ffa61
commit
00caed8d3d
4 changed files with 113 additions and 20 deletions
47
pkg/morph/event/netmap/add_peer_notary.go
Normal file
47
pkg/morph/event/netmap/add_peer_notary.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package netmap
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
)
|
||||
|
||||
func (s *AddPeer) setNode(v []byte) {
|
||||
if v != nil {
|
||||
s.node = 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)
|
||||
}
|
||||
}
|
||||
|
||||
return ev, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue