frostfs-node/pkg/innerring/bindings.go
Evgenii Stratonikov d0ce835fbf [#1546] morph/event: Merge notification parser and handlers
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>
2024-12-11 07:39:49 +00:00

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
}