Skip to content

Commit 463b148

Browse files
committedSep 22, 2016
Updates to the node SDK docs and sample files
cherry-picking commit 70237c3. Fix broken links and formatting issues on doc files Include docker image and compose files to support docs Update sample apps with environment settings fix src and tag in dockerfile fix docker image name in doc Change-Id: I7e2781411199039ee851ec5da63d3f9377767cac Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
1 parent d4d04e9 commit 463b148

12 files changed

+458
-499
lines changed
 
+42-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
11
# Setting up the Full Hyperledger fabric Developer's Environment
22

3-
1. See [Setting Up The Development Environment](../dev-setup/devenv.md) to set up your development environment.
3+
* See [Setting Up The Development Environment](../dev-setup/devenv.md) to set up your development environment.
4+
5+
* The following commands are all issued from the vagrant environment. The following will open a terminal session:
46

5-
2. Issue the following commands to build the Hyperledger fabric client (HFC) Node.js SDK including the API reference documentation
7+
```
8+
cd <your cloned location>/fabric/devenv
9+
vagrant up
10+
vagrant ssh
11+
```
612

7-
```
13+
* Issue the following commands to build the Hyperledger fabric client (HFC) Node.js SDK including the API reference documentation
14+
15+
```
816
cd /opt/gopath/src/github.com/hyperledger/fabric/sdk/node
917
make all
10-
```
11-
12-
3. Issue the following command where your Node.js application is located if you wish to use the `require("hfc")`, this will install the HFC locally.
13-
14-
```
15-
npm install /opt/gopath/src/github.com/hyperledger/fabric/sdk/node
16-
```
17-
18-
Or use point directly to the HFC directly by using the following require in your code:
19-
```javascript
18+
```
19+
* Issue the following command where your Node.js application is located if you wish to use the `require("hfc")`, this will install the HFC locally.
20+
21+
```
22+
npm install /opt/gopath/src/github.com/hyperledger/fabric/sdk/node
23+
```
24+
25+
Or point to the HFC directly by using the following `require()` in your code:
26+
27+
```javascript
2028
require("/opt/gopath/src/github.com/hyperledger/fabric/sdk/node");
21-
```
22-
23-
24-
4. To see the API reference documentation which is built in step 2:
25-
```
26-
cd /opt/gopath/src/github.com/hyperledger/fabric/sdk/node/doc
27-
```
28-
29-
The [Self Contained Node.js Environment](node-sdk-self-contained.md) will have the reference documentation already built and may be accessed by:
30-
```
29+
```
30+
31+
* To build the API reference documentation:
32+
33+
```
34+
cd /opt/gopath/src/github.com/hyperledger/fabric/sdk/node
35+
make doc
36+
```
37+
38+
* To build the reference documentation in the [Self Contained Node.js Environment](node-sdk-self-contained.md):
39+
40+
```
3141
docker exec -it nodesdk /bin/bash
32-
cd /opt/gopath/src/github.com/hyperledger/fabric/sdk/node/doc
33-
```
42+
cd /opt/gopath/src/github.com/hyperledger/fabric/sdk/node
43+
make doc
44+
```
45+
46+
* The the API reference documentation will be available in:
47+
```
48+
/opt/gopath/src/github.com/hyperledger/fabric/sdk/node/doc
49+
```
50+

‎docs/nodeSDK/app-overview.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
Hyperledger fabric supports two types of applications:
44

