forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockchconfig.go
95 lines (78 loc) · 2.58 KB
/
mockchconfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
reqContext "context"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
msp "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
)
// MockChannelCfg contains mock channel configuration
type MockChannelCfg struct {
MockID string
MockBlockNumber uint64
MockMSPs []*msp.MSPConfig
MockAnchorPeers []*fab.OrgAnchorPeer
MockOrderers []string
MockVersions *fab.Versions
MockMembership fab.ChannelMembership
MockCapabilities map[fab.ConfigGroupKey]map[string]bool
}
// NewMockChannelCfg ...
func NewMockChannelCfg(id string) *MockChannelCfg {
capabilities := make(map[fab.ConfigGroupKey]map[string]bool)
capabilities[fab.ChannelGroupKey] = make(map[string]bool)
capabilities[fab.ApplicationGroupKey] = make(map[string]bool)
capabilities[fab.OrdererGroupKey] = make(map[string]bool)
return &MockChannelCfg{
MockID: id,
MockCapabilities: capabilities,
}
}
// ID returns name
func (cfg *MockChannelCfg) ID() string {
return cfg.MockID
}
// BlockNumber returns block number
func (cfg *MockChannelCfg) BlockNumber() uint64 {
return cfg.MockBlockNumber
}
// MSPs returns msps
func (cfg *MockChannelCfg) MSPs() []*msp.MSPConfig {
return cfg.MockMSPs
}
// AnchorPeers returns anchor peers
func (cfg *MockChannelCfg) AnchorPeers() []*fab.OrgAnchorPeer {
return cfg.MockAnchorPeers
}
// Orderers returns orderers
func (cfg *MockChannelCfg) Orderers() []string {
return cfg.MockOrderers
}
// Versions returns versions
func (cfg *MockChannelCfg) Versions() *fab.Versions {
return cfg.MockVersions
}
// HasCapability indicates whether or not the given group has the given capability
func (cfg *MockChannelCfg) HasCapability(group fab.ConfigGroupKey, capability string) bool {
capabilities, ok := cfg.MockCapabilities[group]
if !ok {
return false
}
return capabilities[capability]
}
// MockChannelConfig mockcore query channel configuration
type MockChannelConfig struct {
channelID string
ctx context.Client
}
// NewMockChannelConfig mockcore channel config implementation
func NewMockChannelConfig(ctx context.Client, channelID string) (*MockChannelConfig, error) {
return &MockChannelConfig{channelID: channelID, ctx: ctx}, nil
}
// Query mockcore query for channel configuration
func (c *MockChannelConfig) Query(reqCtx reqContext.Context) (fab.ChannelCfg, error) {
return NewMockChannelCfg(c.channelID), nil
}