Skip to content

Commit

Permalink
Update commercial paper doc to use enrollUser.js
Browse files Browse the repository at this point in the history
Signed-off-by: NIKHIL E GUPTA <[email protected]>
  • Loading branch information
NIKHIL E GUPTA authored and mergify[bot] committed May 27, 2020
1 parent cc75716 commit 7fa9da9
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 73 deletions.
Binary file modified docs/source/tutorial/commercial_paper.diagram.testnet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
206 changes: 133 additions & 73 deletions docs/source/tutorial/commercial_paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ After downloading, feel free to examine the directory structure of `fabric-sampl
$ cd fabric-samples
$ ls
CODEOWNERS basic-network first-network
CODE_OF_CONDUCT.md chaincode high-throughput
CONTRIBUTING.md chaincode-docker-devmode interest_rate_swaps
Jenkinsfile ci off_chain_data
LICENSE ci.properties scripts
MAINTAINERS.md commercial-paper test-network
README.md docs
SECURITY.md fabcar
CODEOWNERS SECURITY.md first-network
CODE_OF_CONDUCT.md chaincode high-throughput
CONTRIBUTING.md chaincode-docker-devmode interest_rate_swaps
LICENSE ci off_chain_data
MAINTAINERS.md commercial-paper test-network
README.md fabcar
```

Notice the `commercial-paper` directory -- that's where our sample is located!
Expand All @@ -122,21 +120,21 @@ indicates that you should run the `ls` command from Isabella's window.
## Create the network

This tutorial will deploy a smart contract using the Fabric test network.
The test network consists of two peer organizations and an ordering organization.
The test network consists of two peer organizations and one ordering organization.
The two peer organizations operate one peer each, while the ordering organization
operates a single node raft ordering service. We will also use the test network
to create a single channel named `mychannel` that both peer organizations will
be members of.
operates a single node Raft ordering service. We will also use the test network
to create a single channel named `mychannel` that both peer organizations
will be members of.

![commercialpaper.network](./commercial_paper.diagram.testnet.png)
*The Fabric test network is comprised of two peer organizations, Org1 and Org2,
each with one peer and its ledger state database, and an ordering service node.
Each of these components runs as a Docker container.*
and one ordering organization. Each component runs as a Docker container.*

