Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit d1ad22a

Browse files
bstasyszyntroyronda
authored andcommitted
[FAB-10848] Invalid seek type in Event Client
When the Event Client is created using the WithBlockEvents option, only pass the WithSeekType option to the event service if seekType has been specified. Also, add a check for blank seek type in the event service to prevent against this case. Change-Id: I48cff39582f34d3c0d40f327555fcba79ab7a4a1 Signed-off-by: Bob Stasyszyn <Bob.Stasyszyn@securekey.com>
1 parent cb4ad13 commit d1ad22a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pkg/client/event/event.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SPDX-License-Identifier: Apache-2.0
1515
package event
1616

1717
import (
18+
"github.com/hyperledger/fabric-sdk-go/pkg/common/options"
1819
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
1920
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
2021
"github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client"
@@ -55,7 +56,15 @@ func New(channelProvider context.ChannelProvider, opts ...ClientOption) (*Client
5556

5657
var es fab.EventService
5758
if eventClient.permitBlockEvents {
58-
es, err = channelContext.ChannelService().EventService(client.WithBlockEvents(), deliverclient.WithSeekType(eventClient.seekType), deliverclient.WithBlockNum(eventClient.fromBlock))
59+
var opts []options.Opt
60+
opts = append(opts, client.WithBlockEvents())
61+
if eventClient.seekType != "" {
62+
opts = append(opts, deliverclient.WithSeekType(eventClient.seekType))
63+
if eventClient.seekType == seek.FromBlock {
64+
opts = append(opts, deliverclient.WithBlockNum(eventClient.fromBlock))
65+
}
66+
}
67+
es, err = channelContext.ChannelService().EventService(opts...)
5968
} else {
6069
es, err = channelContext.ChannelService().EventService()
6170
}

pkg/fab/events/deliverclient/opts.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ func (p *params) SetFromBlock(value uint64) {
7474

7575
func (p *params) SetSeekType(value seek.Type) {
7676
logger.Debugf("SeekType: %s", value)
77-
p.seekType = value
77+
if value != "" {
78+
p.seekType = value
79+
} else {
80+
logger.Warnf("SeekType must not be empty. Defaulting to %s", p.seekType)
81+
}
7882
}
7983

8084
func (p *params) SetResponseTimeout(value time.Duration) {

0 commit comments

Comments
 (0)