Skip to content

Commit

Permalink
[FAB-6859] introduce capability for pvt channel data
Browse files Browse the repository at this point in the history
This change set creates a capability for private channel data (using
collections and SideDB). The capability is experimental for v1.1 and is
enabled in the binary only if it was built with the experimental flag.

Change-Id: I4b7e9a761507a6d617ee8c585f1b62da2e1f95e7
Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
  • Loading branch information
ale-linux committed Dec 20, 2017
1 parent a63e458 commit c6fc37c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 12 deletions.
23 changes: 11 additions & 12 deletions common/capabilities/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ const (

// ApplicationV1_1 is the capabilties string for standard new non-backwards compatible fabric v1.1 application capabilities.
ApplicationV1_1 = "V1_1"

// ApplicationV1_1PvtDataExperimental is the capabilties string for private data using the experimental feature of collections/sideDB.
ApplicationPvtDataExperimental = "V1_1_PVTDATA_EXPERIMENTAL"
)

// ApplicationProvider provides capabilities information for application level config.
type ApplicationProvider struct {
*registry
v11 bool
v11 bool
v11PvtDataExperimental bool
}

// NewApplicationProvider creates a application capabilities provider.
func NewApplicationProvider(capabilities map[string]*cb.Capability) *ApplicationProvider {
ap := &ApplicationProvider{}
ap.registry = newRegistry(ap, capabilities)
_, ap.v11 = capabilities[ApplicationV1_1]
_, ap.v11PvtDataExperimental = capabilities[ApplicationPvtDataExperimental]
return ap
}

Expand All @@ -36,17 +41,6 @@ func (ap *ApplicationProvider) Type() string {
return applicationTypeName
}

// HasCapability returns true if the capability is supported by this binary.
func (ap *ApplicationProvider) HasCapability(capability string) bool {
switch capability {
// Add new capability names here
case ApplicationV1_1:
return true
default:
return false
}
}

// LifecycleViaConfig returns true if chaincode lifecycle should be managed via the resources config
// tree rather than via the deprecated v1.0 endorser tx mechanism.
func (ap *ApplicationProvider) LifecycleViaConfig() bool {
Expand All @@ -58,3 +52,8 @@ func (ap *ApplicationProvider) LifecycleViaConfig() bool {
func (ap *ApplicationProvider) ForbidDuplicateTXIdInBlock() bool {
return ap.v11
}

// PrivateChannelData returns true if support for private channel data (a.k.a. collections) is enabled.
func (ap *ApplicationProvider) PrivateChannelData() bool {
return ap.v11PvtDataExperimental
}
22 changes: 22 additions & 0 deletions common/capabilities/application_experimental.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build experimental

/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package capabilities

// HasCapability returns true if the capability is supported by this binary.
func (ap *ApplicationProvider) HasCapability(capability string) bool {
switch capability {
// Add new capability names here
case ApplicationV1_1:
return true
case ApplicationPvtDataExperimental:
return true
default:
return false
}
}
22 changes: 22 additions & 0 deletions common/capabilities/application_stable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build !experimental

/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package capabilities

// HasCapability returns true if the capability is supported by this binary.
func (ap *ApplicationProvider) HasCapability(capability string) bool {
switch capability {
// Add new capability names here
case ApplicationV1_1:
return true
case ApplicationPvtDataExperimental:
return false
default:
return false
}
}
7 changes: 7 additions & 0 deletions common/capabilities/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ func TestApplicationV11(t *testing.T) {
assert.NoError(t, op.Supported())
assert.True(t, op.LifecycleViaConfig())
}

func TestApplicationPvtDataExperimental(t *testing.T) {
op := NewApplicationProvider(map[string]*cb.Capability{
ApplicationPvtDataExperimental: {},
})
assert.True(t, op.PrivateChannelData())
}
3 changes: 3 additions & 0 deletions common/channelconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ type ApplicationCapabilities interface {
// LifecycleViaConfig returns true if chaincode lifecycle should be managed via the resources config
// tree rather than via the deprecated v1.0 endorser tx mechanism.
LifecycleViaConfig() bool

// PrivateChannelData returns true if support for private channel data (a.k.a. collections) is enabled.
PrivateChannelData() bool
}

// OrdererCapabilities defines the capabilities for the orderer portion of a channel
Expand Down
5 changes: 5 additions & 0 deletions common/mocks/config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type MockApplicationCapabilities struct {
SupportedRv error
ForbidDuplicateTXIdInBlockRv bool
LifecycleViaConfigRv bool
PrivateChannelDataRv bool
}

func (mac *MockApplicationCapabilities) Supported() error {
Expand All @@ -37,3 +38,7 @@ func (mac *MockApplicationCapabilities) ForbidDuplicateTXIdInBlock() bool {
func (mac *MockApplicationCapabilities) LifecycleViaConfig() bool {
return mac.LifecycleViaConfigRv
}

func (mac *MockApplicationCapabilities) PrivateChannelData() bool {
return mac.PrivateChannelDataRv
}

0 comments on commit c6fc37c

Please sign in to comment.