From 89a6d183d19a3dc16ecc76309550f5d65ae6d759 Mon Sep 17 00:00:00 2001 From: Matthew B White Date: Fri, 17 Jan 2020 14:50:24 +0000 Subject: [PATCH] Update Commercial Paper to v2.0 lifecycle - move to using the test-network - updating README.md to include commands to use v2.0 lifecylce - update Contracts and Applications to use 2.0 libraries Signed-off-by: Matthew B White --- .gitignore | 1 + .vscode/settings.json | 10 - chaincode/abstore/java/build.gradle | 2 +- chaincode/fabcar/java/build.gradle | 4 +- ci/commercialpaper-go.yml | 81 ++++++- ci/commercialpaper-java.yml | 79 +++++- ci/commercialpaper-javascript.yml | 72 +++++- commercial-paper/.gitignore | 6 +- commercial-paper/README.md | 179 ++++++++++---- .../digibank/application-java/pom.xml | 2 +- .../digibank/application/addToWallet.js | 8 +- .../organization/digibank/application/buy.js | 7 +- .../digibank/application/package-lock.json | 18 +- .../digibank/application/redeem.js | 8 +- .../configuration/cli/docker-compose.yml | 11 +- .../contract-java/shadow-build.gradle | 2 +- .../magnetocorp/application/addToWallet.js | 12 +- .../magnetocorp/application/issue.js | 7 +- .../magnetocorp/application/package-lock.json | 18 +- .../configuration/cli/docker-compose.yml | 21 +- .../configuration/cli/monitordocker.sh | 2 +- .../executionHistory/executionHistory.lock | Bin 17 -> 0 bytes .../.gradle/5.6.2/fileChanges/last-build.bin | Bin 1 -> 0 bytes .../.gradle/5.6.2/fileHashes/fileHashes.lock | Bin 17 -> 0 bytes .../contract-java/.gradle/5.6.2/gc.properties | 0 .../buildOutputCleanup.lock | Bin 17 -> 0 bytes .../buildOutputCleanup/cache.properties | 2 - .../contract-java/.gradle/vcs-1/gc.properties | 0 .../magnetocorp/contract-java/build.gradle | 2 +- .../gateway/networkConnection.yaml | 129 ---------- .../gateway/papernetConnection.yaml | 225 ------------------ .../organization/magnetocorp/t.js | 1 + commercial-paper/roles/digibank.sh | 36 +-- commercial-paper/roles/magnetocorp.sh | 57 ++--- commercial-paper/roles/network-starter.sh | 10 +- 35 files changed, 442 insertions(+), 570 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/executionHistory/executionHistory.lock delete mode 100644 commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/fileChanges/last-build.bin delete mode 100644 commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/fileHashes/fileHashes.lock delete mode 100644 commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/gc.properties delete mode 100644 commercial-paper/organization/magnetocorp/contract-java/.gradle/buildOutputCleanup/buildOutputCleanup.lock delete mode 100644 commercial-paper/organization/magnetocorp/contract-java/.gradle/buildOutputCleanup/cache.properties delete mode 100644 commercial-paper/organization/magnetocorp/contract-java/.gradle/vcs-1/gc.properties delete mode 100644 commercial-paper/organization/magnetocorp/gateway/networkConnection.yaml delete mode 100644 commercial-paper/organization/magnetocorp/gateway/papernetConnection.yaml create mode 100644 commercial-paper/organization/magnetocorp/t.js diff --git a/.gitignore b/.gitignore index 2973218017..f5fb3121c7 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ .project # omit Go vendor directories vendor/ +.vscode \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e8e412fc82..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "spellright.language": [ - "English (British)" - ], - "spellright.documentTypes": [ - "markdown", - "latex", - "plaintext" - ] -} \ No newline at end of file diff --git a/chaincode/abstore/java/build.gradle b/chaincode/abstore/java/build.gradle index 6a30517a82..02483c751f 100644 --- a/chaincode/abstore/java/build.gradle +++ b/chaincode/abstore/java/build.gradle @@ -25,7 +25,7 @@ repositories { } dependencies { - implementation 'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.0.0-beta.1' + implementation 'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.0.+' } shadowJar { diff --git a/chaincode/fabcar/java/build.gradle b/chaincode/fabcar/java/build.gradle index b65d862206..8ef8f8c764 100644 --- a/chaincode/fabcar/java/build.gradle +++ b/chaincode/fabcar/java/build.gradle @@ -12,9 +12,9 @@ group 'org.hyperledger.fabric.samples' version '1.0-SNAPSHOT' dependencies { - compileOnly 'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.0.0-beta.1' + compileOnly 'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.0.+' implementation 'com.owlike:genson:1.5' - testImplementation 'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.0.0-beta.1' + testImplementation 'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.0.+' testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2' testImplementation 'org.assertj:assertj-core:3.11.1' testImplementation 'org.mockito:mockito-core:2.+' diff --git a/ci/commercialpaper-go.yml b/ci/commercialpaper-go.yml index d12c0ba700..7692408209 100644 --- a/ci/commercialpaper-go.yml +++ b/ci/commercialpaper-go.yml @@ -9,24 +9,83 @@ steps: - script: go test ./... workingDirectory: commercial-paper/organization/digibank/contract-go displayName: Go unit test digibank - - script: bash start.sh - workingDirectory: basic-network + + - script: | + go mod vendor + workingDirectory: commercial-paper/organization/magnetocorp/contract-go + - script: | + go mod vendor + workingDirectory: commercial-paper/organization/digibank/contract-go + + - script: | + echo $PATH + ls -l /usr/local/bin/peer + sudo tar xzvf /tmp/hyperledger-fabric-linux-amd64-latest.tar.gz -C .. + ./network.sh down + ./network.sh up createChannel -s couchdb -i 2.0.0-beta + + # Copy the connection profiles so they are in the correct organizations. + cp "./organizations/peerOrganizations/org1.example.com/connection-org1.yaml" "../commercial-paper/organization/digibank/gateway/" + cp "./organizations/peerOrganizations/org2.example.com/connection-org2.yaml" "../commercial-paper/organization/magnetocorp/gateway/" + workingDirectory: test-network displayName: Start Fabric + env: + FABRIC_CFG_PATH: /usr/local/config - script: | - docker-compose -f docker-compose.yml up -d cliMagnetoCorp + source <(../../roles/magnetocorp.sh) + peer lifecycle chaincode package cp.tar.gz --lang java --path ./contract-java --label cp_0 + peer lifecycle chaincode install cp.tar.gz - docker exec cliMagnetoCorp bash -c 'cd /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-go && go mod vendor' + export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') + echo $PACKAGE_ID - docker exec cliMagnetoCorp peer lifecycle chaincode package cp.tar.gz --lang golang --path github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-go --label cp_0 - docker exec cliMagnetoCorp peer lifecycle chaincode install cp.tar.gz - export PACKAGE_ID=$(docker exec cliMagnetoCorp peer lifecycle chaincode queryinstalled 2>&1 | awk -F "[, ]+" '/Label: /{print $3}') + peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -v 0 \ + --package-id $PACKAGE_ID \ + --sequence 1 \ + --tls \ + --cafile $ORDERER_CA + + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 + workingDirectory: commercial-paper/organization/magnetocorp + displayName: Setup Commercial Paper contract + env: + FABRIC_CFG_PATH: /usr/local/config + - script: | + source <(../../roles/digibank.sh) + peer lifecycle chaincode package cp.tar.gz --lang java --path ./contract-java --label cp_0 + peer lifecycle chaincode install cp.tar.gz + + export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') + echo $PACKAGE_ID - docker exec cliMagnetoCorp peer lifecycle chaincode approveformyorg --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --signature-policy "AND ('Org1MSP.member')" - docker exec cliMagnetoCorp peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name papercontract -v 0 --sequence 1 --waitForEvent --signature-policy "AND ('Org1MSP.member')" - docker exec cliMagnetoCorp peer chaincode invoke -o orderer.example.com:7050 --channelID mychannel --name papercontract -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' --waitForEvent + peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -v 0 \ + --package-id $PACKAGE_ID \ + --sequence 1 \ + --tls \ + --cafile $ORDERER_CA + + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 - workingDirectory: commercial-paper/organization/magnetocorp/configuration/cli + peer lifecycle chaincode commit -o localhost:7050 \ + --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} \ + --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} \ + --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel --name papercontract -v 0 \ + --sequence 1 \ + --tls --cafile $ORDERER_CA --waitForEvent + + workingDirectory: commercial-paper/organization/digibank displayName: Setup Commercial Paper contract + env: + FABRIC_CFG_PATH: /usr/local/config + + - script: retry -- npm install workingDirectory: commercial-paper/organization/magnetocorp/application diff --git a/ci/commercialpaper-java.yml b/ci/commercialpaper-java.yml index f0216321fc..34300f016e 100644 --- a/ci/commercialpaper-java.yml +++ b/ci/commercialpaper-java.yml @@ -3,26 +3,83 @@ # steps: - - script: bash start.sh - workingDirectory: basic-network - displayName: Start Fabric - script: | ./gradlew build workingDirectory: commercial-paper/organization/digibank/contract-java displayName: Build Java Contract - script: | - docker-compose -f docker-compose.yml up -d cliDigiBank + ./gradlew build + workingDirectory: commercial-paper/organization/magnetocorp/contract-java + displayName: Build Java Contract + + - script: | + echo $PATH + ls -l /usr/local/bin/peer + sudo tar xzvf /tmp/hyperledger-fabric-linux-amd64-latest.tar.gz -C .. + ./network.sh down + ./network.sh up createChannel -s couchdb -i 2.0.0-beta + + # Copy the connection profiles so they are in the correct organizations. + cp "./organizations/peerOrganizations/org1.example.com/connection-org1.yaml" "../commercial-paper/organization/digibank/gateway/" + cp "./organizations/peerOrganizations/org2.example.com/connection-org2.yaml" "../commercial-paper/organization/magnetocorp/gateway/" + workingDirectory: test-network + displayName: Start Fabric + env: + FABRIC_CFG_PATH: /usr/local/config + - script: | + source <(../../roles/magnetocorp.sh) + peer lifecycle chaincode package cp.tar.gz --lang java --path ./contract-java --label cp_0 + peer lifecycle chaincode install cp.tar.gz + + export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') + echo $PACKAGE_ID - docker exec cliDigiBank peer lifecycle chaincode package cp.tar.gz --lang java --path /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/digibank/contract-java/build/libs --label cp_0 - docker exec cliDigiBank peer lifecycle chaincode install cp.tar.gz - export PACKAGE_ID=$(docker exec cliDigiBank peer lifecycle chaincode queryinstalled 2>&1 | awk -F "[, ]+" '/Label: /{print $3}') + peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -v 0 \ + --package-id $PACKAGE_ID \ + --sequence 1 \ + --tls \ + --cafile $ORDERER_CA + + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 + workingDirectory: commercial-paper/organization/magnetocorp + displayName: Setup Commercial Paper contract + env: + FABRIC_CFG_PATH: /usr/local/config + - script: | + source <(../../roles/digibank.sh) + peer lifecycle chaincode package cp.tar.gz --lang java --path ./contract-java --label cp_0 + peer lifecycle chaincode install cp.tar.gz - docker exec cliDigiBank peer lifecycle chaincode approveformyorg --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --signature-policy "AND ('Org1MSP.member')" - docker exec cliDigiBank peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name papercontract -v 0 --sequence 1 --waitForEvent --signature-policy "AND ('Org1MSP.member')" - docker exec cliDigiBank peer chaincode invoke -o orderer.example.com:7050 --channelID mychannel --name papercontract -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' --waitForEvent + export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') + echo $PACKAGE_ID - workingDirectory: commercial-paper/organization/digibank/configuration/cli + peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -v 0 \ + --package-id $PACKAGE_ID \ + --sequence 1 \ + --tls \ + --cafile $ORDERER_CA + + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 + + peer lifecycle chaincode commit -o localhost:7050 \ + --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} \ + --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} \ + --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel --name papercontract -v 0 \ + --sequence 1 \ + --tls --cafile $ORDERER_CA --waitForEvent + + workingDirectory: commercial-paper/organization/digibank displayName: Setup Commercial Paper contract + env: + FABRIC_CFG_PATH: /usr/local/config + - script: retry -- npm install workingDirectory: commercial-paper/organization/magnetocorp/application diff --git a/ci/commercialpaper-javascript.yml b/ci/commercialpaper-javascript.yml index 6d712c4c46..2c84a82088 100644 --- a/ci/commercialpaper-javascript.yml +++ b/ci/commercialpaper-javascript.yml @@ -3,23 +3,73 @@ # steps: - - script: bash start.sh - workingDirectory: basic-network - displayName: Start Fabric - script: | - docker-compose -f docker-compose.yml up -d cliMagnetoCorp + echo $PATH + ls -l /usr/local/bin/peer + sudo tar xzvf /tmp/hyperledger-fabric-linux-amd64-latest.tar.gz -C .. + ./network.sh down + ./network.sh up createChannel -s couchdb -i 2.0.0-beta - docker exec cliMagnetoCorp peer lifecycle chaincode package cp.tar.gz --lang node --path /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract --label cp_0 - docker exec cliMagnetoCorp peer lifecycle chaincode install cp.tar.gz - export PACKAGE_ID=$(docker exec cliMagnetoCorp peer lifecycle chaincode queryinstalled 2>&1 | awk -F "[, ]+" '/Label: /{print $3}') + # Copy the connection profiles so they are in the correct organizations. + cp "./organizations/peerOrganizations/org1.example.com/connection-org1.yaml" "../commercial-paper/organization/digibank/gateway/" + cp "./organizations/peerOrganizations/org2.example.com/connection-org2.yaml" "../commercial-paper/organization/magnetocorp/gateway/" + workingDirectory: test-network + displayName: Start Fabric + env: + FABRIC_CFG_PATH: /usr/local/config + - script: | + source <(../../roles/magnetocorp.sh) + peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0 + peer lifecycle chaincode install cp.tar.gz - docker exec cliMagnetoCorp peer lifecycle chaincode approveformyorg --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --signature-policy "AND ('Org1MSP.member')" - docker exec cliMagnetoCorp peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name papercontract -v 0 --sequence 1 --waitForEvent --signature-policy "AND ('Org1MSP.member')" - docker exec cliMagnetoCorp peer chaincode invoke -o orderer.example.com:7050 --channelID mychannel --name papercontract -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' --waitForEvent + export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') + echo $PACKAGE_ID - workingDirectory: commercial-paper/organization/magnetocorp/configuration/cli + peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -v 0 \ + --package-id $PACKAGE_ID \ + --sequence 1 \ + --tls \ + --cafile $ORDERER_CA + + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 + workingDirectory: commercial-paper/organization/magnetocorp displayName: Setup Commercial Paper contract + env: + FABRIC_CFG_PATH: /usr/local/config + - script: | + source <(../../roles/digibank.sh) + peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0 + peer lifecycle chaincode install cp.tar.gz + export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') + echo $PACKAGE_ID + + peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -v 0 \ + --package-id $PACKAGE_ID \ + --sequence 1 \ + --tls \ + --cafile $ORDERER_CA + + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 + + peer lifecycle chaincode commit -o localhost:7050 \ + --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} \ + --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} \ + --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel --name papercontract -v 0 \ + --sequence 1 \ + --tls --cafile $ORDERER_CA --waitForEvent + + workingDirectory: commercial-paper/organization/digibank + displayName: Setup Commercial Paper contract + env: + FABRIC_CFG_PATH: /usr/local/config - script: retry -- npm install workingDirectory: commercial-paper/organization/magnetocorp/application displayName: Install Magnetocorp application diff --git a/commercial-paper/.gitignore b/commercial-paper/.gitignore index fe00636120..c68e967997 100644 --- a/commercial-paper/.gitignore +++ b/commercial-paper/.gitignore @@ -1 +1,5 @@ -cp.tar.gz \ No newline at end of file +cp.tar.gz + +**/.gradle +**/gateway/connection-org1.yaml +**/gateway/connection-org2.yaml \ No newline at end of file diff --git a/commercial-paper/README.md b/commercial-paper/README.md index d415850590..e786225be2 100644 --- a/commercial-paper/README.md +++ b/commercial-paper/README.md @@ -1,11 +1,11 @@ # Commercial Paper Tutorial This folder contains the code for an introductory tutorial to Smart Contract development. It is based around the scenario of Commercial Paper. -The full tutorial, including full scenario details and line by line code walkthroughs is in the [Hyperledger Fabric documentation](https://hyperledger-fabric.readthedocs.io/en/latest/tutorial/commercial_paper.html). +The full tutorial, including full scenario details and line by line code walk-through is in the [Hyperledger Fabric Commercial Paper Tutorial](https://hyperledger-fabric.readthedocs.io/en/latest/tutorial/commercial_paper.html). ## Scenario -In this tutorial two organizations, MagnetoCorp and DigiBank, trade commercial paper with each other using PaperNet, a Hyperledger Fabric blockchain network. +In this tutorial two organizations, MagnetoCorp and DigiBank, trade commercial paper with each other using 'PaperNet', a Hyperledger Fabric blockchain network. Once you’ve set up a basic network, you’ll act as Isabella, an employee of MagnetoCorp, who will issue a commercial paper on its behalf. You’ll then switch hats to take the role of Balaji, an employee of DigiBank, who will buy this commercial paper, hold it for a period of time, and then redeem it with MagnetoCorp for a small profit. @@ -13,7 +13,7 @@ Once you’ve set up a basic network, you’ll act as Isabella, an employee of M ## Quick Start -You are strongly advised to read the full tutorial to get information about the code and the scenario. Below are the quick start instructions for running the tutorial, but no details on the how or why it works. +You are strongly advised to read the full tutorial to get information about the code and the scenario. Below are the quick start instructions for running the tutorial, but without extensive details of what is happening. ### Steps @@ -25,9 +25,9 @@ You are strongly advised to read the full tutorial to get information about the 3) Run client applications in the roles of MagnetoCorp and DigiBank to trade the commercial paper - - Issue the Paper as Magnetocorp - - Buy the paper as DigiBank - - Redeem the paper as DigiBank + - Issue the Paper as Magnetocorp (org2) + - Buy the paper as DigiBank (org1) + - Redeem the paper as DigiBank (org1) ## Setup @@ -40,73 +40,169 @@ You will need a machine with the following It is advised to have 3 console windows open; one to monitor the infrastructure and one each for MagnetoCorp and DigiBank -If you haven't already clone the repository to a directory of your choice, and change to the `commercial-paper` directory +You will need to install the peer cli binaries and this fabric-samples repository available. For more information +[Install the Samples, Binaries and Docker Images](https://hyperledger-fabric.readthedocs.io/en/latest/install.html) in the Hyperledger Fabric documentation shows how to do this. + +To specify the configuration location ensure FABRIC_CFG_PATH is set to the location of the config files. The usual place is the `fabric-samples/config` directory. +``` +export FABRIC_CFG_PATH=$(pwd)/config +``` + +Once you've cloned the fabric-samples - change to the commercial-paper directory. ``` -git clone https://github.com/hyperledger/fabric-samples.git cd fabric-samples/commercial-paper ``` This `README.md` file is in the `commercial-paper` directory, the source code for client applications and the contracts ins in the `organization` directory, and some helper scripts are in the `roles` directory. + ## Running the Infrastructure In one console window, run the `./roles/network-starter.sh` script; this will start the basic infrastructure and also start monitoring all the docker containers. -You can cancel this if you wish to reuse the terminal, but it's best left open. +You can cancel this if you wish to reuse the terminal, but it's best left open so you can see what is occurring. + +### Setup the organizations environments + +The contract code is available as either JavaScript, Java or Go. You can use either one, and the choice of contract language does not affect the choice of client language. With the v2.0 life-cycle, this requires operations for both MagentoCorp and Digibank admin + +In your 'MagnetoCorp' window run the following commands, to set-up the shell environment variables to act as that organization. + +``` +source <(./roles/magnetocorp.sh) +cd organizations/magentocorp +``` + +Similarly in your 'DigiBank' window run the following command -### Install and Instantiate the contract +``` +source <(./roles/digibank.sh) +cd organizations/digibank +``` -The contract code is available as either JavaScript or Java. You can use either one, and the choice of contract language does not affect the choice of client language. +### Package and Install Contracts -In your 'MagnetoCorp' window run the following command +You need to perform similar operations for both organizations. For different contract langauges the steps are very similar. The steps for JavaScript +are shown first, with the details of different languages afterwards. -`./roles/magnetocorp.sh` -This will start a docker container for Fabric CLI commands, and put you in the correct directory for the source code. +**For a JavaScript Contract** -**For a JavaScript Contract:** +Running in MagnetoCorp: ``` -docker exec cliMagnetoCorp peer lifecycle chaincode package cp.tar.gz --lang node --path /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract --label cp_0 -docker exec cliMagnetoCorp peer lifecycle chaincode install cp.tar.gz -export PACKAGE_ID=$(docker exec cliMagnetoCorp peer lifecycle chaincode queryinstalled 2>&1 | awk -F "[, ]+" '/Label: /{print $3}') +# MAGENTOCORP + +peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0 +peer lifecycle chaincode install cp.tar.gz + +export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') +echo $PACKAGE_ID + +peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -v 0 \ + --package-id $PACKAGE_ID \ + --sequence 1 \ + --tls \ + --cafile $ORDERER_CA + +peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 +``` -docker exec cliMagnetoCorp peer lifecycle chaincode approveformyorg --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --signature-policy "AND ('Org1MSP.member')" -docker exec cliMagnetoCorp peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name papercontract -v 0 --sequence 1 --waitForEvent --signature-policy "AND ('Org1MSP.member')" -docker exec cliMagnetoCorp peer chaincode invoke -o orderer.example.com:7050 --channelID mychannel --name papercontract -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' --waitForEvent +Running in Digibank ``` -**For a Java Contract:** +# DIGIBANK + +peer lifecycle chaincode package cp.tar.gz --lang node --path /opt/gopath/src/github.com/contract --label cp_0 +peer lifecycle chaincode install cp.tar.gz + +export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') +echo $PACKAGE_ID + +peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -v 0 \ + --package-id $PACKAGE_ID \ + --sequence 1 \ + --tls \ + --cafile $ORDERER_CA + +peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 ``` -pushd ./organization/magnetocorp/contract-java -./gradlew installDist +Once both organizations have installed, and approved the chaincode, it can be committed. -popd +``` +# MAGNETOCORP -docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-java/build/install/papercontract -l java +peer lifecycle chaincode commit -o localhost:7050 \ + --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} \ + --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} \ + --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel --name papercontract -v 0 \ + --sequence 1 \ + --tls --cafile $ORDERER_CA --waitForEvent -docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l java -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')" ``` -> If you want to try both a Java and JavaScript Contract, then you will need to restart the infrastructure and deploy the other contract. +To test try sending some simple transactions. -**For a Go Contract:** ``` -docker exec cliMagnetoCorp bash -c 'cd /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-go && go mod vendor' -docker exec cliMagnetoCorp peer lifecycle chaincode package cp.tar.gz --lang golang --path github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-go --label cp_0 -docker exec cliMagnetoCorp peer lifecycle chaincode install cp.tar.gz -export PACKAGE_ID=$(docker exec cliMagnetoCorp peer lifecycle chaincode queryinstalled 2>&1 | awk -F "[, ]+" '/Label: /{print $3}') +peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} \ + --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} \ + --channelID mychannel --name papercontract \ + -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' ${PEER_ADDRESS_ORG1} ${PEER_ADDRESS_ORG2} \ + --tls --cafile $ORDERER_CA --waitForEvent + +peer chaincode query -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ + --channelID mychannel \ + --name papercontract \ + -c '{"Args":["org.hyperledger.fabric:GetMetadata"]}' \ + --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} \ + --tls --cafile $ORDERER_CA | jq -C | more +``` -docker exec cliMagnetoCorp peer lifecycle chaincode approveformyorg --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --signature-policy "AND ('Org1MSP.member')" -docker exec cliMagnetoCorp peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name papercontract -v 0 --sequence 1 --waitForEvent --signature-policy "AND ('Org1MSP.member')" -docker exec cliMagnetoCorp peer chaincode invoke -o orderer.example.com:7050 --channelID mychannel --name papercontract -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' --waitForEvent +**For a Java Contract:** + +Before the `peer lifecycle chaincode package` command, you will need to change into each organization's `contract-java` directory and issues + +``` +./gradlew build +``` + +Then when you package the contract, use this variation of the command to specify language +``` +peer lifecycle chaincode package cp.tar.gz --lang java --path /opt/gopath/src/github.com/contract-java --label cp_0 ``` +After this point the steps are exactly the same as for JavaScript + +**For a Go Contract:** + + +Before the `peer lifecycle chaincode package` command, you will need to change into each organization's `contract-go` directory and issues + +``` +go mod vendor +``` + +Then when you package the contract, use this variation of the command to specify language +``` +peer lifecycle chaincode package cp.tar.gz --lang golang --path /opt/gopath/src/github.com/contract-go --label cp_0 +``` + +After this point the steps are exactly the same as for JavaScript + + ## Client Applications Note for Java applications you will need to compile the Java Code using maven. Use this command in each application-java directory @@ -120,13 +216,13 @@ Note for JavaScript applications you will need to install the dependencies first ``` npm install ``` - - > Note that there is NO dependency between the language of any one client application and any contract. Mix and match as you wish! +The docker containers don't contain the node or Java runtimes; so it is best to exit the docker containers - but keep the windows open and run the applications locally. + ### Issue the paper -This is running as *MagnetoCorp* so you can stay in the same window. These commands are to be run in the +This is running as *MagnetoCorp* These commands are to be run in the `commercial-paper/organization/magnetocorp/application` directory or the `commercial-paper/organization/magnetocorp/application-java` *Add the Identity to be used* @@ -147,10 +243,7 @@ java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.magnetocorp.Issue ### Buy and Redeem the paper -This is running as *Digibank*; you've not acted as this organization before so in your 'Digibank' window run the following command in the -`fabric-samples/commercial-paper/` directory - -`./roles/digibank.sh` +This is running as *Digibank*; You can now run the applications to buy and redeem the paper. Change to either the `commercial-paper/organization/digibank/application` directory or `commercial-paper/organization/digibank/application-java` diff --git a/commercial-paper/organization/digibank/application-java/pom.xml b/commercial-paper/organization/digibank/application-java/pom.xml index 0a58cee7bb..23373e0750 100644 --- a/commercial-paper/organization/digibank/application-java/pom.xml +++ b/commercial-paper/organization/digibank/application-java/pom.xml @@ -14,7 +14,7 @@ UTF-8 - 2.0.0-beta.1 + [2.0.0,2.1) diff --git a/commercial-paper/organization/digibank/application/addToWallet.js b/commercial-paper/organization/digibank/application/addToWallet.js index ca7857c2e6..0829a3dad4 100644 --- a/commercial-paper/organization/digibank/application/addToWallet.js +++ b/commercial-paper/organization/digibank/application/addToWallet.js @@ -9,7 +9,7 @@ const fs = require('fs'); const { Wallets } = require('fabric-network'); const path = require('path'); -const fixtures = path.resolve(__dirname, '../../../../basic-network'); +const fixtures = path.resolve(__dirname, '../../../../test-network'); async function main() { @@ -20,12 +20,12 @@ async function main() { const wallet = await Wallets.newFileSystemWallet('../identity/user/balaji/wallet'); // Identity to credentials to be stored in the wallet - const credPath = path.join(fixtures, '/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com'); + const credPath = path.join(fixtures, '/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com'); const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/Admin@org1.example.com-cert.pem')).toString(); - const privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/5ba12183ab07014ba831f9a79cf51fe7e6f62cdebe6193f070445243aedddee9_sk')).toString(); + const privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/priv_sk')).toString(); // Load credentials into wallet - const identityLabel = 'Admin@org1.example.com'; + const identityLabel = 'balaji'; const identity = { credentials: { diff --git a/commercial-paper/organization/digibank/application/buy.js b/commercial-paper/organization/digibank/application/buy.js index e2af7d9665..7908f1582d 100644 --- a/commercial-paper/organization/digibank/application/buy.js +++ b/commercial-paper/organization/digibank/application/buy.js @@ -35,17 +35,16 @@ async function main () { try { // Specify userName for network access - // const userName = 'isabella.issuer@magnetocorp.com'; - const userName = 'Admin@org1.example.com'; + const userName = 'balaji'; // Load connection profile; will be used to locate a gateway - let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/networkConnection.yaml', 'utf8')); + let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org1.yaml', 'utf8')); // Set connection options; identity and wallet let connectionOptions = { identity: userName, wallet: wallet, - discovery: { enabled: false, asLocalhost: true } + discovery: { enabled: true, asLocalhost: true } }; diff --git a/commercial-paper/organization/digibank/application/package-lock.json b/commercial-paper/organization/digibank/application/package-lock.json index c8063236c8..984dfef7b1 100644 --- a/commercial-paper/organization/digibank/application/package-lock.json +++ b/commercial-paper/organization/digibank/application/package-lock.json @@ -39,14 +39,14 @@ "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==" }, "@types/long": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.0.tgz", - "integrity": "sha512-1w52Nyx4Gq47uuu0EVcsHBxZFJgurQ+rTKS3qMHxR1GY2T8c2AJYd6vZoZ9q1rupaDjU0yT+Jc2XTyXkjeMA+Q==" + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.1.tgz", + "integrity": "sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==" }, "@types/node": { - "version": "13.1.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.7.tgz", - "integrity": "sha512-HU0q9GXazqiKwviVxg9SI/+t/nAsGkvLDkIdxz+ObejG2nX6Si00TeLqHMoS+a/1tjH7a8YpKVQwtgHuMQsldg==" + "version": "13.5.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.5.0.tgz", + "integrity": "sha512-Onhn+z72D2O2Pb2ql2xukJ55rglumsVo1H6Fmyi8mlU9SvKdBk/pUSUAiBY/d9bAOF7VVWajX3sths/+g6ZiAQ==" }, "@types/request": { "version": "2.48.4", @@ -2337,9 +2337,9 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "uuid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", - "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==" + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" }, "verror": { "version": "1.10.0", diff --git a/commercial-paper/organization/digibank/application/redeem.js b/commercial-paper/organization/digibank/application/redeem.js index 2697de65da..98e46af377 100644 --- a/commercial-paper/organization/digibank/application/redeem.js +++ b/commercial-paper/organization/digibank/application/redeem.js @@ -35,17 +35,17 @@ async function main() { try { // Specify userName for network access - // const userName = 'isabella.issuer@magnetocorp.com'; - const userName = 'Admin@org1.example.com'; + // Specify userName for network access + const userName = 'balaji'; // Load connection profile; will be used to locate a gateway - let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/networkConnection.yaml', 'utf8')); + let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org1.yaml', 'utf8')); // Set connection options; identity and wallet let connectionOptions = { identity: userName, wallet: wallet, - discovery: { enabled:false, asLocalhost: true } + discovery: { enabled:true, asLocalhost: true } }; // Connect to gateway using application specified parameters diff --git a/commercial-paper/organization/digibank/configuration/cli/docker-compose.yml b/commercial-paper/organization/digibank/configuration/cli/docker-compose.yml index 88b9bd83de..d7c9092882 100644 --- a/commercial-paper/organization/digibank/configuration/cli/docker-compose.yml +++ b/commercial-paper/organization/digibank/configuration/cli/docker-compose.yml @@ -8,12 +8,12 @@ version: '2' networks: basic: external: - name: net_basic + name: net_test services: cliDigiBank: container_name: cliDigiBank - image: hyperledger/fabric-tools + image: hyperledger/fabric-tools:2.0.0-beta tty: true environment: - GOPATH=/opt/gopath @@ -24,12 +24,15 @@ services: - CORE_PEER_LOCALMSPID=Org1MSP - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp - CORE_CHAINCODE_KEEPALIVE=10 + - CORE_PEER_TLS_ENABLED=true + - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt + - ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: /bin/bash volumes: - /var/run/:/host/var/run/ - - ./../../../../organization/digibank:/opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/digibank - - ./../../../../../basic-network/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ + - ./../../../../organization/digibank:/opt/gopath/src/github.com/ + - ./../../../../../test-network/organizations:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ networks: - basic diff --git a/commercial-paper/organization/digibank/contract-java/shadow-build.gradle b/commercial-paper/organization/digibank/contract-java/shadow-build.gradle index 24ba2199ad..f683babbc3 100644 --- a/commercial-paper/organization/digibank/contract-java/shadow-build.gradle +++ b/commercial-paper/organization/digibank/contract-java/shadow-build.gradle @@ -20,7 +20,7 @@ repositories { } dependencies { - implementation group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '2.0.0-beta.1' + implementation group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '2.0.+' implementation group: 'org.json', name: 'json', version: '20180813' testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2' testImplementation 'org.assertj:assertj-core:3.11.1' diff --git a/commercial-paper/organization/magnetocorp/application/addToWallet.js b/commercial-paper/organization/magnetocorp/application/addToWallet.js index 97a0344e19..9de29e68a2 100644 --- a/commercial-paper/organization/magnetocorp/application/addToWallet.js +++ b/commercial-paper/organization/magnetocorp/application/addToWallet.js @@ -9,7 +9,7 @@ const fs = require('fs'); const { Wallets } = require('fabric-network'); const path = require('path'); -const fixtures = path.resolve(__dirname, '../../../../basic-network'); +const fixtures = path.resolve(__dirname, '../../../../test-network'); async function main() { @@ -19,19 +19,19 @@ async function main() { const wallet = await Wallets.newFileSystemWallet('../identity/user/isabella/wallet'); // Identity to credentials to be stored in the wallet - const credPath = path.join(fixtures, '/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com'); - const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/User1@org1.example.com-cert.pem')).toString(); - const privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/740efb1655d71c3984062726b31361c151463b13979271b86e41d5a3dc3594de_sk')).toString(); + const credPath = path.join(fixtures, '/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com'); + const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/User1@org2.example.com-cert.pem')).toString(); + const privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/priv_sk')).toString(); // Load credentials into wallet - const identityLabel = 'User1@org1.example.com'; + const identityLabel = 'isabella'; const identity = { credentials: { certificate, privateKey }, - mspId: 'Org1MSP', + mspId: 'Org2MSP', type: 'X.509' } diff --git a/commercial-paper/organization/magnetocorp/application/issue.js b/commercial-paper/organization/magnetocorp/application/issue.js index 738783f213..04db65eab6 100644 --- a/commercial-paper/organization/magnetocorp/application/issue.js +++ b/commercial-paper/organization/magnetocorp/application/issue.js @@ -24,7 +24,6 @@ const CommercialPaper = require('../contract/lib/paper.js'); async function main() { // A wallet stores a collection of identities for use - //const wallet = new FileSystemWallet('../user/isabella/wallet'); const wallet = await Wallets.newFileSystemWallet('../identity/user/isabella/wallet'); // A gateway defines the peers used to access Fabric networks @@ -35,16 +34,16 @@ async function main() { // Specify userName for network access // const userName = 'isabella.issuer@magnetocorp.com'; - const userName = 'User1@org1.example.com'; + const userName = 'isabella'; // Load connection profile; will be used to locate a gateway - let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/networkConnection.yaml', 'utf8')); + let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org2.yaml', 'utf8')); // Set connection options; identity and wallet let connectionOptions = { identity: userName, wallet: wallet, - discovery: { enabled:false, asLocalhost: true } + discovery: { enabled:true, asLocalhost: true } }; // Connect to gateway using application specified parameters diff --git a/commercial-paper/organization/magnetocorp/application/package-lock.json b/commercial-paper/organization/magnetocorp/application/package-lock.json index 388553bee7..4325de96ac 100644 --- a/commercial-paper/organization/magnetocorp/application/package-lock.json +++ b/commercial-paper/organization/magnetocorp/application/package-lock.json @@ -39,14 +39,14 @@ "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==" }, "@types/long": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.0.tgz", - "integrity": "sha512-1w52Nyx4Gq47uuu0EVcsHBxZFJgurQ+rTKS3qMHxR1GY2T8c2AJYd6vZoZ9q1rupaDjU0yT+Jc2XTyXkjeMA+Q==" + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.1.tgz", + "integrity": "sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==" }, "@types/node": { - "version": "13.1.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.7.tgz", - "integrity": "sha512-HU0q9GXazqiKwviVxg9SI/+t/nAsGkvLDkIdxz+ObejG2nX6Si00TeLqHMoS+a/1tjH7a8YpKVQwtgHuMQsldg==" + "version": "13.5.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.5.0.tgz", + "integrity": "sha512-Onhn+z72D2O2Pb2ql2xukJ55rglumsVo1H6Fmyi8mlU9SvKdBk/pUSUAiBY/d9bAOF7VVWajX3sths/+g6ZiAQ==" }, "@types/request": { "version": "2.48.4", @@ -2337,9 +2337,9 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "uuid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", - "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==" + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" }, "verror": { "version": "1.10.0", diff --git a/commercial-paper/organization/magnetocorp/configuration/cli/docker-compose.yml b/commercial-paper/organization/magnetocorp/configuration/cli/docker-compose.yml index 53e514a50c..cc14e5f1d6 100644 --- a/commercial-paper/organization/magnetocorp/configuration/cli/docker-compose.yml +++ b/commercial-paper/organization/magnetocorp/configuration/cli/docker-compose.yml @@ -8,31 +8,30 @@ version: '2' networks: basic: external: - name: net_basic + name: net_test services: cliMagnetoCorp: container_name: cliMagnetoCorp - image: hyperledger/fabric-tools + image: hyperledger/fabric-tools:2.0.0-beta tty: true environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - FABRIC_LOGGING_SPEC=info - CORE_PEER_ID=cli - - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - - CORE_PEER_LOCALMSPID=Org1MSP - - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp + - CORE_PEER_ADDRESS=peer0.org2.example.com:9051 + - CORE_PEER_LOCALMSPID=Org2MSP + - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp - CORE_CHAINCODE_KEEPALIVE=10 + - CORE_PEER_TLS_ENABLED=true + - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt + - ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: /bin/bash volumes: - /var/run/:/host/var/run/ - - ./../../../../organization/magnetocorp:/opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp - - ./../../../../../basic-network/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ + - ./../../../../organization/magnetocorp:/opt/gopath/src/github.com/ + - ./../../../../../test-network/organizations:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ networks: - basic - #depends_on: - # - orderer.example.com - # - peer0.org1.example.com - # - couchdb diff --git a/commercial-paper/organization/magnetocorp/configuration/cli/monitordocker.sh b/commercial-paper/organization/magnetocorp/configuration/cli/monitordocker.sh index 2cf82fbd67..cd388b28a5 100755 --- a/commercial-paper/organization/magnetocorp/configuration/cli/monitordocker.sh +++ b/commercial-paper/organization/magnetocorp/configuration/cli/monitordocker.sh @@ -6,7 +6,7 @@ # More information at https://github.com/gliderlabs/logspout/tree/master/httpstream if [ -z "$1" ]; then - DOCKER_NETWORK=basicnetwork_basic + DOCKER_NETWORK=net_test else DOCKER_NETWORK="$1" fi diff --git a/commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/executionHistory/executionHistory.lock b/commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/executionHistory/executionHistory.lock deleted file mode 100644 index e2c28744b04bb49338c073145eff52378623ab96..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17 ScmZQJdzWu@jn&zM0SW*q{{uGw diff --git a/commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/fileChanges/last-build.bin b/commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/fileChanges/last-build.bin deleted file mode 100644 index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1 IcmZPo000310RR91 diff --git a/commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/fileHashes/fileHashes.lock b/commercial-paper/organization/magnetocorp/contract-java/.gradle/5.6.2/fileHashes/fileHashes.lock deleted file mode 100644 index c8db6aeff99b98f6f109fe9e5d51273a2a825610..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17 TcmZQx-mz)s{8u*L7@z - To buy the paper : node buy.js - To redeem the paper : node redeem.js +# alternative +cd "${DIR}/../test-network" +env | sort > /tmp/env.orig - Java Client Applications: +. ./scripts/envVar.sh - (remember to build the Java first with 'mvn clean package') +ORG="1" +setGlobals $ORG - < issue the paper run as Magnetocorp> - To buy the paper : node buy.js - To redeem the paper : node redeem.js +env | sort | comm -1 -3 /tmp/env.orig - | sed -E 's/(.*)=(.*)/export \1="\2"/' -" -echo "Suggest that you change to this dir> cd ${DIR}/organization/digibank" \ No newline at end of file +rm /tmp/env.orig \ No newline at end of file diff --git a/commercial-paper/roles/magnetocorp.sh b/commercial-paper/roles/magnetocorp.sh index 0b735d0cbe..13e2cd361f 100755 --- a/commercial-paper/roles/magnetocorp.sh +++ b/commercial-paper/roles/magnetocorp.sh @@ -1,55 +1,36 @@ #!/bin/bash # # SPDX-License-Identifier: Apache-2.0 +shopt -s extglob function _exit(){ printf "Exiting:%s\n" "$1" exit -1 } -# Where am I? -# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" - -# cd "${DIR}/organization/magnetocorp/configuration/cli" -# docker-compose -f docker-compose.yml up -d cliMagnetoCorp - -echo " - Install and Instantiate a Smart Contract in either langauge - - JavaScript Contract: - - docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract -l node - docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l node -c '{\"Args\":[\"org.papernet.commercialpaper:instantiate\"]}' -C mychannel -P \"AND ('Org1MSP.member')\" - Java Contract: +: ${CHANNEL_NAME:="mychannel"} +: ${DELAY:="3"} +: ${MAX_RETRY:="5"} +: ${VERBOSE:="false"} - docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-java -l java - docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l java -c '{\"Args\":[\"org.papernet.commercialpaper:instantiate\"]}' -C mychannel -P \"AND ('Org1MSP.member')\" - - Go Contract: - docker exec cliMagnetoCorp bash -c 'cd /opt/gopath/src/github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-go && go mod vendor' - - docker exec cliMagnetoCorp peer lifecycle chaincode package cp.tar.gz --lang golang --path github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-go --label cp_0 - docker exec cliMagnetoCorp peer lifecycle chaincode install cp.tar.gz - export PACKAGE_ID=\$(docker exec cliMagnetoCorp peer lifecycle chaincode queryinstalled 2>&1 | awk -F \"[, ]+\" '/Label: /{print \$3}') - - docker exec cliMagnetoCorp peer lifecycle chaincode approveformyorg --channelID mychannel --name papercontract -v 0 --package-id \$PACKAGE_ID --sequence 1 --signature-policy \"AND ('Org1MSP.member')\" - docker exec cliMagnetoCorp peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name papercontract -v 0 --sequence 1 --waitForEvent --signature-policy \"AND ('Org1MSP.member')\" - docker exec cliMagnetoCorp peer chaincode invoke -o orderer.example.com:7050 --channelID mychannel --name papercontract -c '{\"Args\":[\"org.papernet.commercialpaper:instantiate\"]}' --waitForEvent - - Run Applications in either langauage (can be different from the Smart Contract) +# Where am I? +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" - JavaScript Client Aplications: - To add identity to the wallet: node addToWallet.js - To issue the paper : node issue.js +# alternative +cd "${DIR}/../test-network" +env | sort > /tmp/env.orig - Java Client Applications: +. ./scripts/envVar.sh - (remember to build the Java first with 'mvn') +ORG="2" +parsePeerConnectionParameters 1 2 +export PEER_PARMS="${PEER_CONN_PARMS##*( )}" - To add identity to the wallet: java addToWallet - To issue the paper : java issue -" +env | sort | comm -1 -3 /tmp/env.orig - | sed -E 's/(.*)=(.*)/export \1="\2"/' +rm /tmp/env.orig -echo "Suggest that you change to this dir> cd ${DIR}/organization/magnetocorp/" +#cd "${DIR}/organization/magnetocorp/configuration/cli" +#docker-compose -f docker-compose.yml up -d cliMagnetoCorp +#docker exec -it cliMagnetoCorp bash diff --git a/commercial-paper/roles/network-starter.sh b/commercial-paper/roles/network-starter.sh index 56db94d7f3..e62639a728 100755 --- a/commercial-paper/roles/network-starter.sh +++ b/commercial-paper/roles/network-starter.sh @@ -17,12 +17,14 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" cd "${DIR}/../test-network/" docker kill cliDigiBank cliMagnetoCorp logspout || true -./network.sh up createChannel -s couchdb - - +./network.sh down +./network.sh up createChannel -s couchdb -i 2.0.0-beta +# Copy the connection profiles so they are in the correct organizations. +cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml" "${DIR}/organization/digibank/gateway/" +cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/connection-org2.yaml" "${DIR}/organization/magnetocorp/gateway/" # ------------------------------------------------------------------------------- # # Good to start the applications in other terminals # -"${DIR}/organization/magnetocorp/configuration/cli/monitordocker.sh" net_basic +"${DIR}/organization/magnetocorp/configuration/cli/monitordocker.sh" net_test