5-
* A standalone application that interacts directly with a blockchain.
5+
* A standalone application that interacts directly with a blockchain.
66
See the [Standalone Application](#standaloneApp) section.
77

8-
* A web application that interacts with a blockchain on behalf of its web application users.
8+
* A web application that interacts with a blockchain on behalf of its web application users.
99
See the [Web Application](#webApp) section.
1010

1111
<a name="standaloneApp"></a>
1212
## Standalone Application
1313

1414
The following diagram provides an overview of the major components of Hyperledger fabric for the standalone application developer.
1515

16-
![Reference architecture](../images/standalone-app-developer.png)
16+
<img src="../images/standalone-app-developer.png" width="900" height="456">
1717

1818
In the diagram above, the blue boxes are Hyperledger fabric components and the green boxes are application developer components. Each outer box represents a separate process.
1919

@@ -24,31 +24,33 @@ The **Standalone Application** may be developed in Node.js by using the Hyperled
2424

2525
The **SDK** interacts with a **Peer** process. If the Peer process fails, the Node.js Client SDK can fail-over to another Peer as shown by the dotted line from the Node.js Client SDK to another Peer.
2626

27-
This interaction with the Peer consists of submitting transactions to the blockchain. There are three types of transactions:
28-
* deploy - to deploy developer's chaincode as depicted by the green **CC1** boxes in the diagram;
29-
* invoke - to execute a chaincode function which changes the state of the *blockchain database*;
27+
This interaction with the Peer consists of submitting transactions to the blockchain. There are three types of transactions:
28+
29+
* deploy - to deploy developer's chaincode as depicted by the green **CC1** boxes in the diagram;
30+
* invoke - to execute a chaincode function which changes the state of the *blockchain database*;
3031
* query - to execute a chaincode function which may return state information related to the *blockchain database*.
3132

32-
The **SDK** also interacts with a **Membership Services** process. In fact, if security is enabled in the Peer (strongly recommended), the Node.js client SDK must interact with Membership Services first in order to retrieve *credentials* which are then used to interact with the Peer. These *credentials* consist of certificates as described in [Membership Services](membership-services.md).
33+
The **SDK** also interacts with a **Membership Services** process. In fact, if security is enabled in the Peer (strongly recommended), the Node.js client SDK must interact with Membership Services first in order to retrieve credential certificates which are then used to interact with the Peer.
3334

3435
The interaction with the Membership Services consists of:
35-
* register - to indicate a new user to the blockchain
36+
37+
* register - to invite a new user to the blockchain
3638
* enroll - to get access to the blockchain
3739

3840
<a name="webApp"></a>
3941
## Web Application
4042

4143
The following diagram provides an overview of the major components of Hyperledger fabric for the web application developer.
4244

43-
At a high-level, you can think of the Block Chain as a database with which the web application interacts; therefore, it is similar to the following topology.
45+
At a high-level, you can think of the blockchain as a database with which the web application interacts; therefore, it is similar to the following topology.
46+
4447
```
4548
browser --> web tier --> database tier
46-
```
4749
50+
```
4851

49-
![Reference architecture](../images/web-app-developer.png)
52+
<img src="../images/web-app-developer.png" width="900" height="456">
5053

5154
In the diagram above, the blue boxes are Hyperledger fabric components and the green boxes are application developer components. Each outer box represents a separate process.
5255

53-
The browser interacts with the developer's Node.js web application using the Hyperledger fabric's Node.js client SDK. The SDK handles all interactions with other Hyperledger fabric components in the same manor as described in the [SDK interactions](#sdk-interactions) section of [Standalone Application](#standaloneApp).
54-
56+
The browser interacts with the developer's Node.js web application using the Hyperledger fabric's Node.js client SDK. The SDK handles all interactions with other Hyperledger fabric components as described in the [SDK interactions](#sdk-interactions) section of [Standalone Application](#standaloneApp).

‎docs/nodeSDK/node-sdk-guide.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ The Hyperledger fabric Client (HFC) SDK for Node.js provides a powerful and easy
2121

2222
* [Node.js Standalone Application in Vagrant](sample-standalone-app.md) for a sample standalone Node.js application running in the full development environment within Vagrant.
2323

24-
* [Node.js Web Application](sample-web-app.md) for a sample web application and to see how to use the Node.js client SDK for a sample web app leveraging the client SDK to interact with blockchain network.
24+
* [Node.js Web Application](sample-web-app.md) for a sample web application and to see how to use the Node.js client SDK for a sample web app leveraging the client SDK to interact with a blockchain network.
2525

2626

2727

2828
#### Related information
2929

30-
* To build and view the reference documentation for the Node.js client SDK APIs follow the instructions [here](app-developer-env-setup.md).
30+
* To build the reference documentation for the Node.js client SDK APIs follow the instructions [here](app-developer-env-setup.md).
3131

3232
* To learn more about chaincode, see [Writing, Building, and Running Chaincode in a Development Environment](../Setup/Chaincode-setup.md).

‎docs/nodeSDK/node-sdk-indepth.md

+50-39
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22

33
The Hyperledger fabric Client (HFC) SDK provides a powerful and easy to use API to interact with a Hyperledger fabric blockchain.
44

5+
Below, you'll find the following sections:
6+
7+
- [Installing only the SDK](#installing-only-the-sdk)
8+
- [Terminology](#terminology)
9+
- [HFC Objects](#hfc-objects)
10+
- [Pluggability](#pluggability)
11+
- [Chaincode Deployment](#chaincode-deployment)
12+
- [Enabling TLS](#enabling-tls)
13+
- [Troubleshooting](#troubleshooting)
14+
515
## Installing only the SDK
616

7-
If you are an experienced node.js developer and already have a blockchain environment set up and running elsewhere, you can set up a client-only environment to run the node.js client by installing the HFC node module as shown below. This assumes npm version 2.11.3 and node.js version 0.12.7 are already installed.
8-
17+
If you are an experienced node.js developer and already have a blockchain environment set up and running elsewhere, you can set up a client-only environment to run the node.js client by installing the HFC node module as shown below. This assumes a minimum of npm version 2.11.3 and node.js version 0.12.7 are already installed.
18+
919
* To install the latest HFC module of Hyperledger fabric
20+
1021
```
11-
npm install hfc
22+
npm install hfc
1223
```
1324

1425
### Terminology
1526

16-
In order to transact on a hyperledger blockchain, you must first have an identity which has been both **registered** and **enrolled** with Membership Services. For a topological overview of how the components interact, see [Application Developer's Overview](app-developer-overview.md).
27+
In order to transact on a Hyperledger fabric blockchain, you must first have an identity which has been both **registered** and **enrolled** with Membership Services. For a topological overview of how the components interact, see [Application Developer's Overview](app-overview.md).
1728

1829
Think of **registration** as *issuing a user invitation* to join a blockchain. It consists of adding a new user name (also called an *enrollment ID*) to the membership service configuration. This can be done programatically with the `Member.register` method, or by adding the enrollment ID directly to the [membersrvc.yaml](https://github.com/hyperledger/fabric/blob/master/membersrvc/membersrvc.yaml) configuration file.
1930

@@ -45,58 +56,59 @@ The following is a high-level description of the HFC objects (classes and interf
4556

4657
This class implements the bulk of the deploy, invoke, and query logic. It interacts with Membership Services to get a TCert to perform these operations. Note that there is a one-to-one relationship between TCert and TransactionContext. In other words, a single TransactionContext will always use the same TCert. If you want to issue multiple transactions with the same TCert, then you can get a `TransactionContext` object from a `Member` object directly and issue multiple deploy, invoke, or query operations on it. Note however that if you do this, these transactions are linkable, which means someone could tell that they came from the same user, though not know which user. For this reason, you will typically just call deploy, invoke, and query on the Member or User object.
4758

48-
#### Pluggability
59+
## Pluggability
4960

5061
HFC was designed to support two pluggable components:
5162

52-
1. Pluggable `KeyValStore` key value store which is used to retrieve and store keys associated with a member. The key value store is used to store sensitive private keys, so care must be taken to properly protect access.
63+
1. Pluggable `KeyValStore` key value store which is used to retrieve and store keys associated with a member. The key value store is used to store sensitive private keys, so care must be taken to properly protect access.
64+
5365
**IMPORTANT NOTE**: The default KeyValStore is file-based. If multiple instances of a web application run in a cluster, you must provide an implementation of the KeyValStore which is used by all members of the cluster.
5466

5567
2. Pluggable `MemberServices` which is used to register and enroll members. Member services enables hyperledger to be a permissioned blockchain, providing security services such as anonymity, unlinkability of transactions, and confidentiality
5668

57-
### Chaincode Deployment
69+
## Chaincode Deployment
5870

59-
#### 'net' mode
71+
### 'net' mode
6072

6173
To have the chaincode deployment succeed in network mode, you must properly set
6274
up the chaincode project outside of your Hyperledger fabric source tree to include all the **golang** dependencies such that when tarred up and sent to the peer, the peer will be able to build the chain code and then deploy it. The
6375
following instructions will demonstrate how to properly set up the directory
6476
structure to deploy *chaincode_example02* in network mode.
6577

66-
The chaincode project must be placed under the `$GOPATH/src` directory. For
67-
example, the
68-
[chaincode_example02](https://github.com/hyperledger/fabric/blob/master/examples/chaincode/go/chaincode_example02/chaincode_example02.go)
78+
The chaincode project must be placed under the `$GOPATH/src` directory. For example, the [chaincode_example02](https://github.com/hyperledger/fabric/blob/master/examples/chaincode/go/chaincode_example02/chaincode_example02.go)
6979
project should be placed under `$GOPATH/src/` as shown below.
7080

7181
```
72-
mkdir -p $GOPATH/src/github.com/chaincode_example02/
73-
cd $GOPATH/src/github.com/chaincode_example02
74-
curl GET https://raw.githubusercontent.com/hyperledger/fabric/master/examples/chaincode/go/chaincode_example02/chaincode_example02.go > chaincode_example02.go
82+
mkdir -p $GOPATH/src/github.com/chaincode_example02/
83+
cd $GOPATH/src/github.com/chaincode_example02
84+
curl GET https://raw.githubusercontent.com/hyperledger/fabric/master/examples/chaincode/go/chaincode_example02/chaincode_example02.go > chaincode_example02.go
7585
```
7686

7787
After you have placed your chaincode project under the `$GOPATH/src`, you will need to vendor the dependencies. From the directory containing your chaincode source, run the following commands:
7888

7989
```
80-
go get -u github.com/kardianos/govendor
81-
cd $GOPATH/src/github.com/chaincode_example02
82-
govendor init
83-
govendor fetch github.com/hyperledger/fabric
90+
go get -u github.com/kardianos/govendor
91+
cd $GOPATH/src/github.com/chaincode_example02
92+
govendor init
93+
govendor fetch github.com/hyperledger/fabric
8494
```
8595

8696
Now, execute `go build` to verify that all of the chaincode dependencies are
8797
present.
8898

8999
```
90-
go build
100+
go build
91101
```
92102

93-
#### 'dev' mode
103+
### 'dev' mode
94104
For deploying chaincode in development mode see [Writing, Building, and Running Chaincode in a Development Environment](../Setup/Chaincode-setup.md).
95105
The chaincode must be running and connected to the peer before issuing the `deploy()` from the Node.js application. The hfc `chain` object must be set to dev mode.
106+
96107
```javascript
97108
chain.setDevMode(true);
98109
```
99110
The deploy request must include the `chaincodeName` that the chaincode registered with the peer. The built-in chaincode example checks an environment variable `CORE_CHAINCODE_ID_NAME=mycc` when it starts.
111+
100112
```json
101113
var deployRequest = {
102114
chaincodeName: 'mycc',
@@ -112,11 +124,11 @@ If you wish to configure TLS with the Membership Services server, the following
112124
- Modify `$GOPATH/src/github.com/hyperledger/fabric/membersrvc/membersrvc.yaml` as follows:
113125

114126
```
115-
server:
116-
tls:
117-
cert:
127+
server:
128+
tls:
129+
cert:
118130
file: "/var/hyperledger/production/.membersrvc/tlsca.cert"
119-
key:
131+
key:
120132
file: "/var/hyperledger/production/.membersrvc/tlsca.priv"
121133
```
122134

@@ -125,12 +137,12 @@ To specify to the Membership Services (TLS) Certificate Authority (TLSCA) what X
125137
- Modify `$GOPATH/src/github.com/hyperledger/fabric/peer/core.yaml` as follows:
126138

127139
```
128-
peer:
129-
pki:
130-
tls:
131-
enabled: true
132-
rootcert:
133-
file: "/var/hyperledger/production/.membersrvc/tlsca.cert"
140+
peer:
141+
pki:
142+
tls:
143+
enabled: true
144+
rootcert:
145+
file: "/var/hyperledger/production/.membersrvc/tlsca.cert"
134146
```
135147

136148
To configure the peer to connect to the Membership Services server over TLS (otherwise, the connection will fail).
@@ -140,19 +152,18 @@ To configure the peer to connect to the Membership Services server over TLS (oth
140152
- Copy `/var/hyperledger/production/.membersrvc/tlsca.cert` to `$GOPATH/src/github.com/hyperledger/fabric/sdk/node`.
141153

142154
*Note:* If you cleanup the folder `/var/hyperledger/production` then don't forget to copy again the *tlsca.cert* file as described above.
143-
144-
145-
146155

147-
148-
### Troublingshooting
156+
### Troubleshooting
149157
If you see errors stating that the client has already been registered/enrolled, keep in mind that you can perform the enrollment process only once, as the enrollmentSecret is a one-time-use password. You will see these errors if you have performed a user registration/enrollment and subsequently deleted the cryptographic tokens stored on the client side. The next time you try to enroll, errors similar to the ones below will be seen.
150158

151-
```
159+
```
152160
Error: identity or token do not match
153-
```
154-
```
161+
162+
```
163+
164+
```
155165
Error: user is already registered
156-
```
166+
167+
```
157168

158169
To address this, remove any stored cryptographic material from the CA server by following the instructions [here](https://github.com/hyperledger/fabric/blob/master/docs/Setup/Chaincode-setup.md#removing-temporary-files-when-security-is-enabled). You will also need to remove any of the cryptographic tokens stored on the client side by deleting the KeyValStore directory. That directory is configurable and is set to `/tmp/keyValStore` within the unit tests.

‎docs/nodeSDK/node-sdk-self-contained.md

+66-112
Original file line numberDiff line numberDiff line change
@@ -4,142 +4,96 @@ This section describes how to set up a self contained environment for Node.js ap
44

55
**note:** This sample was prepared using Docker for Mac 1.12.0
66

7-
1. Prerequisite software to install:
7+
* Prerequisite software to install:
8+
89
* Docker
910
* docker-compose (may be packaged with Docker)
1011

11-
2. Create a docker-compose file called *docker-compose.yml*
12-
13-
You may retrieve the docker-compose.yml file:
14-
```
15-
curl -o docker-compose.yml https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/example02/docker-compose.yml
12+
* Copy our [docker-compose.yml](https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/docker-compose.yml) file to a local directory:
13+
14+
```
15+
curl -o docker-compose.yml https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/docker-compose.yml
16+
```
17+
* **Optionally** build your own docker images.
18+
The docker compose environment uses three docker images. If you wish to customize and build your own docker images. The following [Dockerfile](https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/Dockerfile)
19+
was used to build the **nodesdk** image and may be used as a starting point to your own customizations.
20+
```
21+
curl -o Dockerfile https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/Dockerfile
22+
docker build -t hyperledger/fabric-node-sdk:latest .
23+
```
24+
25+
* Start the fabric network environment using docker-compose. From a terminal session that has the working directory of where the above *docker-compose.yml* is located, execute one of following **docker-compose** commands.
26+
27+
* to run as detached containers:
28+
```
29+
docker-compose up -d
30+
```
31+
**note:** to see the logs for the **peer** container use the `docker logs peer` command
32+
33+
* to run in the foreground and see the log output in the current terminal session:
34+
```
35+
docker-compose up
36+
```
37+
38+
Both commands will start three docker containers, to view the container status try `docker ps` command. The first time this is run the **docker** images will be downloaded. This may take 10 minutes or more depending on the network connections of the system running the command.
39+
```
40+
docker ps
1641
```
1742
18-
docker-compose.yml:
19-
```yaml
20-
membersrvc:
21-
# try 'docker ps' to see the container status after starting this compose
22-
container_name: membersrvc
23-
image: hyperledger/fabric-membersrvc
24-
command: membersrvc
25-
26-
peer:
27-
container_name: peer
28-
image: hyperledger/fabric-peer
29-
environment:
30-
- CORE_PEER_ADDRESSAUTODETECT=true
31-
- CORE_VM_ENDPOINT=unix:///var/run/docker.sock
32-
- CORE_LOGGING_LEVEL=DEBUG
33-
- CORE_PEER_ID=vp0
34-
- CORE_SECURITY_ENABLED=true
35-
- CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
36-
- CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
37-
- CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
38-
- CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=noops
39-
# this gives access to the docker host daemon to deploy chaincode in network mode
40-
volumes:
41-
- /var/run/docker.sock:/var/run/docker.sock
42-
# have the peer wait 10 sec for membersrvc to start
43-
# the following is to run the peer in Developer mode - also set sample DEPLOY_MODE=dev
44-
command: sh -c "sleep 10; peer node start --peer-chaincodedev"
45-
#command: sh -c "sleep 10; peer node start"
46-
links:
47-
- membersrvc
48-
49-
nodesdk:
50-
container_name: nodesdk
51-
image: hyperledger/fabric-node-sdk
52-
volumes:
53-
- ~/mytest:/user/mytest
54-
environment:
55-
- MEMBERSRVC_ADDRESS=membersrvc:7054
56-
- PEER_ADDRESS=peer:7051
57-
- KEY_VALUE_STORE=/tmp/hl_sdk_node_key_value_store
58-
- NODE_PATH=/usr/local/lib/node_modules
59-
# set DEPLOY_MODE to 'dev' if peer running in Developer mode
60-
- DEPLOY_MODE=dev
61-
- CORE_CHAINCODE_ID_NAME=mycc
62-
- CORE_PEER_ADDRESS=peer:7051
63-
# the following command will start the chaincode when this container starts and ready it for deployment by the app
64-
command: sh -c "sleep 20; /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/chaincode_example02"
65-
stdin_open: true
66-
tty: true
67-
links:
68-
- membersrvc
69-
- peer
70-
43+
You should see something like the following:
44+
```
45+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46+
bb01a2fa96ef hyperledger/fabric-node-sdk "sh -c 'sleep 20; /op" About a minute ago Up 59 seconds nodesdk
47+
ec7572e65f12 hyperledger/fabric-peer "sh -c 'sleep 10; pee" About a minute ago Up About a minute peer
48+
118ef6da1709 hyperledger/fabric-membersrvc "membersrvc" About a minute ago Up About a minute membersrvc
7149
```
7250
73-
3. Start the fabric environment using docker-compose. From a terminal session where the working directory is where the *docker-compose.yml* from step 2 is located, execute one of following **docker-compose** commands.
51+
* Start a terminal session in the **nodesdk** container. This is where the Node.js application is located.
7452
75-
* to run as detached containers, then to see the logs for the **peer** container use the `docker logs peer` command
76-
```
77-
docker-compose up -d
78-
```
79-
* to run in the foreground and see the log output in the current terminal session
80-
```
81-
docker-compose up
82-
```
83-
84-
This will start three docker containers, to view the container status try `docker ps` command. The first time this is run the **docker** images will be downloaded. This may take 10 minutes or more depending on the network connections of the system running the command.
85-
* Membership services --**membersrvc**
86-
* Peer -- **peer**
87-
* Node.js SDK Application and chaincode -- **nodesdk**
88-
89-
4. Start a terminal session in the **nodesdk** container. This is where the Node.js application is located.
53+
**note:** Be sure to wait 20 seconds after starting the network using the `docker-compose up` command before executing the following command to allow the network to initialize.
9054
91-
**Note:** Be sure to wait 20 seconds after starting the network before executing.
92-
93-
```
55+
```
9456
docker exec -it nodesdk /bin/bash
95-
```
57+
```
9658
97-
5. From the terminal session in the **nodesdk** container execute the standalone Node.js application. The docker terminal session should be in the working directory of the sample application called **app.js** (*/opt/gopath/src/github.com/hyperledger/fabric/examples/sdk/node/example02*). Execute the following Node.js command to run the application.
59+
* From the terminal session in the **nodesdk** container execute the standalone Node.js application. The docker terminal session should be in the working directory of the sample application called **app.js** (*/opt/gopath/src/github.com/hyperledger/fabric/examples/sdk/node*). Execute the following Node.js command to run the application.
9860
99-
```
61+
```
10062
node app
101-
```
102-
On another terminal session on the host you can view the logs for the peer by executing the following command (not in the docker shell above, in a new terminal session of the real system)
103-
```
63+
```
64+
In another terminal session on the host you can view the logs for the peer by executing the following command (not in the docker shell above, in a new terminal session of the real system)
65+
```
10466
docker logs peer
105-
```
106-
107-
6. This environment will have the reference documentation already built and may be access by:
108-
```
109-
docker exec -it nodesdk /bin/bash
110-
cd /opt/gopath/src/github.com/hyperledger/fabric/sdk/node/doc
111-
```
112-
113-
7. If you wish to run your own Node.js application
114-
* use the directories in the `volumes` tag under **nodesdk** in the `docker-compose.yml` file as a place to store your programs from the host system into the docker container. The first path is the top level system (host system) and the second is created in the docker container. If you wish to use a host location that is not under the `/Users` directory (`~` is under `/Users') then you must add that to the **docker** file sharing under **docker** preferences.
115-
```yaml
67+
```
68+
69+
* If you wish to run your own Node.js application using the pre build docker images:
70+
* use the directories in the `volumes` tag under **nodesdk** in the `docker-compose.yml` file as a place to store your programs from the host system into the docker container. The first path is the top level system (host system) and the second is created in the docker container. If you wish to use a host location that is not under the `/Users` directory (`~` is under `/Users') then you must add that to the **docker** file sharing under **docker** preferences.
71+
72+
```yaml
11673
volumes:
11774
- ~/mytest:/user/mytest
118-
```
75+
```
11976
* copy or create and edit your application in the `~/mytest` directory as stated in the `docker-compose.yml` `volumes` tag under **nodesdk** container.
12077
* run npm to install Hyperledger Fabric Node.js SDK in the `mytest` directory
121-
```
122-
npm install /opt/gopath/src/github.com/hyperledger/fabric/sdk/node
123-
```
78+
```
79+
npm install /opt/gopath/src/github.com/hyperledger/fabric/sdk/node
80+
```
12481
* run the application from within the **nodesdk** docker container using the commands
125-
```
82+
```
12683
docker exec -it nodesdk /bin/bash
127-
```
84+
```
12885
once in the shell, and assuming your Node.js application is called `app.js`
129-
```
86+
```
13087
cd /user/mytest
13188
node app
132-
```
89+
```
90+
* To shutdown the environment, execute the following **docker-compose** command in the directory where the *docker-compose.yml* is located. Any changes you made to the sample application or deployment of a chaincode will be lost. Only changes made to the shared area defined in the 'volumes' tag of the **nodesdk** container will persist. This will shutdown each of the containers and remove the containers from **docker**:
13391

134-
8. To shutdown the environment, execute the following **docker-compose** command in the directory where the *docker-compose.yml* is located. Any changes you made to the sample application or deployment of a chaincode will be lost. Only changes made to the shared area defined in the 'volumes' tag of the **nodesdk** container will persist. This will shutdown each of the containers and remove the containers from **docker**:
135-
136-
```
92+
```
13793
docker-compose down
138-
```
139-
94+
```
14095
or if you wish to keep your changes and just stop the containers, which will be restarted on the next `up` command
141-
142-
```
96+
97+
```
14398
docker-compose kill
144-
```
145-
99+
```

‎docs/nodeSDK/sample-standalone-app.md

+25-110
Original file line numberDiff line numberDiff line change
@@ -2,133 +2,48 @@
22

33
This section describes how to run a sample standalone Node.js application which interacts with a Hyperledger fabric blockchain.
44

5-
1. If you haven't already done so, see [Setting Up The Application Development Environment](app-developer-env-setup.md) to get your environment set up. The remaining steps assume that you are running **inside the vagrant environment**.
5+
* If you haven't already done so, see [Setting Up The Application Development Environment](app-developer-env-setup.md) to get your environment set up. The remaining steps assume that you are running **inside the vagrant environment**.
66

7-
2. Issue the following commands to build the Node.js Client SDK:
7+
* Issue the following commands to build the Node.js Client SDK:
88

9-
```
9+
```
1010
cd /opt/gopath/src/github.com/hyperledger/fabric
1111
make node-sdk
12-
```
12+
```
1313

14-
3. Start the membership services and peer processes. We run the peer in dev mode for simplicity.
14+
* Start the membership services and peer processes. We run the peer in dev mode for simplicity.
1515

16-
```
16+
```
1717
cd /opt/gopath/src/github.com/hyperledger/fabric/build/bin
1818
membersrvc > membersrvc.log 2>&1&
1919
peer node start --peer-chaincodedev > peer.log 2>&1&
20-
```
20+
```
2121

22-
4. Build and run chaincode example 2:
22+
* Build and run chaincode example 2:
2323

24-
```
24+
```
2525
cd /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
2626
go build
27-
CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:30303 ./chaincode_example02 > log 2>&1&
28-
```
27+
CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:7051 ./chaincode_example02 > log 2>&1&
28+
```
2929

30-
5. Put the following sample app in a file named **app.js** in the */tmp* directory. Take a moment (now or later) to read the comments and code to begin to learn the Node.js Client SDK APIs.
30+
* Put the following sample app in a file named **app.js** in the */tmp* directory. Take a moment (now or later) to read the comments and code to begin to learn the Node.js Client SDK APIs.
3131

32-
You may retrieve the sample application file:
33-
```
34-
curl -o webapp.js https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/standalone-app.js
35-
```
36-
The sample app:
32+
You may retrieve the [sample application](https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/app.js) file:
33+
```
34+
cd /tmp
35+
curl -o app.js https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/app.js
36+
```
37+
* Run **npm** to install Hyperledger Fabric Node.js SDK in the `/tmp` directory
38+
```
39+
npm install /opt/gopath/src/github.com/hyperledger/fabric/sdk/node
40+
```
3741

38-
```javascript
39-
/*
40-
* A simple application utilizing the Node.js Client SDK to:
41-
* 1) Enroll a user
42-
* 2) User deploys chaincode
43-
* 3) User queries chaincode
44-
*/
45-
// "HFC" stands for "Hyperledger fabric Client"
46-
var hfc = require("hfc");
42+
* Run the application as follows:
4743

48-
var chain, user, chaincodeID;
49-
50-
// Create a chain object used to interact with the chain.
51-
// You can name it anything you want as it is only used by client.
52-
chain = hfc.newChain("mychain");
53-
// Initialize the place to store sensitive private key information
54-
chain.setKeyValStore( hfc.newFileKeyValStore('/tmp/keyValStore') );
55-
// Set the URL to membership services and to the peer
56-
chain.setMemberServicesUrl("grpc://localhost:7054");
57-
chain.addPeer("grpc://localhost:7051");
58-
// The following is required when the peer is started in dev mode
59-
// (i.e. with the '--peer-chaincodedev' option)
60-
chain.setDevMode(true);
61-
62-
// Begin by enrolling the user
63-
enroll();
64-
65-
// Enroll a user.
66-
function enroll() {
67-
console.log("enrolling user admin ...");
68-
// Enroll "admin" which is preregistered in the membersrvc.yaml
69-
chain.enroll("admin", "Xurw3yU9zI0l", function(err, admin) {
70-
if (err) {
71-
console.log("ERROR: failed to register admin: %s",err);
72-
process.exit(1);
73-
}
74-
user = admin;
75-
deploy();
76-
});
77-
}
78-
79-
// Deploy chaincode
80-
function deploy() {
81-
console.log("deploying chaincode; please wait ...");
82-
// Construct the deploy request
83-
var req = {
84-
chaincodeName: 'mycc',
85-
fcn: "init",
86-
args: ["a", "100", "b", "200"]
87-
};
88-
// Issue the deploy request and listen for events
89-
var tx = user.deploy(req);
90-
tx.on('complete', function(results) {
91-
// Deploy request completed successfully
92-
console.log("deploy complete; results: %j",results);
93-
// Set the testChaincodeID for subsequent tests
94-
chaincodeID = results.chaincodeID;
95-
query();
96-
});
97-
tx.on('error', function(err) {
98-
console.log("Failed to deploy chaincode: request=%j, error=%k",req,err);
99-
process.exit(1);
100-
});
101-
102-
}
103-
104-
// Query chaincode
105-
function query() {
106-
console.log("querying chaincode ...");
107-
// Construct a query request
108-
var req = {
109-
chaincodeID: chaincodeID,
110-
fcn: "query",
111-
args: ["a"]
112-
};
113-
// Issue the query request and listen for events
114-
var tx = user.query(req);
115-
tx.on('complete', function (results) {
116-
console.log("query completed successfully; results=%j",results);
117-
process.exit(0);
118-
});
119-
tx.on('error', function (err) {
120-
console.log("Failed to query chaincode: request=%j, error=%k",req,err);
121-
process.exit(1);
122-
});
123-
}
124-
```
125-
126-
6. Run the application as follows:
127-
128-
```
129-
cd /tmp
44+
```
13045
node app
131-
```
46+
```
13247

133-
7. Congratulations! You've successfully run your first Hyperledger fabric application.
48+
Congratulations! You've successfully run your first Hyperledger fabric application.
13449

‎docs/nodeSDK/sample-web-app.md

+3-102
Original file line numberDiff line numberDiff line change
@@ -4,109 +4,10 @@ The following is a web application template. It is NOT a complete program.
44

55
This template code demonstrates how to communicate with a blockchain from a Node.js web application. It does not show how to listen for incoming requests nor how to authenticate your web users as this is application specific. The code below is intended to demonstrate how to interact with a Hyperledger fabric blockchain from an existing web application.
66

7-
You may retrieve the sample application file:
7+
You may retrieve the [sample application]( https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/web-app.js) file:
8+
89
```
9-
curl -o app.js https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/web-app.js
10+
curl -o app.js https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sdk/node/web-app.js
1011
```
1112

12-
See the embedded comments below.
13-
14-
```javascript
15-
/**
16-
* This example shows how to do the following in a web app.
17-
* 1) At initialization time, enroll the web app with the blockchain.
18-
* The identity must have already been registered.
19-
* 2) At run time, after a user has authenticated with the web app:
20-
* a) register and enroll an identity for the user;
21-
* b) use this identity to deploy, query, and invoke a chaincode.
22-
*/
23-
var hfc = require('hfc');
24-
25-
// Create a client chain.
26-
// The name can be anything as it is only used internally.
27-
var chain = hfc.newChain("targetChain");
28-
29-
// Configure the KeyValStore which is used to store sensitive keys
30-
// as so it is important to secure this storage.
31-
// The FileKeyValStore is a simple file-based KeyValStore, but you
32-
// can easily implement your own to store whereever you want.
33-
// To work correctly in a cluster, the file-based KeyValStore must
34-
// either be on a shared file system shared by all members of the cluster
35-
// or you must implement you own KeyValStore which all members of the
36-
// cluster can share.
37-
chain.setKeyValStore( hfc.newFileKeyValStore('/tmp/keyValStore') );
38-
39-
// Set the URL for membership services
40-
chain.setMemberServicesUrl("grpc://localhost:7054");
4113

42-
// Add at least one peer's URL. If you add multiple peers, it will failover
43-
// to the 2nd if the 1st fails, to the 3rd if both the 1st and 2nd fails, etc.
44-
chain.addPeer("grpc://localhost:7051");
45-
46-
// Enroll "WebAppAdmin" which is already registered because it is
47-
// listed in fabric/membersrvc/membersrvc.yaml with its one time password.
48-
// If "WebAppAdmin" has already been registered, this will still succeed
49-
// because it stores the state in the KeyValStore
50-
// (i.e. in '/tmp/keyValStore' in this sample).
51-
chain.enroll("WebAppAdmin", "DJY27pEnl16d", function(err, webAppAdmin) {
52-
if (err) return console.log("ERROR: failed to register %s: %s",err);
53-
// Successfully enrolled WebAppAdmin during initialization.
54-
// Set this user as the chain's registrar which is authorized to register other users.
55-
chain.setRegistrar(webAppAdmin);
56-
// Now begin listening for web app requests
57-
listenForUserRequests();
58-
});
59-
60-
// Main web app function to listen for and handle requests. This is specific to
61-
// your application but is provided here to demonstrate the pattern.
62-
function listenForUserRequests() {
63-
for (;;) {
64-
// WebApp-specific logic goes here to await the next request.
65-
// ...
66-
// Assume that we received a request from an authenticated user
67-
// 'userName', and determined that we need to invoke the chaincode
68-
// with 'chaincodeID' and function named 'fcn' with arguments 'args'.
69-
handleUserRequest(userName,chaincodeID,fcn,args);
70-
}
71-
}
72-
73-
// Handle a user request
74-
function handleUserRequest(userName, chaincodeID, fcn, args) {
75-
// Register and enroll this user.
76-
// If this user has already been registered and/or enrolled, this will
77-
// still succeed because the state is kept in the KeyValStore
78-
// (i.e. in '/tmp/keyValStore' in this sample).
79-
var registrationRequest = {
80-
enrollmentID: userName,
81-
// Customize account & affiliation
82-
account: "bank_a",
83-
affiliation: "00001"
84-
};
85-
chain.registerAndEnroll( registrationRequest, function(err, user) {
86-
if (err) return console.log("ERROR: %s",err);
87-
// Issue an invoke request
88-
var invokeRequest = {
89-
// Name (hash) required for invoke
90-
chaincodeID: chaincodeID,
91-
// Function to trigger
92-
fcn: fcn,
93-
// Parameters for the invoke function
94-
args: args
95-
};
96-
// Invoke the request from the user object and wait for events to occur.
97-
var tx = user.invoke(invokeRequest);
98-
// Listen for the 'submitted' event
99-
tx.on('submitted', function(results) {
100-
console.log("submitted invoke: %j",results);
101-
});
102-
// Listen for the 'complete' event.
103-
tx.on('complete', function(results) {
104-
console.log("completed invoke: %j",results);
105-
});
106-
// Listen for the 'error' event.
107-
tx.on('error', function(err) {
108-
console.log("error on invoke: %j",err);
109-
});
110-
});
111-
}
112-
```

‎examples/sdk/node/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM hyperledger/fabric-peer:latest
2+
# setup the chaincode sample
3+
WORKDIR $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
4+
RUN go build
5+
# build the node SDK
6+
WORKDIR $GOPATH/src/github.com/hyperledger/fabric/sdk/node
7+
RUN make all
8+
# now switch to the sample node app location when the shell is opened in the docker
9+
WORKDIR $GOPATH/src/github.com/hyperledger/fabric/examples/sdk/node
10+
# install the hfc locally for use by the application
11+
RUN npm install $GOPATH/src/github.com/hyperledger/fabric/sdk/node

‎examples/sdk/node/app.js

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
Copyright IBM Corp 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
* A simple application utilizing the Node.js Client SDK to:
19+
* 1) Enroll a user
20+
* 2) User deploys chaincode
21+
* 3) User queries chaincode
22+
*/
23+
// "HFC" stands for "Hyperledger Fabric Client"
24+
var hfc = require("hfc");
25+
26+
console.log(" **** starting HFC sample ****");
27+
28+
29+
// get the addresses from the docker-compose environment
30+
var PEER_ADDRESS = process.env.CORE_PEER_ADDRESS;
31+
var MEMBERSRVC_ADDRESS = process.env.MEMBERSRVC_ADDRESS;
32+
33+
var chain, chaincodeID;
34+
35+
// Create a chain object used to interact with the chain.
36+
// You can name it anything you want as it is only used by client.
37+
chain = hfc.newChain("mychain");
38+
// Initialize the place to store sensitive private key information
39+
chain.setKeyValStore( hfc.newFileKeyValStore('/tmp/keyValStore') );
40+
// Set the URL to membership services and to the peer
41+
console.log("member services address ="+MEMBERSRVC_ADDRESS);
42+
console.log("peer address ="+PEER_ADDRESS);
43+
chain.setMemberServicesUrl("grpc://"+MEMBERSRVC_ADDRESS);
44+
chain.addPeer("grpc://"+PEER_ADDRESS);
45+
46+
// The following is required when the peer is started in dev mode
47+
// (i.e. with the '--peer-chaincodedev' option)
48+
var mode = process.env['DEPLOY_MODE'];
49+
console.log("DEPLOY_MODE=" + mode);
50+
if (mode === 'dev') {
51+
chain.setDevMode(true);
52+
//Deploy will not take long as the chain should already be running
53+
chain.setDeployWaitTime(10);
54+
} else {
55+
chain.setDevMode(false);
56+
//Deploy will take much longer in network mode
57+
chain.setDeployWaitTime(120);
58+
}
59+
60+
61+
chain.setInvokeWaitTime(10);
62+
63+
// Begin by enrolling the user
64+
enroll();
65+
66+
// Enroll a user.
67+
function enroll() {
68+
console.log("enrolling user admin ...");
69+
// Enroll "admin" which is preregistered in the membersrvc.yaml
70+
chain.enroll("admin", "Xurw3yU9zI0l", function(err, admin) {
71+
if (err) {
72+
console.log("ERROR: failed to register admin: %s",err);
73+
process.exit(1);
74+
}
75+
// Set this user as the chain's registrar which is authorized to register other users.
76+
chain.setRegistrar(admin);
77+
78+
var userName = "JohnDoe";
79+
// registrationRequest
80+
var registrationRequest = {
81+
enrollmentID: userName,
82+
affiliation: "bank_a"
83+
};
84+
chain.registerAndEnroll(registrationRequest, function(error, user) {
85+
if (error) throw Error(" Failed to register and enroll " + userName + ": " + error);
86+
console.log("Enrolled %s successfully\n", userName);
87+
deploy(user);
88+
});
89+
});
90+
}
91+
92+
// Deploy chaincode
93+
function deploy(user) {
94+
console.log("deploying chaincode; please wait ...");
95+
// Construct the deploy request
96+
var deployRequest = {
97+
chaincodeName: process.env.CORE_CHAINCODE_ID_NAME,
98+
fcn: "init",
99+
args: ["a", "100", "b", "200"]
100+
};
101+
// where is the chain code, ignored in dev mode
102+
deployRequest.chaincodePath = "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02";
103+
104+
// Issue the deploy request and listen for events
105+
var tx = user.deploy(deployRequest);
106+
tx.on('complete', function(results) {
107+
// Deploy request completed successfully
108+
console.log("deploy complete; results: %j",results);
109+
// Set the testChaincodeID for subsequent tests
110+
chaincodeID = results.chaincodeID;
111+
invoke(user);
112+
});
113+
tx.on('error', function(error) {
114+
console.log("Failed to deploy chaincode: request=%j, error=%k",deployRequest,error);
115+
process.exit(1);
116+
});
117+
118+
}
119+
120+
// Query chaincode
121+
function query(user) {
122+
console.log("querying chaincode ...");
123+
// Construct a query request
124+
var queryRequest = {
125+
chaincodeID: chaincodeID,
126+
fcn: "query",
127+
args: ["a"]
128+
};
129+
// Issue the query request and listen for events
130+
var tx = user.query(queryRequest);
131+
tx.on('complete', function (results) {
132+
console.log("query completed successfully; results=%j",results);
133+
process.exit(0);
134+
});
135+
tx.on('error', function (error) {
136+
console.log("Failed to query chaincode: request=%j, error=%k",queryRequest,error);
137+
process.exit(1);
138+
});
139+
}
140+
141+
//Invoke chaincode
142+
function invoke(user) {
143+
console.log("invoke chaincode ...");
144+
// Construct a query request
145+
var invokeRequest = {
146+
chaincodeID: chaincodeID,
147+
fcn: "invoke",
148+
args: ["a", "b", "1"]
149+
};
150+
// Issue the invoke request and listen for events
151+
var tx = user.invoke(invokeRequest);
152+
tx.on('submitted', function (results) {
153+
console.log("invoke submitted successfully; results=%j",results);
154+
});
155+
tx.on('complete', function (results) {
156+
console.log("invoke completed successfully; results=%j",results);
157+
query(user);
158+
});
159+
tx.on('error', function (error) {
160+
console.log("Failed to invoke chaincode: request=%j, error=%k",invokeRequest,error);
161+
process.exit(1);
162+
});
163+
}

‎examples/sdk/node/docker-compose.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
membersrvc:
2+
# try 'docker ps' to see the container status after starting this compose
3+
container_name: membersrvc
4+
image: hyperledger/fabric-membersrvc
5+
command: membersrvc
6+
7+
peer:
8+
container_name: peer
9+
image: hyperledger/fabric-peer
10+
environment:
11+
- CORE_PEER_ADDRESSAUTODETECT=true
12+
- CORE_VM_ENDPOINT=unix:///var/run/docker.sock
13+
- CORE_LOGGING_LEVEL=DEBUG
14+
- CORE_PEER_ID=vp0
15+
- CORE_SECURITY_ENABLED=true
16+
- CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
17+
- CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
18+
- CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
19+
- CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=noops
20+
# this gives access to the docker host daemon to deploy chain code in network mode
21+
volumes:
22+
- /var/run/docker.sock:/var/run/docker.sock
23+
# have the peer wait 10 sec for membersrvc to start
24+
# the following is to run the peer in Developer mode - also set sample DEPLOY_MODE=dev
25+
command: sh -c "sleep 10; peer node start --peer-chaincodedev"
26+
#command: sh -c "sleep 10; peer node start"
27+
links:
28+
- membersrvc
29+
30+
nodesdk:
31+
container_name: nodesdk
32+
image: hyperledger/fabric-node-sdk
33+
volumes:
34+
- ~/mytest:/user/mytest
35+
environment:
36+
- MEMBERSRVC_ADDRESS=membersrvc:7054
37+
- PEER_ADDRESS=peer:7051
38+
- KEY_VALUE_STORE=/tmp/hl_sdk_node_key_value_store
39+
# set to following to 'dev' if peer running in Developer mode
40+
- DEPLOY_MODE=dev
41+
- CORE_CHAINCODE_ID_NAME=mycc
42+
- CORE_PEER_ADDRESS=peer:7051
43+
# the following command will start the chain code when this container starts and ready it for deployment by the app
44+
command: sh -c "sleep 20; /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/chaincode_example02"
45+
stdin_open: true
46+
tty: true
47+
links:
48+
- membersrvc
49+
- peer

‎examples/sdk/node/standalone-app.js

-85
This file was deleted.

‎examples/sdk/node/web-app.js

+32-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright IBM Corp 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
/**
218
* This example shows how to do the following in a web app.
319
* 1) At initialization time, enroll the web app with the blockchain.
@@ -8,6 +24,10 @@
824
*/
925
var hfc = require('hfc');
1026

27+
//get the addresses from the docker-compose environment
28+
var PEER_ADDRESS = process.env.PEER_ADDRESS;
29+
var MEMBERSRVC_ADDRESS = process.env.MEMBERSRVC_ADDRESS;
30+
1131
// Create a client chain.
1232
// The name can be anything as it is only used internally.
1333
var chain = hfc.newChain("targetChain");
@@ -23,11 +43,11 @@ var chain = hfc.newChain("targetChain");
2343
chain.setKeyValStore( hfc.newFileKeyValStore('/tmp/keyValStore') );
2444

2545
// Set the URL for membership services
26-
chain.setMemberServicesUrl("grpc://localhost:7054");
46+
chain.setMemberServicesUrl("grpc://MEMBERSRVC_ADDRESS");
2747

2848
// Add at least one peer's URL. If you add multiple peers, it will failover
2949
// to the 2nd if the 1st fails, to the 3rd if both the 1st and 2nd fails, etc.
30-
chain.addPeer("grpc://localhost:7051");
50+
chain.addPeer("grpc://PEER_ADDRESS");
3151

3252
// Enroll "WebAppAdmin" which is already registered because it is
3353
// listed in fabric/membersrvc/membersrvc.yaml with its one time password.
@@ -49,25 +69,26 @@ function listenForUserRequests() {
4969
for (;;) {
5070
// WebApp-specific logic goes here to await the next request.
5171
// ...
52-
// Assume that we received a request from an authenticated user
53-
// 'userName', and determined that we need to invoke the chaincode
72+
// Assume that we received a request from an authenticated user
73+
// and have 'userName' and 'userAccount'.
74+
// Then determined that we need to invoke the chaincode
5475
// with 'chaincodeID' and function named 'fcn' with arguments 'args'.
55-
handleUserRequest(userName,chaincodeID,fcn,args);
76+
handleUserRequest(userName,userAccount,chaincodeID,fcn,args);
5677
}
5778
}
5879

5980
// Handle a user request
60-
function handleUserRequest(userName, chaincodeID, fcn, args) {
81+
function handleUserRequest(userName, userAccount, chaincodeID, fcn, args) {
6182
// Register and enroll this user.
6283
// If this user has already been registered and/or enrolled, this will
6384
// still succeed because the state is kept in the KeyValStore
6485
// (i.e. in '/tmp/keyValStore' in this sample).
6586
var registrationRequest = {
66-
enrollmentID: userName,
67-
// Customize account & affiliation
68-
account: "bank_a",
69-
affiliation: "00001"
70-
};
87+
roles: [ 'client' ],
88+
enrollmentID: userName,
89+
affiliation: "bank_a",
90+
attributes: [{name:'role',value:'client'},{name:'account',value:userAccount}]
91+
};
7192
chain.registerAndEnroll( registrationRequest, function(err, user) {
7293
if (err) return console.log("ERROR: %s",err);
7394
// Issue an invoke request

0 commit comments

Comments
 (0)
Please sign in to comment.