Skip to content

Commit

Permalink
[FAB-10848] Invalid seek type in Event Client
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bstasyszyn authored and troyronda committed Jun 26, 2018
1 parent cb4ad13 commit d1ad22a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/client/event/event.go
Expand Up @@ -15,6 +15,7 @@ SPDX-License-Identifier: Apache-2.0
package event

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

var es fab.EventService
if eventClient.permitBlockEvents {
es, err = channelContext.ChannelService().EventService(client.WithBlockEvents(), deliverclient.WithSeekType(eventClient.seekType), deliverclient.WithBlockNum(eventClient.fromBlock))
var opts []options.Opt
opts = append(opts, client.WithBlockEvents())
if eventClient.seekType != "" {
opts = append(opts, deliverclient.WithSeekType(eventClient.seekType))
if eventClient.seekType == seek.FromBlock {
opts = append(opts, deliverclient.WithBlockNum(eventClient.fromBlock))
}
}
es, err = channelContext.ChannelService().EventService(opts...)
} else {
es, err = channelContext.ChannelService().EventService()
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/fab/events/deliverclient/opts.go
Expand Up @@ -74,7 +74,11 @@ func (p *params) SetFromBlock(value uint64) {

func (p *params) SetSeekType(value seek.Type) {
logger.Debugf("SeekType: %s", value)
p.seekType = value
if value != "" {
p.seekType = value
} else {
logger.Warnf("SeekType must not be empty. Defaulting to %s", p.seekType)
}
}

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

0 comments on commit d1ad22a

Please sign in to comment.