[#770] pkg/morph/event: Add notary notifications support

Add handlers and parsers functionality for listener.
Separate notification and notary events by files.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-08-15 20:03:15 +03:00 committed by Pavel Karpy
parent 8f2924d6cf
commit c042f6a429
6 changed files with 376 additions and 29 deletions

View file

@ -3,6 +3,7 @@ package event
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
)
@ -19,20 +20,31 @@ type NotificationParserInfo struct {
p NotificationParser
}
type wrongPrmNumber struct {
exp, act int
// NotaryPreparator constructs NotaryEvent
// from the NotaryRequest event.
type NotaryPreparator interface {
Prepare(*payload.P2PNotaryRequest) (NotaryEvent, error)
}
// WrongNumberOfParameters returns an error about wrong number of smart contract parameters.
func WrongNumberOfParameters(exp, act int) error {
return &wrongPrmNumber{
exp: exp,
act: act,
}
// NotaryParser is a function that constructs Event
// from the NotaryEvent event.
type NotaryParser func(NotaryEvent) (Event, error)
// NotaryParserInfo is a structure that groups
// the parameters of particular notary request
// event parser.
type NotaryParserInfo struct {
notaryRequestTypes
p NotaryParser
}
func (s wrongPrmNumber) Error() string {
return fmt.Errorf("wrong parameter count: expected %d, has %d", s.exp, s.act).Error()
func (n *NotaryParserInfo) parser() NotaryParser {
return n.p
}
func (n *NotaryParserInfo) SetParser(p NotaryParser) {
n.p = p
}
// SetParser is an event parser setter.
@ -52,3 +64,19 @@ func (s *NotificationParserInfo) SetType(v Type) {
func (s NotificationParserInfo) getType() Type {
return s.typ
}
type wrongPrmNumber struct {
exp, act int
}
// WrongNumberOfParameters returns an error about wrong number of smart contract parameters.
func WrongNumberOfParameters(exp, act int) error {
return &wrongPrmNumber{
exp: exp,
act: act,
}
}
func (s wrongPrmNumber) Error() string {
return fmt.Errorf("wrong parameter count: expected %d, has %d", s.exp, s.act).Error()
}