Skip to content

Commit f19d8cc

Browse files
committed
CLI install/query should not require orderer endpoint
This change ensures installing and querying chaincode from the CLI does not require passing an orderer endpoint parameter. https://jira.hyperledger.org/browse/FAB-2708 Change-Id: Iae212abdf208e940a07fd3441f3111db1ee5a9a6 Signed-off-by: Will Lahti <[email protected]>
1 parent 3295920 commit f19d8cc

File tree

8 files changed

+17
-15
lines changed

8 files changed

+17
-15
lines changed

examples/e2e_cli/end-to-end.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ Install the sample go code onto one of the four peer nodes
442442

443443
.. code:: bash
444444
445-
peer chaincode install -o orderer:7050 -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
445+
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
446446
447447
Instantiate chaincode and define the endorsement policy
448448
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -476,7 +476,7 @@ Query chaincode
476476

477477
.. code:: bash
478478
479-
peer chaincode query -o orderer:7050 -C mychannel -n mycc -c '{"Args":["query","a"]}'
479+
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
480480
481481
The result of the above command should be as below:
482482

examples/e2e_cli/scripts/script.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ joinChannel () {
8282
installChaincode () {
8383
PEER=$1
8484
setGlobals $PEER
85-
peer chaincode install -o $ORDERER_IP:7050 -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txt
85+
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txt
8686
res=$?
8787
cat log.txt
8888
verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed"
@@ -114,7 +114,7 @@ chaincodeQuery () {
114114
do
115115
sleep 3
116116
echo "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs"
117-
peer chaincode query -o $ORDERER_IP:7050 -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
117+
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
118118
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
119119
test "$VALUE" = "$2" && let rc=0
120120
done

peer/chaincode/common.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ type ChaincodeCmdFactory struct {
214214
}
215215

216216
// InitCmdFactory init the ChaincodeCmdFactory with default clients
217-
func InitCmdFactory() (*ChaincodeCmdFactory, error) {
217+
func InitCmdFactory(isOrdererRequired bool) (*ChaincodeCmdFactory, error) {
218218
endorserClient, err := common.GetEndorserClient()
219219
if err != nil {
220220
return nil, fmt.Errorf("Error getting endorser client %s: %s", chainFuncName, err)
@@ -225,11 +225,14 @@ func InitCmdFactory() (*ChaincodeCmdFactory, error) {
225225
return nil, fmt.Errorf("Error getting default signer: %s", err)
226226
}
227227

228-
broadcastClient, err := common.GetBroadcastClient(orderingEndpoint)
229-
if err != nil {
230-
return nil, fmt.Errorf("Error getting broadcast client: %s", err)
231-
}
228+
var broadcastClient common.BroadcastClient
229+
if isOrdererRequired {
230+
broadcastClient, err = common.GetBroadcastClient(orderingEndpoint)
232231

232+
if err != nil {
233+
return nil, fmt.Errorf("Error getting broadcast client: %s", err)
234+
}
235+
}
233236
return &ChaincodeCmdFactory{
234237
EndorserClient: endorserClient,
235238
Signer: signer,

peer/chaincode/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func chaincodeInstall(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory
8888

8989
var err error
9090
if cf == nil {
91-
cf, err = InitCmdFactory()
91+
cf, err = InitCmdFactory(false)
9292
if err != nil {
9393
return err
9494
}

peer/chaincode/instantiate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func instantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envel
9999
func chaincodeDeploy(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
100100
var err error
101101
if cf == nil {
102-
cf, err = InitCmdFactory()
102+
cf, err = InitCmdFactory(true)
103103
if err != nil {
104104
return err
105105
}

peer/chaincode/invoke.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func invokeCmd(cf *ChaincodeCmdFactory) *cobra.Command {
4242
func chaincodeInvoke(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
4343
var err error
4444
if cf == nil {
45-
cf, err = InitCmdFactory()
45+
cf, err = InitCmdFactory(true)
4646
if err != nil {
4747
return err
4848
}

peer/chaincode/query.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ func queryCmd(cf *ChaincodeCmdFactory) *cobra.Command {
4747
func chaincodeQuery(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
4848
var err error
4949
if cf == nil {
50-
cf, err = InitCmdFactory()
50+
cf, err = InitCmdFactory(false)
5151
if err != nil {
5252
return err
5353
}
5454
}
55-
defer cf.BroadcastClient.Close()
5655

5756
return chaincodeInvokeOrQuery(cmd, args, false, cf)
5857
}

peer/chaincode/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func upgrade(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envelope,
9898
func chaincodeUpgrade(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
9999
var err error
100100
if cf == nil {
101-
cf, err = InitCmdFactory()
101+
cf, err = InitCmdFactory(true)
102102
if err != nil {
103103
return err
104104
}

0 commit comments

Comments
 (0)