Skip to content

Commit

Permalink
Allowing discovery client users to use response.Endorsers (hyperledge…
Browse files Browse the repository at this point in the history
…r#166)

* Added WithIndifferentFilter constructor for discovery client to allow users to use response.Endorsers() method.

Signed-off-by: Vladyslav Kopaihorodskyi <[email protected]>

* renamed WithIndifferentFilter to NewIndifferentFilter

Signed-off-by: Vladyslav Kopaihorodskyi <[email protected]>

* goimports on test file

Signed-off-by: Vladyslav Kopaihorodskyi <[email protected]>
  • Loading branch information
kopaygorodsky authored Feb 25, 2021
1 parent a662a94 commit 7bf5879
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/fab/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ type Response interface {
Error() error
}

// NewIndifferentFilter returns NoPriorities/NoExclusion filter.
// Note: this method was added just to allow users of Client to be able to use Endorsers method in response, which requires Filter as an argument.
// It's impossible to implement interface because Filter is placed under internal dir which is not available to end user.
// A user should filter peers by himself.
func NewIndifferentFilter() discclient.Filter {
return discclient.NewFilter(discclient.NoPriorities, discclient.NoExclusion)
}

// Send retrieves information about channel peers, endorsers, and MSP config from the
// given set of peers. A channel of successful responses is returned and an error if there is not targets.
// Each Response contains Error method to check if there is an error.
Expand Down
8 changes: 8 additions & 0 deletions pkg/fab/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/hyperledger/fabric-protos-go/discovery"
discclient "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/discovery/client"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/comm"
discmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/discovery/mocks"
Expand Down Expand Up @@ -141,3 +142,10 @@ func newMockContext() *mocks.MockContext {
context.SetCustomInfraProvider(comm.NewMockInfraProvider())
return context
}

func TestNewIndifferentFilter(t *testing.T) {
endorsers := discclient.Endorsers{&discclient.Peer{MSPID: "org1MSP"}, &discclient.Peer{MSPID: "org2MSP"}}
filter := NewIndifferentFilter()
filteredEndorsers := filter.Filter(endorsers)
assert.Len(t, filteredEndorsers, len(endorsers))
}

0 comments on commit 7bf5879

Please sign in to comment.