mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +00:00
[FAB-14487] Make FabCar use BYFN, not basic-network
Update FabCar to use BYFN. As a result, the sample client applications need to change so that they use the correct connection profile paths, and so that they use service discovery. Change-Id: If02b7fb4ad308c6a7d1e1aa9f953e1bc4e942719 Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
This commit is contained in:
parent
8271a472f8
commit
2a5a59b60a
9 changed files with 99 additions and 48 deletions
|
|
@ -9,7 +9,7 @@ const { FileSystemWallet, X509WalletMixin } = require('fabric-network');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', 'basic-network', 'connection.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
||||||
const ccp = JSON.parse(ccpJSON);
|
const ccp = JSON.parse(ccpJSON);
|
||||||
|
|
||||||
|
|
@ -17,8 +17,10 @@ async function main() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Create a new CA client for interacting with the CA.
|
// Create a new CA client for interacting with the CA.
|
||||||
const caURL = ccp.certificateAuthorities['ca.example.com'].url;
|
const caInfo = ccp.certificateAuthorities['ca.org1.example.com'];
|
||||||
const ca = new FabricCAServices(caURL);
|
const caTLSCACertsPath = path.resolve(__dirname, '..', '..', 'first-network', caInfo.tlsCACerts.path);
|
||||||
|
const caTLSCACerts = fs.readFileSync(caTLSCACertsPath);
|
||||||
|
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
|
||||||
|
|
||||||
// Create a new file system based wallet for managing identities.
|
// Create a new file system based wallet for managing identities.
|
||||||
const walletPath = path.join(process.cwd(), 'wallet');
|
const walletPath = path.join(process.cwd(), 'wallet');
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { FileSystemWallet, Gateway } = require('fabric-network');
|
const { FileSystemWallet, Gateway } = require('fabric-network');
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', 'basic-network', 'connection.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
|
||||||
const ccp = JSON.parse(ccpJSON);
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -30,7 +27,7 @@ async function main() {
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccp, { wallet, identity: 'user1', discovery: { enabled: false } });
|
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { FileSystemWallet, Gateway } = require('fabric-network');
|
const { FileSystemWallet, Gateway } = require('fabric-network');
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', 'basic-network', 'connection.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
|
||||||
const ccp = JSON.parse(ccpJSON);
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -30,7 +27,7 @@ async function main() {
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccp, { wallet, identity: 'user1', discovery: { enabled: false } });
|
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { FileSystemWallet, Gateway, X509WalletMixin } = require('fabric-network');
|
const { FileSystemWallet, Gateway, X509WalletMixin } = require('fabric-network');
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', 'basic-network', 'connection.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
|
||||||
const ccp = JSON.parse(ccpJSON);
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -37,7 +34,7 @@ async function main() {
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccp, { wallet, identity: 'admin', discovery: { enabled: false } });
|
await gateway.connect(ccpPath, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the CA client object from the gateway for interacting with the CA.
|
// Get the CA client object from the gateway for interacting with the CA.
|
||||||
const ca = gateway.getClient().getCertificateAuthority();
|
const ca = gateway.getClient().getCertificateAuthority();
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ CC_SRC_LANGUAGE=${1:-"go"}
|
||||||
CC_SRC_LANGUAGE=`echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:]`
|
CC_SRC_LANGUAGE=`echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:]`
|
||||||
if [ "$CC_SRC_LANGUAGE" = "go" -o "$CC_SRC_LANGUAGE" = "golang" ]; then
|
if [ "$CC_SRC_LANGUAGE" = "go" -o "$CC_SRC_LANGUAGE" = "golang" ]; then
|
||||||
CC_RUNTIME_LANGUAGE=golang
|
CC_RUNTIME_LANGUAGE=golang
|
||||||
CC_SRC_PATH=github.com/fabcar/go
|
CC_SRC_PATH=github.com/chaincode/fabcar/go
|
||||||
elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
|
elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
|
||||||
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
|
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
|
||||||
CC_SRC_PATH=/opt/gopath/src/github.com/fabcar/javascript
|
CC_SRC_PATH=/opt/gopath/src/github.com/chaincode/fabcar/javascript
|
||||||
elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
|
elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
|
||||||
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
|
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
|
||||||
CC_SRC_PATH=/opt/gopath/src/github.com/fabcar/typescript
|
CC_SRC_PATH=/opt/gopath/src/github.com/chaincode/fabcar/typescript
|
||||||
echo Compiling TypeScript code into JavaScript ...
|
echo Compiling TypeScript code into JavaScript ...
|
||||||
pushd ../chaincode/fabcar/typescript
|
pushd ../chaincode/fabcar/typescript
|
||||||
npm install
|
npm install
|
||||||
|
|
@ -38,18 +38,83 @@ fi
|
||||||
rm -rf ./hfc-key-store
|
rm -rf ./hfc-key-store
|
||||||
|
|
||||||
# launch network; create channel and join peer to channel
|
# launch network; create channel and join peer to channel
|
||||||
cd ../basic-network
|
cd ../first-network
|
||||||
./start.sh
|
echo y | ./byfn.sh down
|
||||||
|
echo y | ./byfn.sh up -a -n -s couchdb
|
||||||
|
|
||||||
# Now launch the CLI container in order to install, instantiate chaincode
|
CONFIG_ROOT=/opt/gopath/src/github.com/hyperledger/fabric/peer
|
||||||
# and prime the ledger with our 10 cars
|
ORG1_MSPCONFIGPATH=${CONFIG_ROOT}/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
||||||
docker-compose -f ./docker-compose.yml up -d cli
|
ORG1_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
|
||||||
docker ps -a
|
ORG2_MSPCONFIGPATH=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
|
||||||
|
ORG2_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
||||||
|
ORDERER_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
|
||||||
|
set -x
|
||||||
|
|
||||||
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n fabcar -v 1.0 -p "$CC_SRC_PATH" -l "$CC_RUNTIME_LANGUAGE"
|
echo "Installing smart contract on peer0.org1.example.com"
|
||||||
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -l "$CC_RUNTIME_LANGUAGE" -v 1.0 -c '{"Args":[]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
|
docker exec \
|
||||||
|
-e CORE_PEER_LOCALMSPID=Org1MSP \
|
||||||
|
-e CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
|
||||||
|
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
|
||||||
|
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_TLS_ROOTCERT_FILE} \
|
||||||
|
cli \
|
||||||
|
peer chaincode install \
|
||||||
|
-n fabcar \
|
||||||
|
-v 1.0 \
|
||||||
|
-p "$CC_SRC_PATH" \
|
||||||
|
-l "$CC_RUNTIME_LANGUAGE"
|
||||||
|
|
||||||
|
echo "Installing smart contract on peer0.org2.example.com"
|
||||||
|
docker exec \
|
||||||
|
-e CORE_PEER_LOCALMSPID=Org2MSP \
|
||||||
|
-e CORE_PEER_ADDRESS=peer0.org2.example.com:9051 \
|
||||||
|
-e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH} \
|
||||||
|
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_TLS_ROOTCERT_FILE} \
|
||||||
|
cli \
|
||||||
|
peer chaincode install \
|
||||||
|
-n fabcar \
|
||||||
|
-v 1.0 \
|
||||||
|
-p "$CC_SRC_PATH" \
|
||||||
|
-l "$CC_RUNTIME_LANGUAGE"
|
||||||
|
|
||||||
|
echo "Instantiating smart contract on mychannel"
|
||||||
|
docker exec \
|
||||||
|
-e CORE_PEER_LOCALMSPID=Org1MSP \
|
||||||
|
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
|
||||||
|
cli \
|
||||||
|
peer chaincode instantiate \
|
||||||
|
-o orderer.example.com:7050 \
|
||||||
|
-C mychannel \
|
||||||
|
-n fabcar \
|
||||||
|
-l "$CC_RUNTIME_LANGUAGE" \
|
||||||
|
-v 1.0 \
|
||||||
|
-c '{"Args":[]}' \
|
||||||
|
-P "AND('Org1MSP.member','Org2MSP.member')" \
|
||||||
|
--tls \
|
||||||
|
--cafile ${ORDERER_TLS_ROOTCERT_FILE} \
|
||||||
|
--peerAddresses peer0.org1.example.com:7051 \
|
||||||
|
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE}
|
||||||
|
|
||||||
|
echo "Waiting for instantiation request to be committed ..."
|
||||||
sleep 10
|
sleep 10
|
||||||
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[]}'
|
|
||||||
|
echo "Submitting initLedger transaction to smart contract on mychannel"
|
||||||
|
docker exec \
|
||||||
|
-e CORE_PEER_LOCALMSPID=Org1MSP \
|
||||||
|
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
|
||||||
|
cli \
|
||||||
|
peer chaincode invoke \
|
||||||
|
-o orderer.example.com:7050 \
|
||||||
|
-C mychannel \
|
||||||
|
-n fabcar \
|
||||||
|
-c '{"function":"initLedger","Args":[]}' \
|
||||||
|
--waitForEvent \
|
||||||
|
--tls \
|
||||||
|
--cafile ${ORDERER_TLS_ROOTCERT_FILE} \
|
||||||
|
--peerAddresses peer0.org1.example.com:7051 \
|
||||||
|
--peerAddresses peer0.org2.example.com:9051 \
|
||||||
|
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
|
||||||
|
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}
|
||||||
|
set +x
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { FileSystemWallet, X509WalletMixin } from 'fabric-network';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'basic-network', 'connection.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
||||||
const ccp = JSON.parse(ccpJSON);
|
const ccp = JSON.parse(ccpJSON);
|
||||||
|
|
||||||
|
|
@ -15,8 +15,10 @@ async function main() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Create a new CA client for interacting with the CA.
|
// Create a new CA client for interacting with the CA.
|
||||||
const caURL = ccp.certificateAuthorities['ca.example.com'].url;
|
const caInfo = ccp.certificateAuthorities['ca.org1.example.com'];
|
||||||
const ca = new FabricCAServices(caURL);
|
const caTLSCACertsPath = path.resolve(__dirname, '..', '..', '..', 'first-network', caInfo.tlsCACerts.path);
|
||||||
|
const caTLSCACerts = fs.readFileSync(caTLSCACertsPath);
|
||||||
|
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
|
||||||
|
|
||||||
// Create a new file system based wallet for managing identities.
|
// Create a new file system based wallet for managing identities.
|
||||||
const walletPath = path.join(process.cwd(), 'wallet');
|
const walletPath = path.join(process.cwd(), 'wallet');
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FileSystemWallet, Gateway } from 'fabric-network';
|
import { FileSystemWallet, Gateway } from 'fabric-network';
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'basic-network', 'connection.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
|
||||||
const ccp = JSON.parse(ccpJSON);
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -28,7 +25,7 @@ async function main() {
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccp, { wallet, identity: 'user1', discovery: { enabled: false } });
|
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FileSystemWallet, Gateway } from 'fabric-network';
|
import { FileSystemWallet, Gateway } from 'fabric-network';
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'basic-network', 'connection.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
|
||||||
const ccp = JSON.parse(ccpJSON);
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -28,7 +25,7 @@ async function main() {
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccp, { wallet, identity: 'user1', discovery: { enabled: false } });
|
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FileSystemWallet, Gateway, X509WalletMixin } from 'fabric-network';
|
import { FileSystemWallet, Gateway, X509WalletMixin } from 'fabric-network';
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'basic-network', 'connection.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
|
||||||
const ccp = JSON.parse(ccpJSON);
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -35,7 +32,7 @@ async function main() {
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccp, { wallet, identity: 'admin', discovery: { enabled: false } });
|
await gateway.connect(ccpPath, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the CA client object from the gateway for interacting with the CA.
|
// Get the CA client object from the gateway for interacting with the CA.
|
||||||
const ca = gateway.getClient().getCertificateAuthority();
|
const ca = gateway.getClient().getCertificateAuthority();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue