Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 40b253e

Browse files
committed
[FAB-7826] Fix QueryInstantiatedChaincodes
This patch fixes QueryInstantiatedChaincodes to call lscc on the channel rather than channel-less. Change-Id: Ia0a9ed66170ce6bf8c7136460f60062c20a51cae Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent 0a3ac6f commit 40b253e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pkg/fabric-client/channel/query.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,20 @@ func (c *Channel) QueryTransaction(transactionID string) (*pb.ProcessedTransacti
133133
// This query will be made to the primary peer.
134134
func (c *Channel) QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error) {
135135

136-
payload, err := c.queryBySystemChaincodeByTarget("lscc", "getchaincodes", nil, c.PrimaryPeer())
136+
targets := []txn.ProposalProcessor{c.PrimaryPeer()}
137+
request := txn.ChaincodeInvokeRequest{
138+
Targets: targets,
139+
ChaincodeID: "lscc",
140+
Fcn: "getchaincodes",
141+
}
142+
143+
payload, err := c.QueryByChaincode(request)
137144
if err != nil {
138145
return nil, errors.WithMessage(err, "lscc.getchaincodes failed")
139146
}
140147

141148
response := new(pb.ChaincodeQueryResponse)
142-
err = proto.Unmarshal(payload, response)
149+
err = proto.Unmarshal(payload[0], response)
143150
if err != nil {
144151
return nil, errors.Wrap(err, "unmarshal of ChaincodeQueryResponse failed")
145152
}
@@ -211,7 +218,9 @@ func (c *Channel) queryBySystemChaincodeByTarget(chaincodeID string, fcn string,
211218
return responses[0], nil
212219
}
213220

214-
// QueryBySystemChaincode invokes a system chaincode
221+
// QueryBySystemChaincode invokes a chaincode that isn't part of a channel.
222+
//
223+
// TODO: This function's name is confusing - call the normal QueryByChaincode for system chaincode on a channel.
215224
func (c *Channel) QueryBySystemChaincode(request txn.ChaincodeInvokeRequest) ([][]byte, error) {
216225
request, err := c.chaincodeInvokeRequestAddDefaultPeers(request)
217226
if err != nil {

test/integration/fab/channel_queries_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ func TestChannelQueries(t *testing.T) {
7676

7777
testQueryByChaincode(t, channel, client.Config(), testSetup)
7878

79-
// TODO: Synch with test in node SDK when it becomes available
80-
// testInstantiatedChaincodes(t, channel)
79+
testInstantiatedChaincodes(t, channel)
8180

8281
}
8382

0 commit comments

Comments
 (0)