Skip to content

Commit

Permalink
[FAB-8150] ChannelService with System Channel
Browse files Browse the repository at this point in the history
ChannelProvider should allow creation of
ChannelService on a system channel.

Change-Id: Iff7cfd69ba5503157ee7df79420c7662cd119cd2
Signed-off-by: Bob Stasyszyn <bob.stasyszyn@securekey.com>
  • Loading branch information
bstasyszyn committed Feb 8, 2018
1 parent a0c4e3e commit 110c5e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
32 changes: 19 additions & 13 deletions pkg/fabsdk/provider/chpvdr/chprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/api/apicore"
"github.com/hyperledger/fabric-sdk-go/api/apifabclient"
"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/chconfig"
)

// ChannelProvider keeps context across ChannelService instances.
Expand All @@ -34,21 +35,26 @@ func New(fabricProvider apicore.FabricProvider) (*ChannelProvider, error) {
func (cp *ChannelProvider) NewChannelService(ic apifabclient.IdentityContext, channelID string) (apifabclient.ChannelService, error) {

var cfg apifabclient.ChannelCfg
v, ok := cp.chCfgMap.Load(channelID)
if !ok {
p, err := cp.fabricProvider.NewChannelConfig(ic, channelID)
if err != nil {
return nil, err
if channelID != "" {
v, ok := cp.chCfgMap.Load(channelID)
if !ok {
p, err := cp.fabricProvider.NewChannelConfig(ic, channelID)
if err != nil {
return nil, err
}

cfg, err = p.Query()
if err != nil {
return nil, err
}

cp.chCfgMap.Store(channelID, cfg)
} else {
cfg = v.(apifabclient.ChannelCfg)
}

cfg, err = p.Query()
if err != nil {
return nil, err
}

cp.chCfgMap.Store(channelID, cfg)
} else {
cfg = v.(apifabclient.ChannelCfg)
// System channel
cfg = chconfig.NewChannelCfg("")
}

cs := ChannelService{
Expand Down
11 changes: 11 additions & 0 deletions pkg/fabsdk/provider/chpvdr/chprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ func TestBasicValidChannel(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error creating Channel Service: %v", err)
}

// System channel
channelService, err = cp.NewChannelService(user, "")
if err != nil {
t.Fatalf("Unexpected error creating Channel Service: %v", err)
}

_, err = channelService.Channel()
if err != nil {
t.Fatalf("Unexpected error creating Channel Service: %v", err)
}
}

// MockProviderFactory is configured to retrieve channel config from orderer
Expand Down

0 comments on commit 110c5e6

Please sign in to comment.