The two peers, their [state databases](../ledger/ledger.html#world-state-database-options), the
ordering service node and the CA each run in the their own Docker container. In production
environments, organizations typically use existing CAs that are shared with
other systems; they're not dedicated to the Fabric network.
Each organization runs their own Certificate Authority. The two peers, the
[state databases](../ledger/ledger.html#world-state-database-options), the ordering service node,
and each organization CA each run in their own Docker container. In production
environments, organizations typically use existing CAs that are shared with other
systems; they're not dedicated to the Fabric network.

The two organizations of the test network allow us to interact with a blockchain
ledger as two organizations that operate separate peers. In this tutorial,
Expand All @@ -152,67 +150,111 @@ Then use the script to start the test network:
```
./network-starter.sh
```
If the command is successful, you will see the test network being created in your
logs. You can use the `docker ps` command to see the Fabric nodes running on your
local machine:

While the script is running, you will see logs of the test network being deployed.
When the script is complete, you can use the `docker ps` command to see the
Fabric nodes running on your local machine:
```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
321cc489b10f hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:7051->7051/tcp peer0.org1.example.com
ad668671f95f hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com
caadbe4d8592 hyperledger/fabric-couchdb "tini -- /docker-ent…" 2 minutes ago Up 2 minutes 4369/tcp, 9100/tcp, 0.0.0.0:7984->5984/tcp couchdb1
ebabe52903b8 hyperledger/fabric-couchdb "tini -- /docker-ent…" 2 minutes ago Up 2 minutes 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb0
7c72711c6e18 hyperledger/fabric-orderer:latest "orderer" 2 minutes ago Up 2 minutes 0.0.0.0:7050->7050/tcp orderer.example.com
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a86f50ca1907 hyperledger/fabric-peer:latest "peer node start" About a minute ago Up About a minute 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com
77d0fcaee61b hyperledger/fabric-peer:latest "peer node start" About a minute ago Up About a minute 0.0.0.0:7051->7051/tcp peer0.org1.example.com
7eb5f64bfe5f hyperledger/fabric-couchdb "tini -- /docker-ent…" About a minute ago Up About a minute 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb0
2438df719f57 hyperledger/fabric-couchdb "tini -- /docker-ent…" About a minute ago Up About a minute 4369/tcp, 9100/tcp, 0.0.0.0:7984->5984/tcp couchdb1
03373d116c5a hyperledger/fabric-orderer:latest "orderer" About a minute ago Up About a minute 0.0.0.0:7050->7050/tcp orderer.example.com
6b4d87f65909 hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" About a minute ago Up About a minute 7054/tcp, 0.0.0.0:8054->8054/tcp ca_org2
7b01f5454832 hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" About a minute ago Up About a minute 7054/tcp, 0.0.0.0:9054->9054/tcp ca_orderer
87aef6062f23 hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" About a minute ago Up About a minute 0.0.0.0:7054->7054/tcp ca_org1
```

See if you can map these containers to the nodes of the test network (you may
need to horizontally scroll to locate the information):

* The Org1 peer, `peer0.org1.example.com`, is running in container `321cc489b10f`
* The Org2 peer, `peer0.org2.example.com`, is running in container `ad668671f95f`
* The CouchDB database for the Org1 peer, `couchdb0`, is running in container `ebabe52903b8`
* The CouchDB database for the Org2 peer, `couchdb1`, is running in container `caadbe4d8592`
* The ordering node `orderer.example.com` is running in container `7c72711c6e18`
* The Org1 peer, `peer0.org1.example.com`, is running in container `a86f50ca1907`
* The Org2 peer, `peer0.org2.example.com`, is running in container `77d0fcaee61b`
* The CouchDB database for the Org1 peer, `couchdb0`, is running in container `7eb5f64bfe5f`
* The CouchDB database for the Org2 peer, `couchdb1`, is running in container `2438df719f57`
* The Ordering node, `orderer.example.com`, is running in container `03373d116c5a`
* The Org1 CA, `ca_org1`, is running in container `87aef6062f23`
* The Org2 CA, `ca_org2`, is running in container `6b4d87f65909`
* The Ordering Org CA, `ca_orderer`, is running in container `7b01f5454832`

These containers all form a [Docker network](https://docs.docker.com/network/)
called `net_test`. You can view the network with the `docker network` command:

```
$ docker network inspect net_test
{
[
{
"Name": "net_test",
"Id": "b77b99d29e37677fac48b7ecd78383bdebf09ebdd6b00e87e3d9444252b1ce31",
"Created": "2020-01-30T23:04:39.6157465Z",
"Id": "f4c9712139311004b8f7acc14e9f90170c5dcfd8cdd06303c7b074624b44dc9f",
"Created": "2020-04-28T22:45:38.525016Z",
"Containers": {
"321cc489b10ff46554d0b215da307d38daf35b68bbea635ae0ae3176c3ae0945": {
"Name": "peer0.org1.example.com",
"IPv4Address": "192.168.224.5/20",
},
"7c72711c6e18caf7bff4cf78c27efc9ef3b2359a749c926c8aba1beacfdb0211": {
"03373d116c5abf2ca94f6f00df98bb74f89037f511d6490de4a217ed8b6fbcd0": {
"Name": "orderer.example.com",
"IPv4Address": "192.168.224.4/20",
"EndpointID": "0eed871a2aaf9a5dbcf7896aa3c0f53cc61f57b3417d36c56747033fd9f81972",
"MacAddress": "02:42:c0:a8:70:05",
"IPv4Address": "192.168.112.5/20",
"IPv6Address": ""
},
"ad668671f95f351f0119320198e1d1e19ebbb0d75766c6c8b9bb7bd36ba506af": {
"Name": "peer0.org2.example.com",
"IPv4Address": "192.168.224.6/20",
},
"caadbe4d8592aa558fe14d07a424a9e04365620ede1143b6ce5902ce038c0851": {
"2438df719f57a597de592cfc76db30013adfdcfa0cec5b375f6b7259f67baff8": {
"Name": "couchdb1",
"IPv4Address": "192.168.224.2/20",
"EndpointID": "52527fb450a7c80ea509cb571d18e2196a95c630d0f41913de8ed5abbd68993d",
"MacAddress": "02:42:c0:a8:70:06",
"IPv4Address": "192.168.112.6/20",
"IPv6Address": ""
},
"6b4d87f65909afd335d7acfe6d79308d6e4b27441b25a829379516e4c7335b88": {
"Name": "ca_org2",
"EndpointID": "1cc322a995880d76e1dd1f37ddf9c43f86997156124d4ecbb0eba9f833218407",
"MacAddress": "02:42:c0:a8:70:04",
"IPv4Address": "192.168.112.4/20",
"IPv6Address": ""
},
"77d0fcaee61b8fff43d33331073ab9ce36561a90370b9ef3f77c663c8434e642": {
"Name": "peer0.org1.example.com",
"EndpointID": "05d0d34569eee412e28313ba7ee06875a68408257dc47e64c0f4f5ef4a9dc491",
"MacAddress": "02:42:c0:a8:70:08",
"IPv4Address": "192.168.112.8/20",
"IPv6Address": ""
},
"ebabe52903b8597d016dbc0d0ca4373ef75162d3400efbe6416975abafd08a8f": {
"7b01f5454832984fcd9650f05b4affce97319f661710705e6381dfb76cd99fdb": {
"Name": "ca_orderer",
"EndpointID": "057390288a424f49d6e9d6f788049b1e18aa28bccd56d860b2be8ceb8173ef74",
"MacAddress": "02:42:c0:a8:70:02",
"IPv4Address": "192.168.112.2/20",
"IPv6Address": ""
},
"7eb5f64bfe5f20701aae8a6660815c4e3a81c3834b71f9e59a62fb99bed1afc7": {
"Name": "couchdb0",
"IPv4Address": "192.168.224.3/20",
"EndpointID": "bfe740be15ec9dab7baf3806964e6b1f0b67032ce1b7ae26ac7844a1b422ddc4",
"MacAddress": "02:42:c0:a8:70:07",
"IPv4Address": "192.168.112.7/20",
"IPv6Address": ""
},
"87aef6062f2324889074cda80fec8fe014d844e10085827f380a91eea4ccdd74": {
"Name": "ca_org1",
"EndpointID": "a740090d33ca94dd7c6aaf14a79e1cb35109b549ee291c80195beccc901b16b7",
"MacAddress": "02:42:c0:a8:70:03",
"IPv4Address": "192.168.112.3/20",
"IPv6Address": ""
},
"a86f50ca19079f59552e8674932edd02f7f9af93ded14db3b4c404fd6b1abe9c": {
"Name": "peer0.org2.example.com",
"EndpointID": "6e56772b4783b1879a06f86901786fed1c307966b72475ce4631405ba8bca79a",
"MacAddress": "02:42:c0:a8:70:09",
"IPv4Address": "192.168.112.9/20",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
```
See how the five containers use different IP addresses, while being part of a

See how the eight containers use different IP addresses, while being part of a
single Docker network. (We've abbreviated the output for clarity.)

Because we are operating the test network as DigiBank and MagnetoCorp,
Expand All @@ -222,7 +264,7 @@ network is up and running, we can refer to our network as PaperNet from this poi
forward.

To recap: you've downloaded the Hyperledger Fabric samples repository from
GitHub and you've got the test network running on your local machine. Let's now
GitHub and you've got a Fabric network running on your local machine. Let's now
start to play the role of MagnetoCorp, who wishes to issue and trade commercial paper.

## Monitor the network as MagnetoCorp
Expand Down Expand Up @@ -346,7 +388,8 @@ environment. Note the following key program lines:

Feel free to examine other files in the `contract` directory to understand how
the smart contract works, and read in detail how `papercontract.js` is
designed in the smart contract [topic](../developapps/smartcontract.html).
designed in the [smart contract processing](../developapps/smartcontract.html)
topic.

## Deploy the smart contract to the channel

Expand Down Expand Up @@ -379,7 +422,7 @@ cd commercial-paper/organization/magnetocorp
A MagnetoCorp administrator can interact with PaperNet using the `peer` CLI. However,
the administrator needs to set certain environment variables in their command
window to use the correct set of `peer` binaries, send commands to the address
of the MagnetoCorp peer, and sign requests with the correct crypto material.
of the MagnetoCorp peer, and sign requests with the correct cryptographic material.

You can use a script provided by the sample to set the environment variables in
your command window. Run the following command in the `magnetocorp` directory:
Expand All @@ -403,7 +446,7 @@ the `peer lifecycle chaincode install` command:
```
(magnetocorp admin)$ peer lifecycle chaincode install cp.tar.gz
```
If the command is successful, you will see messages similar to the following
When the chaincode package is installed, you will see messages similar to the following
printed in your terminal:
```
2020-01-30 18:32:33.762 EST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nEcp_0:ffda93e26b183e231b7e9d5051e1ee7ca47fbf24f00a8376ec54120b1a2a335c\022\004cp_0" >
Expand Down Expand Up @@ -563,7 +606,7 @@ separate terminal window for her, and in `fabric-samples` locate the MagnetoCorp
(isabella)$ cd commercial-paper/organization/magnetocorp/application/
(isabella)$ ls
addToWallet.js issue.js package.json
enrollUser.js issue.js package.json
```

`addToWallet.js` is the program that Isabella is going to use to load her
Expand Down Expand Up @@ -684,7 +727,7 @@ See how this command has updated the directory:
```
(isabella)$ ls
addToWallet.js node_modules package.json
enrollUser.js node_modules package.json
issue.js package-lock.json
```

Expand All @@ -702,22 +745,39 @@ Isabella is almost ready to run `issue.js` to issue MagnetoCorp commercial paper
`00001`; there's just one remaining task to perform! As `issue.js` acts on
behalf of Isabella, and therefore MagnetoCorp, it will use identity from her
[wallet](../developapps/wallet.html) that reflects these facts. We now need to
perform this one-time activity of adding appropriate X.509 credentials to her
wallet.

In Isabella's terminal window, run the `addToWallet.js` program to add identity
perform this one-time activity of generating the appropriate X.509 credentials
to her wallet.

The MagnetoCorp Certificate Authority running on PaperNet, `ca_org2`, has an
application user that was registered when the network was deployed. Isabella
can use the identity name and secret to generate the X.509 cryptographic material
for the `issue.js` application. The process of using a CA to generate client side
cryptographic material is referred to as **enrollment**. In a real word scenario,
a network operator would provide the name and secret of a client identity that
was registered with the CA to an application developer. The developer would then
use the credentials to enroll their application and interact with the network.

The `enrollUser.js` program uses the `fabric-ca-client` class to generate a private
and public key pair, and then issues a **Certificate Signing Request** to the CA.
If the identiy name and secret submitted by Isabella match the credentials
registered with the CA, the CA will issue and sign a certificate that encodes the
public key, establishing that Isabella belongs to MagnetoCorp. When the signing
request is complete, `enrollUser.js` stores the private key and signing certificate
in Isabella's wallet. You can examine the `enrollUser.js` file to learn more about
how the Node SDK uses the `fabric-ca-client` class to complete these tasks.

In Isabella's terminal window, run the `enrollUser.js` program to add identity
information to her wallet:

```
(isabella)$ node addToWallet.js
(isabella)$ node enrollUser.js
done
Wallet path: /Users/nikhilgupta/fabric-samples/commercial-paper/organization/magnetocorp/identity/user/isabella/wallet
Successfully enrolled client user "isabella" and imported it into the wallet
```

`addToWallet.js` is a simple file-copying program which you can examine at your
leisure. It moves an identity from the test network sample to Isabella's
wallet. Let's focus on the result of this program --- the contents of
the wallet which will be used to submit transactions to PaperNet:
We can now turn our focus to the result of this program --- the contents of the
wallet which will be used to submit transactions to PaperNet:

```
(isabella)$ ls ../identity/user/isabella/wallet/
Expand Down Expand Up @@ -878,13 +938,13 @@ In the DigiBank administrator window, install the application dependencies:
added 738 packages in 46.701s
```
In Balaji's command window, run the `addToWallet.js` program to add the identity
to his wallet:
In Balaji's command window, run the `enrollUser.js` program to generate a
certificate and private key and them to his wallet:
```
(balaji)$ node addToWallet.js
(balaji)$ node enrollUser.js

done
Wallet path: /Users/nikhilgupta/fabric-samples/commercial-paper/organization/digibank/identity/user/balaji/wallet
Successfully enrolled client user "balaji" and imported it into the wallet
```
The `addToWallet.js` program has added identity information for `balaji`, to his
Expand Down
Binary file modified docs/source/tutorial/diagrams.pptx
Binary file not shown.

0 comments on commit 7fa9da9

Please sign in to comment.