Skip to content

Commit 463b148

Browse files
committed
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 <[email protected]>
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.

0 commit comments

Comments
 (0)