Skip to content

Commit a7ea9ba

Browse files
author
Ivan Vankov (gatakka)
committed
complete refactor the code and add support for Fabric version 1.1.x
1 parent 4bbf845 commit a7ea9ba

File tree

116 files changed

+8172
-3130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+8172
-3130
lines changed

README.md

Lines changed: 163 additions & 350 deletions
Large diffs are not rendered by default.

caclient.go

Lines changed: 993 additions & 149 deletions
Large diffs are not rendered by default.

chaincode.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333

3434
// ChainCode the fields necessary to execute operation over chaincode.
3535
type ChainCode struct {
36-
Channel *Channel
36+
ChannelId string
3737
Name string
3838
Version string
3939
Type ChainCodeType
@@ -59,7 +59,7 @@ func (c *ChainCode) toChainCodeArgs() ([][]byte) {
5959

6060
// InstallRequest holds fields needed to install chaincode
6161
type InstallRequest struct {
62-
Channel *Channel
62+
ChannelId string
6363
ChainCodeName string
6464
ChainCodeVersion string
6565
ChainCodeType ChainCodeType
@@ -68,6 +68,13 @@ type InstallRequest struct {
6868
Libraries []ChaincodeLibrary
6969
}
7070

71+
type CollectionConfig struct {
72+
Name string
73+
RequiredPeersCount int32
74+
MaximumPeersCount int32
75+
Organizations []string
76+
}
77+
7178
type ChaincodeLibrary struct {
7279
Namespace string
7380
SrcPath string
@@ -82,7 +89,7 @@ type ChainCodesResponse struct {
8289

8390
// createInstallProposal read chaincode from provided source and namespace, pack it and generate install proposal
8491
// transaction. Transaction is not send from this func
85-
func createInstallProposal(identity *Identity, req *InstallRequest) (*transactionProposal, error) {
92+
func createInstallProposal(identity Identity, req *InstallRequest) (*transactionProposal, error) {
8693

8794
var packageBytes []byte
8895
var err error
@@ -109,13 +116,13 @@ func createInstallProposal(identity *Identity, req *InstallRequest) (*transactio
109116
return nil, err
110117
}
111118

112-
spec, err := chainCodeInvocationSpec(&ChainCode{Type: req.ChainCodeType,
119+
spec, err := chainCodeInvocationSpec(ChainCode{Type: req.ChainCodeType,
113120
Name: LSCC,
114121
Args: []string{"install"},
115122
ArgBytes: depSpec,
116123
})
117124

118-
creator, err := marshalProtoIdentity(identity, req.Channel)
125+
creator, err := marshalProtoIdentity(identity)
119126
if err != nil {
120127
return nil, err
121128
}
@@ -125,7 +132,7 @@ func createInstallProposal(identity *Identity, req *InstallRequest) (*transactio
125132
}
126133
ccHdrExt := &peer.ChaincodeHeaderExtension{ChaincodeId: &peer.ChaincodeID{Name: LSCC}}
127134

128-
channelHeaderBytes, err := channelHeader(common.HeaderType_ENDORSER_TRANSACTION, txId, req.Channel, 0, ccHdrExt)
135+
channelHeaderBytes, err := channelHeader(common.HeaderType_ENDORSER_TRANSACTION, txId, req.ChannelId, 0, ccHdrExt)
129136
if err != nil {
130137
return nil, err
131138
}
@@ -158,7 +165,7 @@ func createInstallProposal(identity *Identity, req *InstallRequest) (*transactio
158165

159166
// createInstantiateProposal creates instantiate proposal transaction for already installed chaincode.
160167
// transaction is not send from this func
161-
func createInstantiateProposal(identity *Identity, req *ChainCode, operation string) (*transactionProposal, error) {
168+
func createInstantiateProposal(identity Identity, req *ChainCode, operation string, collectionConfig []byte) (*transactionProposal, error) {
162169
if operation != "deploy" && operation != "upgrade" {
163170
return nil, fmt.Errorf("install proposall accept only 'deploy' and 'upgrade' operations")
164171
}
@@ -174,7 +181,7 @@ func createInstantiateProposal(identity *Identity, req *ChainCode, operation str
174181
return nil, err
175182
}
176183

177-
policy, err := defaultPolicy(req.Channel.MspId)
184+
policy, err := defaultPolicy(identity.MspId)
178185
if err != nil {
179186
return nil, err
180187
}
@@ -183,18 +190,25 @@ func createInstantiateProposal(identity *Identity, req *ChainCode, operation str
183190
return nil, err
184191
}
185192

186-
spec, err := chainCodeInvocationSpec(&ChainCode{
187-
Type: req.Type,
188-
Name: LSCC,
189-
rawArgs: [][]byte{
190-
[]byte(operation),
191-
[]byte(req.Channel.ChannelName),
192-
depSpec, marshPolicy,
193-
[]byte("escc"), []byte("vscc"),
194-
},
193+
args := [][]byte{
194+
[]byte(operation),
195+
[]byte(req.ChannelId),
196+
depSpec,
197+
marshPolicy,
198+
[]byte("escc"),
199+
[]byte("vscc"),
200+
}
201+
if len(collectionConfig) > 0 {
202+
args = append(args, collectionConfig)
203+
}
204+
205+
spec, err := chainCodeInvocationSpec(ChainCode{
206+
Type: req.Type,
207+
Name: LSCC,
208+
rawArgs: args,
195209
})
196210

197-
creator, err := marshalProtoIdentity(identity, req.Channel)
211+
creator, err := marshalProtoIdentity(identity)
198212
if err != nil {
199213
return nil, err
200214
}
@@ -204,7 +218,7 @@ func createInstantiateProposal(identity *Identity, req *ChainCode, operation str
204218
}
205219
headerExtension := &peer.ChaincodeHeaderExtension{ChaincodeId: &peer.ChaincodeID{Name: LSCC}}
206220

207-
channelHeaderBytes, err := channelHeader(common.HeaderType_ENDORSER_TRANSACTION, txId, req.Channel, 0, headerExtension)
221+
channelHeaderBytes, err := channelHeader(common.HeaderType_ENDORSER_TRANSACTION, txId, req.ChannelId, 0, headerExtension)
208222
if err != nil {
209223
return nil, err
210224
}

channel.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ const LSCC = "lscc"
1515
const QSCC = "qscc"
1616
const CSCC = "cscc"
1717

18-
// Channel define channel
19-
type Channel struct {
20-
// ChannelName is channel name over which operations will be executed.
21-
ChannelName string
22-
// MspId identify which member service in peer must be used to verify operation.
23-
MspId string
24-
}
25-
2618
// QueryChannelsResponse holds the result from querying which channels peer is currently joined
2719
type QueryChannelsResponse struct {
2820
PeerName string
@@ -50,7 +42,7 @@ func decodeChannelFromFs(path string) (*common.Envelope, error) {
5042
}
5143

5244
// buildAndSignChannelConfig take channel config payload and prepare the structure need for join transaction
53-
func buildAndSignChannelConfig(identity *Identity, configPayload []byte, crypto CryptoSuite, channel *Channel) (*common.Envelope, error) {
45+
func buildAndSignChannelConfig(identity Identity, configPayload []byte, crypto CryptoSuite,channelId string) (*common.Envelope, error) {
5446

5547
pl := &common.Payload{}
5648
if err := proto.Unmarshal(configPayload, pl); err != nil {
@@ -62,7 +54,7 @@ func buildAndSignChannelConfig(identity *Identity, configPayload []byte, crypto
6254
if err != nil {
6355
return nil, err
6456
}
65-
creator, err := marshalProtoIdentity(identity, channel)
57+
creator, err := marshalProtoIdentity(identity)
6658
if err != nil {
6759
return nil, err
6860
}
@@ -86,7 +78,7 @@ func buildAndSignChannelConfig(identity *Identity, configPayload []byte, crypto
8678
configSignature.Signature = sig
8779
configUpdateEnvelope.Signatures = append(configUpdateEnvelope.GetSignatures(), configSignature)
8880

89-
channelHeaderBytes, err := channelHeader(common.HeaderType_CONFIG_UPDATE, txId, channel,0,nil)
81+
channelHeaderBytes, err := channelHeader(common.HeaderType_CONFIG_UPDATE, txId, channelId,0,nil)
9082
header := header(sigHeaderBytes, channelHeaderBytes)
9183

9284
envelopeBytes, err := proto.Marshal(configUpdateEnvelope)

0 commit comments

Comments
 (0)