frostfs-node/pkg/innerring/bindings.go

40 lines
1.1 KiB
Go
Raw Normal View History

2020-07-24 13:54:03 +00:00
package innerring
import (
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
)
type (
// ContractProcessor interface defines functions for binding event producers
// such as event.Listener and Timers with contract processor.
ContractProcessor interface {
ListenerNotificationParsers() []event.NotificationParserInfo
ListenerNotificationHandlers() []event.NotificationHandlerInfo
TimersHandlers() []event.NotificationHandlerInfo
2020-07-24 13:54:03 +00:00
}
)
func connectListenerWithProcessor(l event.Listener, p ContractProcessor) {
// register parsers
for _, parser := range p.ListenerNotificationParsers() {
l.SetNotificationParser(parser)
2020-07-24 13:54:03 +00:00
}
// register handlers
for _, handler := range p.ListenerNotificationHandlers() {
l.RegisterNotificationHandler(handler)
2020-07-24 13:54:03 +00:00
}
}
// bindMorphProcessor connects morph chain listener handlers.
2020-07-24 13:54:03 +00:00
func bindMorphProcessor(proc ContractProcessor, s *Server) error {
connectListenerWithProcessor(s.morphListener, proc)
return nil
2020-07-24 13:54:03 +00:00
}
// bindMainnetProcessor connects mainnet chain listener handlers.
2020-07-24 13:54:03 +00:00
func bindMainnetProcessor(proc ContractProcessor, s *Server) error {
connectListenerWithProcessor(s.mainnetListener, proc)
return nil
2020-07-24 13:54:03 +00:00
}