Skip to content

Commit 64d1b8e

Browse files
author
Jason Yellick
committed
[FAB-6071] Add application capabilities structures
Certain capabilities may be required of the peer which are completely irrelevant to the other pieces of the system (such as the orderer). For instance, whether a peer may process side-DB transactions had no impact on the orderer, because the orderer is left out of these transactions by design. This CR adds basic support for application/peer capabilities though none are currently implemented. Change-Id: I27fe1266b370b6d71791c5782bbe641c081e8f62 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 79a0119 commit 64d1b8e

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

common/capabilities/application.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package capabilities
8+
9+
import (
10+
cb "github.com/hyperledger/fabric/protos/common"
11+
)
12+
13+
const (
14+
applicationTypeName = "Application"
15+
)
16+
17+
// ApplicationProvider provides capabilities information for application level config.
18+
type ApplicationProvider struct {
19+
*registry
20+
}
21+
22+
// NewApplicationProvider creates a application capabilities provider.
23+
func NewApplicationProvider(capabilities map[string]*cb.Capability) *ApplicationProvider {
24+
cp := &ApplicationProvider{}
25+
cp.registry = newRegistry(cp, capabilities)
26+
return cp
27+
}
28+
29+
// Type returns a descriptive string for logging purposes.
30+
func (cp *ApplicationProvider) Type() string {
31+
return applicationTypeName
32+
}
33+
34+
// HasCapability returns true if the capability is supported by this binary.
35+
func (cp *ApplicationProvider) HasCapability(capability string) bool {
36+
switch capability {
37+
// Add new capability names here
38+
default:
39+
return false
40+
}
41+
}

common/capabilities/capabilities_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestSatisfied(t *testing.T) {
2525
for _, provider := range []*registry{
2626
NewChannelProvider(capsMap).registry,
2727
NewOrdererProvider(capsMap).registry,
28+
NewApplicationProvider(capsMap).registry,
2829
} {
2930
assert.Nil(t, provider.Supported())
3031
}
@@ -42,6 +43,7 @@ func TestSatisfied(t *testing.T) {
4243
for _, provider := range []*registry{
4344
NewChannelProvider(capsMap).registry,
4445
NewOrdererProvider(capsMap).registry,
46+
NewApplicationProvider(capsMap).registry,
4547
} {
4648
assert.Nil(t, provider.Supported())
4749
}
@@ -57,6 +59,7 @@ func TestNotSatisfied(t *testing.T) {
5759
for _, provider := range []*registry{
5860
NewChannelProvider(capsMap).registry,
5961
NewOrdererProvider(capsMap).registry,
62+
NewApplicationProvider(capsMap).registry,
6063
} {
6164
assert.Error(t, provider.Supported())
6265
}

0 commit comments

Comments
 (0)