Skip to content

Commit

Permalink
[FAB-1938] Update documentation how to use peer cli
Browse files Browse the repository at this point in the history
Peer cli command switched to use command line parameter
to get the ordering service endpoint. This commit updates
documentation files to reflect the change.

Change-Id: Ib7d47d3bf6cb4cceb238a8514b0b1b960609448c
Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Mar 2, 2017
1 parent c956be0 commit 715ddcf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 21 deletions.
46 changes: 36 additions & 10 deletions docs/asset_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,64 @@ If successful, you should see the following in your terminal:
```
Send createChannel API to Ordering Service:
```
CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer channel create -c myc2
peer channel create -c myc2 -o orderer:7050
```
This will return a genesis block - `myc2.block` - that you can issue join commands with.
Next, send a joinChannel API to `peer0` and pass in the genesis block as an argument.
The channel is defined within the genesis block:
```
CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 CORE_PEER_ADDRESS=peer0:7051 peer channel join -b myc2.block
CORE_PEER_ADDRESS=peer0:7051 peer channel join -b myc2.block
```
To join the other peers to the channel, simply reissue the above command with `peer1`
or `peer2` specified. For example:
```
CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 CORE_PEER_ADDRESS=peer1:7051 peer channel join -b myc2.block
CORE_PEER_ADDRESS=peer1:7051 peer channel join -b myc2.block
```
Once the peers have all joined the channel, you are able to issues queries against
any peer without having to deploy chaincode to each of them.

## Use cli to deploy, invoke and query
## Use cli to install, instantiate, invoke and query

Run the deploy command. This command is deploying a chaincode named `mycc` to
`peer0` on the Channel ID `myc2`. The constructor message is initializing `a` and
`b` with values of 100 and 200 respectively.
Run the install command. This command is installing a chaincode named `mycc` to
`peer0` on the Channel ID `myc2` and the chaincode version is v0.
```
CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode deploy -C myc2 -n mycc -p github.com/hyperledger/fabric/examples -c '{"Args":["init","a","100","b","200"]}'
CORE_PEER_ADDRESS=peer0:7051 peer chaincode deploy \
-o orderer:7050 \
-C myc2 \
-n mycc \
-p github.com/hyperledger/fabric/examples \
-v v0
```

Next we need to instantiate the chaincode by running the instatiate command on peer cli tool.
The constructor message is initializing `a` and `b` with values of 100 and 200 respectively.

```bash
CORE_PEER_ADDRESS=peer0:7051 peer chaincode instantiate \
-o orderer:7050 \
-C myc2 \
-n mycc \
-p github.com/hyperledger/fabric/examples \
-v v0 \
-c '{"Args":["init","a","100","b","200"]}'
```

Run the invoke command. This invocation is moving 10 units from `a` to `b`.
```
CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode invoke -C myc2 -n mycc -c '{"function":"invoke","Args":["move","a","b","10"]}'
CORE_PEER_ADDRESS=peer0:7051 peer chaincode invoke \
-C myc2 \
-n mycc \
-c '{"Args":["invoke","a", "b", 10]}' \
-v v0
```
Run the query command. The invocation transferred 10 units from `a` to `b`, therefore
a query against `a` should return the value 90.
```
CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode query -C myc2 -n mycc -c '{"function":"invoke","Args":["query","a"]}'
CORE_PEER_ADDRESS=peer0:7051 peer chaincode query \
-C myc2 \
-n mycc \
-c '{"function":"invoke","Args":["query","a"]}' \
-v v0
```
You can issue an `exit` command at any time to exit the cli container.

Expand Down
4 changes: 2 additions & 2 deletions docs/configtxgen.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This configuration file may be edited, or, individual properties may be overridd
## Bootstrapping the orderer
After creating a configuration profile as desired, simply invoke
```
configtxgen -profile &lt;profile_name&gt; -outputBlock &lt;genesis.blockname&gt;
configtxgen -profile <profile_name> -outputBlock <genesis.blockname>;
```
This will produce a `genesis.block` file in the current directory. If you wish to skip writing the file simply do not pass `outputBlock`

Expand All @@ -34,7 +34,7 @@ Then, to utilize this genesis block, before starting the orderer, simply specify
The tool can also output a channel creation tx by executing

```
configtxgen -profile &lt;profile_name&gt; -outputCreateChannelTx &lt;output.txname&gt;
configtxgen -profile <profile_name> -outputCreateChannelTx <output.txname>
```

This will output a marshaled `Envelope` message which may be sent to broadcast to create a channel.
48 changes: 39 additions & 9 deletions docs/install_instantiate.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ through vagrant, make sure you have followed the steps outlined in
fabric directory within your vagrant environment, execute the `make peer-docker`
and `make orderer-docker` commands.

### Start the network of 2 peers, an orderer, and a CLI
### Start the network of 2 peers, an orderer, and a CLI container
Navigate to the fabric/docs directory in your vagrant environment and start your network:
```bash
docker-compose -f docker-2peer.yml up
Expand All @@ -33,7 +33,7 @@ root@ccd3308afc73:/opt/gopath/src/github.com/hyperledger/fabric/peer#
### Create and join channel from the remote CLI
From your second terminal, lets create a channel by the name of "myc":
```bash
peer channel create -c myc
peer channel create -c myc -o orderer:5005
```
This will generate a genesis block - `myc.block` - and place it into the same directory
from which you issued your `peer channel create` command. Now, from the same directory,
Expand All @@ -48,43 +48,69 @@ CORE_PEER_ADDRESS=peer1:7051 peer channel join -b myc.block
From your second terminal, and still within the CLI container, issue the following
command to install a chaincode named `mycc` with a version of `v0` onto `peer0`.
```bash
CORE_PEER_ADDRESS=peer0:7051 peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0
CORE_PEER_ADDRESS=peer0:7051 peer chaincode install \
-o orderer:5005 \
-n mycc \
-p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 \
-v v0
```

