-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-16147] Update Commercial Paper to work with v2 (#98)
Update the applications and scripts to use the new v2 SDKs and the new lifecycle Add in a basic script based on the readme.md that does a basic run of the scenario Signed-off-by: Matthew B White <[email protected]>
- Loading branch information
Showing
35 changed files
with
669 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
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 | ||
docker exec cliDigiBank peer lifecycle chaincode package cp.tar.gz --lang java --path /opt/gopath/src/github.com/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}') | ||
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 | ||
workingDirectory: commercial-paper/organization/digibank/configuration/cli | ||
displayName: Setup Commercial Paper contract | ||
- script: retry -- npm install | ||
workingDirectory: commercial-paper/organization/magnetocorp/application | ||
displayName: Install Magnetocorp application | ||
- script: | | ||
set -ex | ||
node addToWallet.js | ||
node issue.js | ||
workingDirectory: commercial-paper/organization/magnetocorp/application | ||
displayName: Magnetocorp issue paper | ||
- script: retry -- npm install | ||
workingDirectory: commercial-paper/organization/digibank/application | ||
displayName: Install Digibank application | ||
- script: | | ||
set -ex | ||
node addToWallet.js | ||
node buy.js | ||
node redeem.js | ||
workingDirectory: commercial-paper/organization/digibank/application | ||
displayName: Digibank issue paper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
steps: | ||
- script: bash start.sh | ||
workingDirectory: basic-network | ||
displayName: Start Fabric | ||
- script: | | ||
docker-compose -f docker-compose.yml up -d cliMagnetoCorp | ||
docker exec cliMagnetoCorp peer lifecycle chaincode package cp.tar.gz --lang node --path /opt/gopath/src/github.com/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}') | ||
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 | ||
workingDirectory: commercial-paper/organization/magnetocorp/configuration/cli | ||
displayName: Setup Commercial Paper contract | ||
- script: retry -- npm install | ||
workingDirectory: commercial-paper/organization/magnetocorp/application | ||
displayName: Install Magnetocorp application | ||
- script: | | ||
set -ex | ||
node addToWallet.js | ||
node issue.js | ||
workingDirectory: commercial-paper/organization/magnetocorp/application | ||
displayName: Magnetocorp issue paper | ||
- script: retry -- npm install | ||
workingDirectory: commercial-paper/organization/digibank/application | ||
displayName: Install Digibank application | ||
- script: | | ||
set -ex | ||
node addToWallet.js | ||
node buy.js | ||
node redeem.js | ||
workingDirectory: commercial-paper/organization/digibank/application | ||
displayName: Digibank issue paper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash -e | ||
set -o pipefail | ||
|
||
echo "======== PULL DOCKER IMAGES ========" | ||
########################################################## | ||
REPO_URL=hyperledger-fabric.jfrog.io | ||
ORG_NAME="fabric" | ||
|
||
VERSION=2.0.0 | ||
ARCH="amd64" | ||
: ${STABLE_VERSION:=$VERSION-stable} | ||
STABLE_TAG=$ARCH-$STABLE_VERSION | ||
MASTER_TAG=$ARCH-stable | ||
|
||
echo "---------> STABLE_VERSION:" $STABLE_VERSION | ||
|
||
dockerTag() { | ||
for IMAGES in baseos peer orderer ca tools orderer ccenv javaenv nodeenv; do | ||
echo "Images: $IMAGES" | ||
echo | ||
docker pull $REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG | ||
if [ $? != 0 ]; then | ||
echo "FAILED: Docker Pull Failed on $IMAGES" | ||
exit 1 | ||
fi | ||
docker tag $REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG hyperledger/$ORG_NAME-$IMAGES | ||
docker tag $REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG hyperledger/$ORG_NAME-$IMAGES:latest | ||
docker tag $REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG hyperledger/$ORG_NAME-$IMAGES:$ARCH-$VERSION-stable | ||
docker tag $REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG hyperledger/$ORG_NAME-$IMAGES:$ARCH-stable | ||
docker tag $REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG hyperledger/$ORG_NAME-$IMAGES:$VERSION | ||
|
||
echo "Deleting docker images: $IMAGES" | ||
docker rmi -f $REPO_URL/$ORG_NAME-$IMAGES:$STABLE_TAG | ||
done | ||
} | ||
|
||
dockerTag | ||
|
||
echo | ||
docker images | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cp.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -ex | ||
|
||
function _exit(){ | ||
printf "Exiting:%s\n" "$1" | ||
exit -1 | ||
} | ||
|
||
# Where am I? | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" | ||
|
||
## Use this to remove anything existing on the basic network before starting | ||
# docker kill $(docker network inspect net_basic --format '{{json .Containers}}' | jq -r 'keys[]') && docker rm $(docker ps -aq) | ||
|
||
## Start the Fabric Network | ||
cd "${DIR}/basic-network" | ||
. ./start.sh | ||
|
||
docker ps | ||
|
||
## Run as MagnetoCorp | ||
# cd "${DIR}/commercial-paper/organization/magnetocorp/configuration/cli" | ||
# docker-compose -f docker-compose.yml up -d cliMagnetoCorp | ||
|
||
# docker exec cliMagnetoCorp peer lifecycle chaincode package cp.tar.gz --lang node --path /opt/gopath/src/github.com/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}') | ||
|
||
# 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 | ||
|
||
|
||
cd "${DIR}/commercial-paper/organization/digibank/configuration/cli" | ||
docker-compose -f docker-compose.yml up -d cliDigiBank | ||
CLI_CONTAINER=cliDigiBank | ||
docker exec ${CLI_CONTAINER} peer lifecycle chaincode package cp.tar.gz --lang java --path /opt/gopath/src/github.com/contract-java/build/libs --label cp_0 | ||
docker exec ${CLI_CONTAINER} peer lifecycle chaincode install cp.tar.gz | ||
export PACKAGE_ID=$(docker exec ${CLI_CONTAINER} peer lifecycle chaincode queryinstalled 2>&1 | awk -F "[, ]+" '/Label: /{print $3}') | ||
|
||
docker exec ${CLI_CONTAINER} peer lifecycle chaincode approveformyorg --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --signature-policy "AND ('Org1MSP.member')" | ||
docker exec ${CLI_CONTAINER} 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 ${CLI_CONTAINER} peer chaincode invoke -o orderer.example.com:7050 --channelID mychannel --name papercontract -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' --waitForEvent | ||
|
||
|
||
|
||
cd "${DIR}/commercial-paper/organization/magnetocorp/application" | ||
npm install | ||
node addToWallet.js | ||
node issue.js | ||
|
||
cd "${DIR}/commercial-paper/organization/digibank/application" | ||
npm install | ||
node addToWallet.js | ||
node buy.js | ||
node redeem.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,29 +6,37 @@ | |
|
||
// Bring key classes into scope, most importantly Fabric SDK network class | ||
const fs = require('fs'); | ||
const { FileSystemWallet, X509WalletMixin } = require('fabric-network'); | ||
const { Wallets } = require('fabric-network'); | ||
const path = require('path'); | ||
|
||
const fixtures = path.resolve(__dirname, '../../../../basic-network'); | ||
|
||
// A wallet stores a collection of identities | ||
const wallet = new FileSystemWallet('../identity/user/balaji/wallet'); | ||
|
||
async function main() { | ||
|
||
// Main try/catch block | ||
try { | ||
|
||
// A wallet stores a collection of identities | ||
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/[email protected]'); | ||
const cert = fs.readFileSync(path.join(credPath, '/msp/signcerts/[email protected]')).toString(); | ||
const key = fs.readFileSync(path.join(credPath, '/msp/keystore/cd96d5260ad4757551ed4a5a991e62130f8008a0bf996e4e4b84cd097a747fec_sk')).toString(); | ||
const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/[email protected]')).toString(); | ||
const privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/5ba12183ab07014ba831f9a79cf51fe7e6f62cdebe6193f070445243aedddee9_sk')).toString(); | ||
|
||
// Load credentials into wallet | ||
const identityLabel = '[email protected]'; | ||
const identity = X509WalletMixin.createIdentity('Org1MSP', cert, key); | ||
|
||
await wallet.import(identityLabel, identity); | ||
|
||
const identity = { | ||
credentials: { | ||
certificate, | ||
privateKey | ||
}, | ||
mspId: 'Org1MSP', | ||
type: 'X.509' | ||
} | ||
|
||
await wallet.put(identityLabel, identity); | ||
|
||
} catch (error) { | ||
console.log(`Error adding to wallet. ${error}`); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.