Evgenii Stratonikov
d0ce835fbf
They are decoupled, but it is an error to have a handler without a corresponding parser. Register them together on the code level and get rid of unreachable code. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package event
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
|
)
|
|
|
|
// Handler is an Event processing function.
|
|
type Handler func(context.Context, Event)
|
|
|
|
// BlockHandler is a chain block processing function.
|
|
type BlockHandler func(context.Context, *block.Block)
|
|
|
|
// NotificationHandlerInfo is a structure that groups
|
|
// the parameters of the handler of particular
|
|
// contract event.
|
|
type NotificationHandlerInfo struct {
|
|
scriptHashWithType
|
|
|
|
parser NotificationParser
|
|
handlers []Handler
|
|
}
|
|
|
|
// SetParser is an event handler setter.
|
|
func (s *NotificationHandlerInfo) SetParser(p NotificationParser) {
|
|
s.parser = p
|
|
}
|
|
|
|
// AddHandler adds an event handler.
|
|
func (s *NotificationHandlerInfo) AddHandler(v Handler) {
|
|
s.handlers = append(s.handlers, v)
|
|
}
|
|
|
|
// Handler returns an event handler.
|
|
func (s NotificationHandlerInfo) Handlers() []Handler {
|
|
return s.handlers
|
|
}
|
|
|
|
// NotaryHandlerInfo is a structure that groups
|
|
// the parameters of the handler of particular
|
|
// notary event.
|
|
type NotaryHandlerInfo struct {
|
|
notaryRequestTypes
|
|
|
|
h Handler
|
|
}
|
|
|
|
// SetHandler is an event handler setter.
|
|
func (nhi *NotaryHandlerInfo) SetHandler(v Handler) {
|
|
nhi.h = v
|
|
}
|
|
|
|
// Handler returns an event handler.
|
|
func (nhi NotaryHandlerInfo) Handler() Handler {
|
|
return nhi.h
|
|
}
|