Skip to content

Commit

Permalink
[FAB-7826] Fix QueryInstantiatedChaincodes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
troyronda committed Jan 23, 2018
1 parent 0a3ac6f commit 40b253e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 12 additions & 3 deletions pkg/fabric-client/channel/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,20 @@ func (c *Channel) QueryTransaction(transactionID string) (*pb.ProcessedTransacti
// This query will be made to the primary peer.
func (c *Channel) QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error) {

payload, err := c.queryBySystemChaincodeByTarget("lscc", "getchaincodes", nil, c.PrimaryPeer())
targets := []txn.ProposalProcessor{c.PrimaryPeer()}
request := txn.ChaincodeInvokeRequest{
Targets: targets,
ChaincodeID: "lscc",
Fcn: "getchaincodes",
}

payload, err := c.QueryByChaincode(request)
if err != nil {
return nil, errors.WithMessage(err, "lscc.getchaincodes failed")
}

response := new(pb.ChaincodeQueryResponse)
err = proto.Unmarshal(payload, response)
err = proto.Unmarshal(payload[0], response)
if err != nil {
return nil, errors.Wrap(err, "unmarshal of ChaincodeQueryResponse failed")
}
Expand Down Expand Up @@ -211,7 +218,9 @@ func (c *Channel) queryBySystemChaincodeByTarget(chaincodeID string, fcn string,
return responses[0], nil
}

// QueryBySystemChaincode invokes a system chaincode
// QueryBySystemChaincode invokes a chaincode that isn't part of a channel.
//
// TODO: This function's name is confusing - call the normal QueryByChaincode for system chaincode on a channel.
func (c *Channel) QueryBySystemChaincode(request txn.ChaincodeInvokeRequest) ([][]byte, error) {
request, err := c.chaincodeInvokeRequestAddDefaultPeers(request)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions test/integration/fab/channel_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func TestChannelQueries(t *testing.T) {

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

// TODO: Synch with test in node SDK when it becomes available
// testInstantiatedChaincodes(t, channel)
testInstantiatedChaincodes(t, channel)

}

Expand Down

0 comments on commit 40b253e

Please sign in to comment.