Skip to content

Commit

Permalink
CLI install/query should not require orderer endpoint
Browse files Browse the repository at this point in the history
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 <wtlahti@us.ibm.com>
  • Loading branch information
wlahti committed Mar 10, 2017
1 parent 3295920 commit f19d8cc
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/e2e_cli/end-to-end.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Install the sample go code onto one of the four peer nodes

.. code:: bash
peer chaincode install -o orderer:7050 -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
Instantiate chaincode and define the endorsement policy
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -476,7 +476,7 @@ Query chaincode

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

Expand Down
4 changes: 2 additions & 2 deletions examples/e2e_cli/scripts/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ joinChannel () {
installChaincode () {
PEER=$1
setGlobals $PEER
peer chaincode install -o $ORDERER_IP:7050 -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txt
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txt
res=$?
cat log.txt
verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed"
Expand Down Expand Up @@ -114,7 +114,7 @@ chaincodeQuery () {
do
sleep 3
echo "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs"
peer chaincode query -o $ORDERER_IP:7050 -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
test "$VALUE" = "$2" && let rc=0
done
Expand Down
13 changes: 8 additions & 5 deletions peer/chaincode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ type ChaincodeCmdFactory struct {
}

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

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

if err != nil {
return nil, fmt.Errorf("Error getting broadcast client: %s", err)
}
}
return &ChaincodeCmdFactory{
EndorserClient: endorserClient,
Signer: signer,
Expand Down
2 changes: 1 addition & 1 deletion peer/chaincode/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func chaincodeInstall(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory

var err error
if cf == nil {
cf, err = InitCmdFactory()
cf, err = InitCmdFactory(false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion peer/chaincode/instantiate.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func instantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envel
func chaincodeDeploy(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
var err error
if cf == nil {
cf, err = InitCmdFactory()
cf, err = InitCmdFactory(true)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion peer/chaincode/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func invokeCmd(cf *ChaincodeCmdFactory) *cobra.Command {
func chaincodeInvoke(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
var err error
if cf == nil {
cf, err = InitCmdFactory()
cf, err = InitCmdFactory(true)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions peer/chaincode/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ func queryCmd(cf *ChaincodeCmdFactory) *cobra.Command {
func chaincodeQuery(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
var err error
if cf == nil {
cf, err = InitCmdFactory()
cf, err = InitCmdFactory(false)
if err != nil {
return err
}
}
defer cf.BroadcastClient.Close()

return chaincodeInvokeOrQuery(cmd, args, false, cf)
}
2 changes: 1 addition & 1 deletion peer/chaincode/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func upgrade(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envelope,
func chaincodeUpgrade(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
var err error
if cf == nil {
cf, err = InitCmdFactory()
cf, err = InitCmdFactory(true)
if err != nil {
return err
}
Expand Down

0 comments on commit f19d8cc

Please sign in to comment.