From 4e5618aecba8d70198ffc44292021fe631fc9def Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Sun, 15 Aug 2021 21:17:10 +0300 Subject: [PATCH] [#770] pkg/innerring: Add `NotaryContractProcessor` interface Signed-off-by: Pavel Karpy --- pkg/innerring/bindings.go | 22 ++++++++++++++++++++++ pkg/innerring/innerring.go | 3 +++ 2 files changed, 25 insertions(+) diff --git a/pkg/innerring/bindings.go b/pkg/innerring/bindings.go index 57ddb3ef..1c930cdf 100644 --- a/pkg/innerring/bindings.go +++ b/pkg/innerring/bindings.go @@ -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. diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index d4a49730..369f47c9 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -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