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 {
|
2021-08-12 15:24:17 +00:00
|
|
|
ListenerNotificationParsers() []event.NotificationParserInfo
|
|
|
|
ListenerNotificationHandlers() []event.NotificationHandlerInfo
|
|
|
|
TimersHandlers() []event.NotificationHandlerInfo
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
2021-08-15 18:17:10 +00:00
|
|
|
|
|
|
|
// NotaryContractProcessor interface defines function for binding notary event
|
|
|
|
// producers such as event.Listener with contract processor.
|
|
|
|
//
|
|
|
|
// This interface is optional for contract processor. If contract processor
|
|
|
|
// supports notary event handling, it should implement both ContractProcessor
|
|
|
|
// and NotaryContractProcessor interfaces.
|
|
|
|
NotaryContractProcessor interface {
|
|
|
|
ListenerNotaryParsers() []event.NotaryParserInfo
|
|
|
|
ListenerNotaryHandlers() []event.NotaryHandlerInfo
|
|
|
|
}
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func connectListenerWithProcessor(l event.Listener, p ContractProcessor) {
|
|
|
|
// register parsers
|
2021-08-12 15:24:17 +00:00
|
|
|
for _, parser := range p.ListenerNotificationParsers() {
|
|
|
|
l.SetNotificationParser(parser)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// register handlers
|
2021-08-12 15:24:17 +00:00
|
|
|
for _, handler := range p.ListenerNotificationHandlers() {
|
|
|
|
l.RegisterNotificationHandler(handler)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
2021-08-15 18:17:10 +00:00
|
|
|
|
|
|
|
// add notary handlers if processor supports it
|
|
|
|
if notaryProcessor, ok := p.(NotaryContractProcessor); ok {
|
|
|
|
for _, notaryParser := range notaryProcessor.ListenerNotaryParsers() {
|
|
|
|
l.SetNotaryParser(notaryParser)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, notaryHandler := range notaryProcessor.ListenerNotaryHandlers() {
|
|
|
|
l.RegisterNotaryHandler(notaryHandler)
|
|
|
|
}
|
|
|
|
}
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 17:44:51 +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)
|
2021-01-22 15:49:52 +00:00
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 17:44:51 +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)
|
2021-01-22 15:49:52 +00:00
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|