Skip to content

Commit 49a4062

Browse files
authored
Fix sample application startup with test-committer and classic fabric (#111)
#### Type of change Bug fix #### Description The test committer version of the sample application was not working, as the channel in the configuration "arma" did not match the channel used in the test committer "mychannel". This is fixed, and the README.md order has been made more readable. Also, updating the Fabric version to 3.1.4; the sample application installs chaincode to create the namespace and this was failing on newer versions of docker (see: hyperledger/fabric#5350). #### Related issues N/A Signed-off-by: Arne Rutjes <arne123@gmail.com>
1 parent fa66154 commit 49a4062

6 files changed

Lines changed: 61 additions & 61 deletions

File tree

samples/tokens/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ COPY . .
1818

1919
RUN --mount=type=cache,target=/go-cache \
2020
--mount=type=cache,target=/gomod-cache \
21-
cd "${NODE_TYPE}" && go build -tags "${PLATFORM}" -o /app
21+
if [ "${PLATFORM}" = "xdev" ]; then BUILD_TAGS="fabricx"; else BUILD_TAGS="${PLATFORM}"; fi && \
22+
cd "${NODE_TYPE}" && go build -tags "${BUILD_TAGS}" -o /app
2223

2324
FROM busybox
2425

samples/tokens/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ include ./app.mk
1919
# Install the utilities needed to run the components on the targeted remote hosts (e.g. make install-prerequisites).
2020
.PHONY: install-prerequisites
2121
install-prerequisites: install-prerequisites-fabric
22-
./install-fabric.sh --fabric-version 3.1.1
22+
./install-fabric.sh --fabric-version 3.1.4
2323
go mod tidy
2424

2525
# Build all the artifacts and binaries, and copy them to the application folders

samples/tokens/README.md

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,32 @@ The **Token SDK Sample** demonstrates how to:
1212

1313
## Table of Contents
1414

15-
- [Table of Contents](#table-of-contents)
16-
- [About the Sample](#about-the-sample)
17-
- [Components](#components)
18-
- [Application services](#application-services)
19-
- [Fabric(x) Blockchain Network](#fabricx-blockchain-network)
20-
- [Application](#application)
21-
- [UTXO Model](#utxo-model)
22-
- [Deep Dive: What Happens During a Transfer?](#deep-dive-what-happens-during-a-transfer)
23-
- [Running the sample](#running-the-sample)
24-
- [Prerequisites](#prerequisites)
25-
- [Default option: Fabric-X with Ansible](#default-option-fabric-x-with-ansible)
26-
- [Requirements](#requirements)
27-
- [Installation](#installation)
28-
- [Setup Fabric-X](#setup-fabric-x)
29-
- [Option 2: Fabric-X test container](#option-2-fabric-x-test-container)
30-
- [Option 3: Fabric v3](#option-3-fabric-v3)
31-
- [Setup Fabric v3](#setup-fabric-v3)
32-
- [Start the Network and Application](#start-the-network-and-application)
33-
- [Interacting with the Application](#interacting-with-the-application)
34-
- [Example: Issue tokens](#example-issue-tokens)
35-
- [Example: Transfer tokens](#example-transfer-tokens)
36-
- [Teardown and cleanup](#teardown-and-cleanup)
37-
- [Development](#development)
38-
- [Debug mode](#debug-mode)
39-
- [VSCode](#vscode)
40-
- [Running the binaries](#running-the-binaries)
41-
- [Troubleshooting](#troubleshooting)
15+
- [Token SDK Sample](#token-sdk-sample)
16+
- [Table of Contents](#table-of-contents)
17+
- [About the Sample](#about-the-sample)
18+
- [Components](#components)
19+
- [Application services](#application-services)
20+
- [Fabric(x) Blockchain Network](#fabricx-blockchain-network)
21+
- [Application](#application)
22+
- [UTXO Model](#utxo-model)
23+
- [Deep Dive: What Happens During a Transfer?](#deep-dive-what-happens-during-a-transfer)
24+
- [Running the sample](#running-the-sample)
25+
- [Prerequisites](#prerequisites)
26+
- [Default option: Fabric-X with Ansible](#default-option-fabric-x-with-ansible)
27+
- [Requirements](#requirements)
28+
- [Installation](#installation)
29+
- [Setup Fabric-X](#setup-fabric-x)
30+
- [Option 2: Fabric-X test container](#option-2-fabric-x-test-container)
31+
- [Option 3: Fabric v3](#option-3-fabric-v3)
32+
- [Interacting with the Application](#interacting-with-the-application)
33+
- [Example: Issue tokens](#example-issue-tokens)
34+
- [Example: Transfer tokens](#example-transfer-tokens)
35+
- [Teardown and cleanup](#teardown-and-cleanup)
36+
- [Development](#development)
37+
- [Debug mode](#debug-mode)
38+
- [VSCode](#vscode)
39+
- [Running the binaries](#running-the-binaries)
40+
- [Troubleshooting](#troubleshooting)
4241

4342
## About the Sample
4443

@@ -161,32 +160,14 @@ make install-prerequisites
161160

162161
### Setup Fabric-X
163162

164-
Make sure that the crypto is cleared and let the scripts know you want to use ansible:
163+
Let the scripts know you want to use ansible (not strictly necessary as this is the default).
164+
Then generate the crypto material.
165165

166166
```shell
167-
make teardown
168-
make clean
169167
export PLATFORM=fabricx
170168
make setup
171169
```
172170

173-
Then, like with the test container:
174-
175-
```shell
176-
make start
177-
curl -X POST http://localhost:9300/endorser/init
178-
```
179-
180-
## Option 2: Fabric-X test container
181-
182-
The quickest way to get going: a test version of Fabric-X in a single docker container! Even if you want to use different backends, we suggest to start here.
183-
184-
First generate the necessary crypto material:
185-
186-
```shell
187-
make setup
188-
```
189-
190171
This creates:
191172

192173
- Fabric
@@ -203,22 +184,42 @@ This creates:
203184

204185
The relevant crypto material is copied to the folders in the conf/\* directories.
205186

206-
The following first command starts the Fabric-X test container, creates a namespace, and runs the application in docker containers. The second command ensures that the parameters for the network (cryptographic material, the idemix issuer identity for the accounts, the token issuer certificate) are registered on the ledger.
187+
Then start the application and initialize it. The "init" endpoint records the cryptographic
188+
parameters and configuration which we generated in the "setup" step on the blockchain. This will be the anchor for the token transactions.
207189

208190
```shell
209191
make start
210192
curl -X POST http://localhost:9300/endorser/init
211193
```
212194

213-
Now open <http://localhost:8080> in your browser to see the other API endpoints, or scroll down to follow some `curl` commands.
195+
## Option 2: Fabric-X test container
214196

215-
## Option 3: Fabric v3
197+
The quickest way for development: a test version of Fabric-X in a single docker container!
198+
First make sure that the crypto from the ansible network is cleared.
216199

217-
Run the same application against a classic Fabric v3 network.
200+
```shell
201+
make teardown
202+
make clean
203+
```
218204

219-
### Setup Fabric v3
205+
Let the scripts know you want to use the test container ('xdev') and generate the necessary crypto material:
220206

221-
First, clean up any previous state and set Fabric v3:
207+
```shell
208+
export PLATFORM=xdev
209+
make setup
210+
```
211+
212+
Start the application and initialize it.
213+
214+
```shell
215+
make start
216+
curl -X POST http://localhost:9300/endorser/init
217+
```
218+
219+
## Option 3: Fabric v3
220+
221+
It's also possible to the same application against a classic Fabric network. Clean up any previous
222+
state and setup the classic Fabric material:
222223

223224
```shell
224225
make teardown
@@ -227,8 +228,6 @@ export PLATFORM=fabric3
227228
make setup
228229
```
229230

230-
### Start the Network and Application
231-
232231
Start the Fabric network, create the namespace (chaincode), and start the application services. For Fabric 3, you don't have to call the Init endpoint; this is taken care of when installing the chaincode.
233232

234233
```shell

samples/tokens/compose-xdev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
environment:
1414
- SC_SIDECAR_ORDERER_IDENTITY_MSP_DIR=/root/config/crypto/peerOrganizations/org1.example.com/peers/SC.org1.example.com/msp
1515
- SC_SIDECAR_ORDERER_IDENTITY_MSP_ID=Org1MSP
16-
- SC_SIDECAR_ORDERER_CHANNEL_ID=mychannel
16+
- SC_SIDECAR_ORDERER_CHANNEL_ID=arma
1717
- SC_SIDECAR_ORDERER_SIGNED_ENVELOPES=true
1818
- SC_QUERY_SERVICE_SERVER_ENDPOINT=:7001
1919
- SC_ORDERER_BLOCK_SIZE=1

samples/tokens/fabricx_ansible.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CONTAINER_CLI ?= docker
3333
install-prerequisites-fabric:
3434
python3 -m venv $(VENV_DIR)
3535
$(VENV_DIR)/bin/python -m pip install --upgrade pip
36-
$(VENV_DIR)/bin/pip install -r $(ANSIBLE_PATH)/requirements.txt
36+
$(VENV_DIR)/bin/python -m pip install -r $(ANSIBLE_PATH)/requirements.txt
3737
ansible-galaxy collection install -r $(ANSIBLE_PATH)/requirements.yml
3838
ansible-playbook "$(PLAYBOOK_PATH)/01-install-control-node-prerequisites.yaml"
3939
ansible-playbook hyperledger.fabricx.install_prerequisites --extra-vars '{"target_hosts": "$(TARGET_HOSTS)"}'

samples/tokens/fabricx_dev.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ install-prerequisites-fabric:
1616
.PHONY: setup-fabric
1717
setup-fabric:
1818
@go tool cryptogen generate --config crypto-config.yaml --output crypto
19-
@go tool configtxgen --channelID mychannel --profile OrgsChannel --outputBlock crypto/sc-genesis-block.proto.bin
19+
@go tool configtxgen --channelID arma --profile OrgsChannel --outputBlock crypto/sc-genesis-block.proto.bin
2020
@CRYPTO_DIR=crypto ./scripts/cp_fabricx.sh
2121

2222
# Clean all the artifacts (configs and bins) built on the controller node (e.g. make clean).
@@ -33,7 +33,7 @@ start-fabric:
3333
@$(CONTAINER_CLI) network inspect fabric_test >/dev/null 2>&1 || $(CONTAINER_CLI) network create fabric_test
3434
@$(CONTAINER_CLI) compose -f compose-xdev.yml up -d --wait && sleep 2
3535
@echo "install namespace:"
36-
@go tool fxconfig namespace create token_namespace --channel=mychannel --orderer=localhost:7050 --mspID=Org1MSP \
36+
@go tool fxconfig namespace create token_namespace --channel=arma --orderer=localhost:7050 --mspID=Org1MSP \
3737
--mspConfigPath=crypto/peerOrganizations/org1.example.com/users/channel_admin@org1.example.com/msp \
3838
--pk=crypto/peerOrganizations/org1.example.com/users/endorser@org1.example.com/msp/signcerts/endorser@org1.example.com-cert.pem
3939
@until go tool fxconfig namespace list --endpoint=localhost:7001 2>/dev/null | grep -q token_namespace; do sleep 1; echo "waiting for namespace to be created..."; done

0 commit comments

Comments
 (0)