frostfs-node/pkg/innerring/bindings.go

45 lines
1.3 KiB
Go
Raw Normal View History

2020-07-24 13:54:03 +00:00
package innerring
import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
2020-07-24 13:54:03 +00:00
)
type (
// ContractProcessor interface defines functions for binding event producers
// such as event.Listener and Timers with contract processor.
ContractProcessor interface {
ListenerNotificationHandlers() []event.NotificationHandlerInfo
ListenerNotaryParsers() []event.NotaryParserInfo
ListenerNotaryHandlers() []event.NotaryHandlerInfo
}
2020-07-24 13:54:03 +00:00
)
func connectListenerWithProcessor(l event.Listener, p ContractProcessor) {
// register notification handlers
for _, handler := range p.ListenerNotificationHandlers() {
l.RegisterNotificationHandler(handler)
2020-07-24 13:54:03 +00:00
}
// register notary parsers
for _, notaryParser := range p.ListenerNotaryParsers() {
l.SetNotaryParser(notaryParser)
}
// register notary handlers
for _, notaryHandler := range p.ListenerNotaryHandlers() {
l.RegisterNotaryHandler(notaryHandler)
}
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
}