-
Notifications
You must be signed in to change notification settings - Fork 38
/
add_peer_notary.go
50 lines (40 loc) · 1.04 KB
/
add_peer_notary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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) {
const expectedItemNumAddPeer = 1
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.notaryRequest = ne.Raw()
return ev, nil
}