2020-07-10 14:17:51 +00:00
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-07-10 14:17:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Parser is a function that constructs Event
|
|
|
|
// from the StackItem list.
|
2020-10-26 14:46:15 +00:00
|
|
|
type Parser func([]stackitem.Item) (Event, error)
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
// ParserInfo is a structure that groups
|
|
|
|
// the parameters of particular contract
|
|
|
|
// notification event parser.
|
|
|
|
type ParserInfo struct {
|
|
|
|
scriptHashWithType
|
|
|
|
|
|
|
|
p Parser
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return fmt.Errorf("wrong parameter count: expected %d, has %d", s.exp, s.act).Error()
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetParser is an event parser setter.
|
|
|
|
func (s *ParserInfo) SetParser(v Parser) {
|
|
|
|
s.p = v
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ParserInfo) parser() Parser {
|
|
|
|
return s.p
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetType is an event type setter.
|
|
|
|
func (s *ParserInfo) SetType(v Type) {
|
|
|
|
s.typ = v
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ParserInfo) getType() Type {
|
|
|
|
return s.typ
|
|
|
|
}
|