frostfs-node/pkg/innerring/bindings.go
Pavel Karpy ba77bb44e4 [#807] ir: Merge ContractProcessor and NotaryContractProcessor interfaces
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2021-09-09 18:37:45 +03:00

51 lines
1.5 KiB
Go

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
ListenerNotaryParsers() []event.NotaryParserInfo
ListenerNotaryHandlers() []event.NotaryHandlerInfo
TimersHandlers() []event.NotificationHandlerInfo
}
)
func connectListenerWithProcessor(l event.Listener, p ContractProcessor) {
// register notification parsers
for _, parser := range p.ListenerNotificationParsers() {
l.SetNotificationParser(parser)
}
// register notification handlers
for _, handler := range p.ListenerNotificationHandlers() {
l.RegisterNotificationHandler(handler)
}
// register notary parsers
for _, notaryParser := range p.ListenerNotaryParsers() {
l.SetNotaryParser(notaryParser)
}
// register notary handlers
for _, notaryHandler := range p.ListenerNotaryHandlers() {
l.RegisterNotaryHandler(notaryHandler)
}
}
// bindMorphProcessor connects morph chain listener handlers.
func bindMorphProcessor(proc ContractProcessor, s *Server) error {
connectListenerWithProcessor(s.morphListener, proc)
return nil
}
// bindMainnetProcessor connects mainnet chain listener handlers.
func bindMainnetProcessor(proc ContractProcessor, s *Server) error {
connectListenerWithProcessor(s.mainnetListener, proc)
return nil
}