forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doc Fixes (hyperledger-archives#3364)
Add new tutorials to the tutorial list Update the banner Signed-off-by: Caroline Church <[email protected]>
- Loading branch information
Showing
4 changed files
with
38 additions
and
45 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
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ sidebar: sidebars/accordion-toc0.md | |
# Invoking a {{site.data.conrefs.composer_full}} business network from another business network | ||
{{site.data.conrefs.composer_full}} includes functionality that can be used by a business network to access an asset, participant, or transaction that is recorded in another business network. | ||
|
||
This tutorial will demonstrate the steps that a business network developer needs to take in order to invoke a {{site.data.conrefs.composer_full}} business network from a different business network. As part of the tutorial you will deploy the same business network twice. The business networks can be on the same channel or different channels. The business network used in this example will be the tutorial network that is outlined in the [developer tutorial](./developer-tutorial.html). This tutorial will refer to the business networks as "A" and "B" | ||
This tutorial will demonstrate the steps that a business network developer needs to take in order to invoke a {{site.data.conrefs.composer_full}} business network from a different business network. As part of the tutorial you will deploy the same business network twice. The business networks in this tutorial will be on the same channel, but they can be on different channels. The business network used in this example will be the tutorial network that is outlined in the [developer tutorial](./developer-tutorial.html). This tutorial will refer to the business networks as "A" and "B" | ||
|
||
## Prerequisites | ||
|
||
|
@@ -43,27 +43,14 @@ If these commands fail, then you have business network cards from a previous ver | |
|
||
./createPeerAdminCard.sh | ||
|
||
## Step Two: Create a second channel (Optional) | ||
## Step Two: Define the business networks | ||
1. Follow steps one and two in the [developer tutorial](./developer-tutorial.html). This will be network A. | ||
|
||
The simple network config used in the previous step only creates one channel by default. If business network B is to be deployed to a different channel, then the channel should be created now by using the Hyperledger Fabric operational tools. | ||
2. Follow steps one and two again but create a business network called `other-tutorial-network`. This will be network B. | ||
|
||
After the channel has been created a business network card needs to be created to deploy to this channel. | ||
|
||
1. Create a connection profile that specifies the second channel | ||
|
||
2. To create the business network card run the following commands. | ||
|
||
export PRIVATE_KEY=~/fabric-tools/composer/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457_sk | ||
export CERT=~/fabric-tools/composer/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected] | ||
composer card create -p <Path to profile> -u PeerAdmin -c ${CERT} -k ${PRIVATE_KEY} -r PeerAdmin -r ChannelAdmin --file [email protected] | ||
composer card import -f [email protected] -n otherPeerAdmin@hlfv1 | ||
|
||
## Step Three: Define the business networks | ||
1. Follow steps one and two in the [developer tutorial](./developer-tutorial.html). If business network A and business network B are being deployed to the same channel then a second business network will need to be created with a different name but with the same model, script and ACL files. This tutorial will assume this will be called `other-tutorial-network`. | ||
|
||
2. The transaction logic needs to be updated to query an asset in business network B and then update the quantity property of an asset in business network A. | ||
3. The transaction logic needs to be updated in network A and to query an asset in business network B and then update the quantity property of an asset in business network A. | ||
|
||
Replace the contents of the `logic.js` script file to update the transaction processor function to be the following. Where \<CHANNEL\> needs to be replaced with either the name of the channel created in step two, or `composerchannel` if the business networks are on the same channel; and where \<BUSINESS NEWORK NAME\> is either `tutorial-network` if the networks are on different channels, or `other-tutorial-network` if the network are on the same channel. | ||
Replace the contents of the `logic.js` script file to update the transaction processor function to be the following. | ||
|
||
/** | ||
* Track the trade of a commodity from one trader to another | ||
|
@@ -73,7 +60,7 @@ After the channel has been created a business network card needs to be created t | |
async function tradeCommodity(trade) { | ||
trade.commodity.owner = trade.newOwner; | ||
|
||
const otherNetworkData = await getNativeAPI().invokeChaincode(<BUSINESS NETWORK NAME>, ['getResourceInRegistry', 'Asset', 'org.acme.biznet.Commodity', trade.commodity.tradingSymbol], <CHANNEL>); | ||
const otherNetworkData = await getNativeAPI().invokeChaincode('other-tutorial-network', ['getResourceInRegistry', 'Asset', 'org.acme.biznet.Commodity', trade.commodity.tradingSymbol], 'composerchannel'); | ||
const stringAsset = new Buffer(otherNetworkData.payload.toArrayBuffer()).toString('utf8'); | ||
const asset = getSerializer().fromJSON(JSON.parse(stringAsset)); | ||
|
||
|
@@ -83,26 +70,16 @@ After the channel has been created a business network card needs to be created t | |
await assetRegistry.update(trade.commodity); | ||
} | ||
|
||
3. Follow step three in the [developer tutorial](./developer-tutorial.html). | ||
|
||
4. If business network B is going to be deployed on the same channel as business network A, then repeat steps 1-3 but create a network call `other-tutorial-network`. | ||
4. Follow step three in the [developer tutorial](./developer-tutorial.html). | ||
|
||
## Step Four: Deploy the business networks | ||
## Step Three: Deploy the business networks | ||
1. Install and start business network A using the following commands | ||
|
||
composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName tutorial-network | ||
composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile [email protected] --file networkA.card | ||
composer card import --file networkA.card --name networkA | ||
2. Install and start business network B using the following commands | ||
|
||
If business network B will be on a different channel: | ||
|
||
composer runtime install --card otherPeerAdmin@hlfv1 --businessNetworkName tutorial-network | ||
composer network start --card otherPeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile [email protected] --file networkB.card | ||
composer card import --file networkB.card --name networkB | ||
|
||
If business network B will be on the same channel: | ||
2. Install and start business network B using the following commands | ||
|
||
composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName other-tutorial-network | ||
composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile [email protected] --file networkB.card | ||
|
@@ -113,7 +90,7 @@ After the channel has been created a business network card needs to be created t | |
composer network ping --card networkA | ||
composer network ping --card networkB | ||
|
||
## Step Five: Create the assets | ||
## Step Four: Create the assets | ||
|
||
1. Create a participant in business network A. Run the following command. | ||
|
||
|
@@ -131,20 +108,20 @@ After the channel has been created a business network card needs to be created t | |
|
||
composer transaction submit --card networkB -d '{"$class": "org.hyperledger.composer.system.AddAsset","registryType": "Asset","registryId": "org.acme.biznet.Commodity", "targetRegistry" : "resource:org.hyperledger.composer.system.AssetRegistry#org.acme.biznet.Commodity", "resources": [{"$class": "org.acme.biznet.Commodity","tradingSymbol": "Ag","owner": "resource:org.acme.biznet.Trader#[email protected]","description": "a lot of gold", "mainExchange": "exchange", "quantity" : 500}]}' | ||
## Step Six: Bind the identity on network A to the participant on network B | ||
## Step Five: Bind the identity on network A to the participant on network B | ||
1. Export the networkA card to get the credentials | ||
|
||
composer card export -n networkA | ||
|
||
2. Unzip the card | ||
2. Unzip the card, you may need to rename networkA.card to networkA.zip. | ||
|
||
3. Bind the identity to the participant. Run the following command. | ||
|
||
composer identity bind --card networkB --participantId resource:org.hyperledger.composer.system.NetworkAdmin#admin --certificateFile ./networkA/credentials/certificate | ||
|
||
4. Create a card with the bound identity. Where \<PATH TO CONNECTION PROFILE FOR NETWORK B\> should be the one to connect to networkB and \<NAME OF BUSINESS NETWORK B\> should be the name of business network B | ||
4. Create a card with the bound identity. | ||
|
||
composer card create -p \<PATH TO CONNECTION PROFILE FOR NETWORK B\> --businessNetworkName <NAME OF BUSINESS NETWORK B> -u admin -c ./networkA/credentials/certificate -k ./networkA/credentials/privateKey -f newNetworkB.card | ||
composer card create -p ~/.composer/cards/networkB/connection.json --businessNetworkName other-tutorial-network -u admin -c ./networkA/credentials/certificate -k ./networkA/credentials/privateKey -f newNetworkB.card | ||
|
||
5. Import the card | ||
|
||
|
@@ -153,6 +130,12 @@ After the channel has been created a business network card needs to be created t | |
6. Ping the network to activate the identity | ||
|
||
composer network ping --card newNetworkB | ||
## Step Six: Review the asset data | ||
|
||
View the asset to see that the quantity is 250. | ||
|
||
composer network list --card networkA -r org.acme.biznet.Commodity -a Ag | ||
|
||
## Step Seven: Submit a transaction | ||
|
||
|
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