From ff764e455e0c4e0629b125cf9a0ba8095ff59169 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 23 Jul 2024 17:27:59 +0100 Subject: [PATCH] fix: fabric check existence of listener Signed-off-by: Enrique Lacal --- internal/blockchain/fabric/eventstream.go | 17 +++++++++++++++++ internal/blockchain/fabric/fabric.go | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/blockchain/fabric/eventstream.go b/internal/blockchain/fabric/eventstream.go index 3b38142b45..a07425411e 100644 --- a/internal/blockchain/fabric/eventstream.go +++ b/internal/blockchain/fabric/eventstream.go @@ -167,6 +167,23 @@ func (s *streamManager) getSubscription(ctx context.Context, subID string) (sub return sub, nil } +func (s *streamManager) checkSubscriptionExistence(ctx context.Context, subID string) (found bool, err error) { + sub := &subscription{} + res, err := s.client.R(). + SetContext(ctx). + SetResult(&sub). + Get(fmt.Sprintf("/subscriptions/%s", subID)) + + if err != nil || !res.IsSuccess() { + if res.StatusCode() == 404 { + return false, nil + } + return false, ffresty.WrapRestErr(ctx, res, err, coremsgs.MsgFabconnectRESTErr) + } + + return true, nil +} + func (s *streamManager) getSubscriptionName(ctx context.Context, subID string) (string, error) { if cachedValue := s.cache.GetString("sub:" + subID); cachedValue != "" { return cachedValue, nil diff --git a/internal/blockchain/fabric/fabric.go b/internal/blockchain/fabric/fabric.go index 7729aaac17..37182f91cb 100644 --- a/internal/blockchain/fabric/fabric.go +++ b/internal/blockchain/fabric/fabric.go @@ -998,7 +998,13 @@ func (f *Fabric) DeleteContractListener(ctx context.Context, subscription *core. func (f *Fabric) GetContractListenerStatus(ctx context.Context, namespace, subID string, okNotFound bool) (bool, interface{}, core.ContractListenerStatus, error) { // Fabconnect does not currently provide any additional status info for listener subscriptions. - return true, nil, core.ContractListenerStatusUnknown, nil + // But we check for existence of the subscription + found, err := f.streams.checkSubscriptionExistence(ctx, subID) + if err != nil { + return found, nil, core.ContractListenerStatusUnknown, err + } + + return found, nil, core.ContractListenerStatusUnknown, nil } func (f *Fabric) GetFFIParamValidator(ctx context.Context) (fftypes.FFIParamValidator, error) {