forked from TrueCloudLab/frostfs-node
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>
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package innerring
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
|
)
|
|
|
|
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
|
|
}
|
|
)
|
|
|
|
func connectListenerWithProcessor(l event.Listener, p ContractProcessor) {
|
|
// 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
|
|
}
|