[#770] pkg/innerring: Add `NotaryContractProcessor` interface

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
support/v0.27
Pavel Karpy 2021-08-15 21:17:10 +03:00 committed by Pavel Karpy
parent d40f898ee5
commit 4e5618aecb
2 changed files with 25 additions and 0 deletions

View File

@ -12,6 +12,17 @@ type (
ListenerNotificationHandlers() []event.NotificationHandlerInfo
TimersHandlers() []event.NotificationHandlerInfo
}
// 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
}
)
func connectListenerWithProcessor(l event.Listener, p ContractProcessor) {
@ -24,6 +35,17 @@ func connectListenerWithProcessor(l event.Listener, p ContractProcessor) {
for _, handler := range p.ListenerNotificationHandlers() {
l.RegisterNotificationHandler(handler)
}
// 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)
}
}
}
// bindMorphProcessor connects morph chain listener handlers.

View File

@ -392,6 +392,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
if err != nil {
return nil, fmt.Errorf("could not enable side chain notary support: %w", err)
}
server.morphListener.EnableNotarySupport(server.contracts.proxy, server.morphClient.Committee, server.morphClient)
}
if !server.mainNotaryConfig.disabled {
@ -643,6 +645,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
ContainerClient: cnrClient,
NeoFSIDClient: neofsIDClient,
NetworkState: server.netmapClient,
NotaryDisabled: server.sideNotaryConfig.disabled,
})
if err != nil {
return nil, err