### Instantiate the chaincode on the channel from the remote CLI
Now, still within the cli container in your second terminal, instantiate the chaincode
`mycc` with version `v0` onto `peer0`. This instantiation will initialize the chaincode
with key value pairs of ["a","100"] and ["b","200"].
```bash
CORE_PEER_ADDRESS=peer0:7051 peer chaincode instantiate -C myc -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0 -c '{"Args":["init","a","100","b","200"]}'
CORE_PEER_ADDRESS=peer0:7051 peer chaincode instantiate \
-o orderer:5005 \
-C myc \
-n mycc \
-p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 \
-c '{"Args":["init","a","100","b","200"]}' \
-v v0
```
__Continue operating within your second terminal for the remainder of the commands__

### Query for the value of "a" to make sure the chaincode container has successfully started
Send a query to `peer0` for the value of key `"a"`:
```bash
CORE_PEER_ADDRESS=peer0:7051 peer chaincode query -C myc -n mycc -v v0 -c '{"Args":["query","a"]}'
CORE_PEER_ADDRESS=peer0:7051 peer chaincode query \
-C myc \
-n mycc \
-c '{"Args":["query","a"]}' \
-v v0
```
This query should return "100".

### Invoke to make a state change
Send an invoke request to `peer0` to move 10 units from "a" to "b":
```bash
CORE_PEER_ADDRESS=peer0:7051 peer chaincode invoke -C myc -n mycc -v v0 -c '{"Args":["invoke","a","b","10"]}'
CORE_PEER_ADDRESS=peer0:7051 peer chaincode invoke \
-C myc \
-n mycc \
-c '{"Args":["invoke","a","b","10"]}' \
-v v0
```

### Query on the second peer
Issue a query against the key "a" to `peer1`. Recall that `peer1` has successfully
joined the channel.
```bash
CORE_PEER_ADDRESS=peer1:7051 peer chaincode query -C myc -n mycc -v v0 -c '{"Args":["query","a"]}'
CORE_PEER_ADDRESS=peer1:7051 peer chaincode query \
-C myc \
-n mycc \
-c '{"Args":["query","a"]}' \
-v v0
```
This will return an error response because `peer1` does not have the chaincode installed.

### Install on the second peer
Now add the chaincode to `peer1` so that you can successfully perform read/write operations.
```bash
CORE_PEER_ADDRESS=peer1:7051 peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0
CORE_PEER_ADDRESS=peer1:7051 peer chaincode install \
-o orderer:5005 \
-n mycc \
-p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 \
-v v0
```
__Note__: The initial instantiation applies to all peers in the channel, and is
affected upon any peer that has the chaincode installed. Therefore, we installed
Expand All @@ -97,7 +123,11 @@ chaincode must be installed on any peer receiving endorsement requests for that
### Query on the second peer
Now issue the same query request to `peer1`.
```bash
CORE_PEER_ADDRESS=peer1:7051 peer chaincode query -C myc -n mycc -v v0 -c '{"Args":["query","a"]}'
CORE_PEER_ADDRESS=peer1:7051 peer chaincode query \
-C myc \
-n mycc \
-c '{"Args":["query","a"]}' \
-v v0
```
Query will now succeed.

Expand Down

0 comments on commit 715ddcf

Please sign in to comment.