2020-07-10 14:17:51 +00:00
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-07-28 16:22:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2021-08-15 17:03:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
2020-07-10 14:17:51 +00:00
|
|
|
)
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
// NotificationParser is a function that constructs Event
|
2020-07-10 14:17:51 +00:00
|
|
|
// from the StackItem list.
|
2022-07-28 16:22:32 +00:00
|
|
|
type NotificationParser func(*state.ContainedNotificationEvent) (Event, error)
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
// NotificationParserInfo is a structure that groups
|
2020-07-10 14:17:51 +00:00
|
|
|
// the parameters of particular contract
|
|
|
|
// notification event parser.
|
2021-08-12 15:24:17 +00:00
|
|
|
type NotificationParserInfo struct {
|
2020-07-10 14:17:51 +00:00
|
|
|
scriptHashWithType
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
p NotificationParser
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 17:03:15 +00:00
|
|
|
// NotaryPreparator constructs NotaryEvent
|
|
|
|
// from the NotaryRequest event.
|
|
|
|
type NotaryPreparator interface {
|
|
|
|
Prepare(*payload.P2PNotaryRequest) (NotaryEvent, error)
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 17:03:15 +00:00
|
|
|
// 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
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 17:03:15 +00:00
|
|
|
func (n *NotaryParserInfo) parser() NotaryParser {
|
|
|
|
return n.p
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NotaryParserInfo) SetParser(p NotaryParser) {
|
|
|
|
n.p = p
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetParser is an event parser setter.
|
2021-08-12 15:24:17 +00:00
|
|
|
func (s *NotificationParserInfo) SetParser(v NotificationParser) {
|
2020-07-10 14:17:51 +00:00
|
|
|
s.p = v
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
func (s NotificationParserInfo) parser() NotificationParser {
|
2020-07-10 14:17:51 +00:00
|
|
|
return s.p
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetType is an event type setter.
|
2021-08-12 15:24:17 +00:00
|
|
|
func (s *NotificationParserInfo) SetType(v Type) {
|
2020-07-10 14:17:51 +00:00
|
|
|
s.typ = v
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
func (s NotificationParserInfo) getType() Type {
|
2020-07-10 14:17:51 +00:00
|
|
|
return s.typ
|
|
|
|
}
|
2021-08-15 17:03:15 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|