mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-19 08:15:08 +00:00
[FAB-15199] Update interest rate sample
Update interest rate sample for chaincode lifecycle Change-Id: I8e481dda11a757d5fe76105098307141a67dff60 Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com>
This commit is contained in:
parent
f0dca20446
commit
7c5f5d39c9
5 changed files with 457 additions and 63 deletions
|
|
@ -110,19 +110,23 @@ and run a swap transaction flow from creation to settlement.
|
|||
### Prerequisites
|
||||
|
||||
The following prerequisites are needed to run this sample:
|
||||
* You need to run this sample from your GOPATH. If you have downloaded the
|
||||
`fabric-samples` directory outside your GOPATH, then you need to copy or
|
||||
move the interest rate sample into your GOPATH.
|
||||
* Fabric docker images. By default the `network/network.sh` script will look for
|
||||
fabric images with the `latest` tag, this can be adapted with the `-i` command
|
||||
line parameter of the script.
|
||||
* A local installation of `configtxgen` and `cryptogen` in the `PATH` environment,
|
||||
or included in `fabric-samples/bin` directory.
|
||||
* Vendoring the chaincode. In the chaincode directory, run `govendor init` and
|
||||
* Vendoring the chaincode. In the `chaincode` directory, run `govendor init` and
|
||||
`govendor add +external` to vendor the shim from your local copy of fabric.
|
||||
|
||||
### Bringing up the network
|
||||
|
||||
Simply run `network.sh up` to bring up the network. This will spawn docker
|
||||
containers running a network of 3 "regular" organizations, one auditor
|
||||
organization and one reference rate provider as well as a solo orderer.
|
||||
Navigate to the `network` folder. Run the command `./network.sh up` to bring up
|
||||
the network. This will spawn docker containers running a network of 3 "regular"
|
||||
organizations, one auditor organization and one reference rate provider as well
|
||||
as a solo orderer.
|
||||
|
||||
An additional CLI container will run `network/scripts/script.sh` to join the
|
||||
peers to the `irs` channel and deploy the chaincode. In the init parameters it
|
||||
|
|
@ -134,26 +138,27 @@ commands in the following section.
|
|||
|
||||
### Transactions
|
||||
|
||||
The chaincode is instantiated as follows:
|
||||
The chaincode is initialized as follows:
|
||||
```
|
||||
peer chaincode instantiate -o irs-orderer:7050 -C irs -n irscc -l golang -v 0 -c '{"Args":["init","auditor","100000","rrprovider","myrr"]}' -P "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')"
|
||||
peer chaincode invoke -o irs-orderer:7050 --isInit -C irs --waitForEvent -n irscc --peerAddresses irs-rrprovider:7051 --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-partyc:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["init","auditor","1000000","rrprovider","myrr"]}'
|
||||
```
|
||||
|
||||
This sets an auditing threshold of 1M, above which the `auditor` organization
|
||||
needs to be involved. It also specifies the `myrr` reference rate provided by
|
||||
the `rrprovider` organization.
|
||||
|
||||
To set a reference rate:
|
||||
```
|
||||
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-rrprovider:7051 -c '{"Args":["setReferenceRate","myrr","3"]}'
|
||||
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-rrprovider:7051 -c '{"Args":["setReferenceRate","myrr","300"]}'
|
||||
```
|
||||
Note that the transaction is endorsed by a peer of the organization we have
|
||||
specified as providing this reference rate in the init parameters.
|
||||
|
||||
To create a swap named "myswap":
|
||||
```
|
||||
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["createSwap","myswap","{\"StartDate\":\"2018-09-27T15:04:05Z\",\"EndDate\":\"2018-09-30T15:04:05Z\",\"PaymentInterval\":365,\"PrincipalAmount\":10000000,\"FixedRate\":4,\"FloatingRate\":5,\"ReferenceRate\":\"myrr\"}", "partya", "partyb"]}'
|
||||
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["createSwap","myswap","{\"StartDate\":\"2018-09-27T15:04:05Z\",\"EndDate\":\"2018-09-30T15:04:05Z\",\"PaymentInterval\":395,\"PrincipalAmount\":100000,\"FixedRate\":400,\"FloatingRate\":500,\"ReferenceRate\":\"myrr\"}", "partya", "partyb"]}'
|
||||
```
|
||||
Note that the transaction is endorsed by both parties that are part of this
|
||||
Note that the transaction is endorsed by both parties that are part of this
|
||||
swap as well as the auditor. Since the principal amount in this case is lower
|
||||
than the audit threshold we set as init parameters, no auditor will be required
|
||||
to endorse changes to the payment info or swap details.
|
||||
|
|
@ -173,4 +178,13 @@ peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc `--peer
|
|||
As an exercise, try to create a new swap above the auditing threshold and see
|
||||
how validation fails if the auditor is not involved in every operation on the
|
||||
swap. Also try to calculate payment info before settling a prior payment to a
|
||||
swap.
|
||||
swap. You can run the commands yourself using the CLI container by issuing the
|
||||
command ``docker exec -it cli bash``. You will need to set the corresponding
|
||||
environment variables for the organization issuing the command. You refer to the
|
||||
`network/scripts/script.sh` file for more information.
|
||||
|
||||
## Clean up
|
||||
|
||||
When you are finished using the network, you can bring down the docker images
|
||||
and remove any artifacts by running the command `./network.sh down` from the
|
||||
`network` folder.
|
||||
|
|
|
|||
|
|
@ -3,27 +3,57 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
---
|
||||
################################################################################
|
||||
#
|
||||
# Section: Organizations
|
||||
#
|
||||
# - This section defines the different organizational identities which will
|
||||
# be referenced later in the configuration.
|
||||
#
|
||||
################################################################################
|
||||
Organizations:
|
||||
|
||||
# SampleOrg defines an MSP using the sampleconfig. It should never be used
|
||||
# in production but may be used as a template for other definitions
|
||||
- &orderer
|
||||
# DefaultOrg defines the organization which is used in the sampleconfig
|
||||
# of the fabric.git development environment
|
||||
Name: orderer
|
||||
|
||||
# ID to load the MSP definition as
|
||||
ID: orderer
|
||||
|
||||
# MSPDir is the filesystem path which contains the MSP configuration
|
||||
MSPDir: crypto-config/ordererOrganizations/example.com/msp
|
||||
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For organization policies, their canonical path is usually
|
||||
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
|
||||
Policies:
|
||||
Readers:
|
||||
Type: Signature
|
||||
Rule: OR('orderer.member')
|
||||
Rule: "OR('orderer.member')"
|
||||
Writers:
|
||||
Type: Signature
|
||||
Rule: OR('orderer.member')
|
||||
Rule: "OR('orderer.member')"
|
||||
Admins:
|
||||
Type: Signature
|
||||
Rule: OR('orderer.admin')
|
||||
|
||||
Rule: "OR('orderer.admin')"
|
||||
|
||||
- &partya
|
||||
# DefaultOrg defines the organization which is used in the sampleconfig
|
||||
# of the fabric.git development environment
|
||||
Name: partya
|
||||
|
||||
# ID to load the MSP definition as
|
||||
ID: partya
|
||||
|
||||
MSPDir: crypto-config/peerOrganizations/partya.example.com/msp
|
||||
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For organization policies, their canonical path is usually
|
||||
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
|
||||
Policies:
|
||||
Readers:
|
||||
Type: Signature
|
||||
|
|
@ -34,14 +64,31 @@ Organizations:
|
|||
Admins:
|
||||
Type: Signature
|
||||
Rule: OR('partya.admin')
|
||||
Endorsement:
|
||||
Type: Signature
|
||||
Rule: "OR('partya.peer')"
|
||||
|
||||
# leave this flag set to true.
|
||||
AnchorPeers:
|
||||
# AnchorPeers defines the location of peers which can be used
|
||||
# for cross org gossip communication. Note, this value is only
|
||||
# encoded in the genesis block in the Application section context
|
||||
- Host: irs-partya
|
||||
Port: 7051
|
||||
|
||||
- &partyb
|
||||
# DefaultOrg defines the organization which is used in the sampleconfig
|
||||
# of the fabric.git development environment
|
||||
Name: partyb
|
||||
|
||||
# ID to load the MSP definition as
|
||||
ID: partyb
|
||||
|
||||
MSPDir: crypto-config/peerOrganizations/partyb.example.com/msp
|
||||
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For organization policies, their canonical path is usually
|
||||
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
|
||||
Policies:
|
||||
Readers:
|
||||
Type: Signature
|
||||
|
|
@ -52,32 +99,67 @@ Organizations:
|
|||
Admins:
|
||||
Type: Signature
|
||||
Rule: OR('partyb.admin')
|
||||
Endorsement:
|
||||
Type: Signature
|
||||
Rule: "OR('partyb.peer')"
|
||||
|
||||
# leave this flag set to true.
|
||||
AnchorPeers:
|
||||
# AnchorPeers defines the location of peers which can be used
|
||||
# for cross org gossip communication. Note, this value is only
|
||||
# encoded in the genesis block in the Application section context
|
||||
- Host: irs-partyb
|
||||
Port: 7051
|
||||
|
||||
- &partyc
|
||||
# DefaultOrg defines the organization which is used in the sampleconfig
|
||||
# of the fabric.git development environment
|
||||
Name: partyc
|
||||
|
||||
# ID to load the MSP definition as
|
||||
ID: partyc
|
||||
|
||||
MSPDir: crypto-config/peerOrganizations/partyc.example.com/msp
|
||||
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For organization policies, their canonical path is usually
|
||||
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
|
||||
Policies:
|
||||
Readers:
|
||||
Type: Signature
|
||||
Rule: OR('partyc.admin', 'partyc.peer', 'partyc.client')
|
||||
Rule: "OR('partyc.admin', 'partyc.peer', 'partyc.client')"
|
||||
Writers:
|
||||
Type: Signature
|
||||
Rule: OR('partyc.admin', 'partyc.client')
|
||||
Rule: "OR('partyc.admin', 'partyc.client')"
|
||||
Admins:
|
||||
Type: Signature
|
||||
Rule: OR('partyc.admin')
|
||||
Rule: "OR('partyc.admin')"
|
||||
Endorsement:
|
||||
Type: Signature
|
||||
Rule: "OR('partyc.peer')"
|
||||
|
||||
# leave this flag set to true.
|
||||
AnchorPeers:
|
||||
# AnchorPeers defines the location of peers which can be used
|
||||
# for cross org gossip communication. Note, this value is only
|
||||
# encoded in the genesis block in the Application section context
|
||||
- Host: irs-partyc
|
||||
Port: 7051
|
||||
|
||||
|
||||
- &auditor
|
||||
# DefaultOrg defines the organization which is used in the sampleconfig
|
||||
# of the fabric.git development environment
|
||||
Name: auditor
|
||||
|
||||
# ID to load the MSP definition as
|
||||
ID: auditor
|
||||
|
||||
MSPDir: crypto-config/peerOrganizations/auditor.example.com/msp
|
||||
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For organization policies, their canonical path is usually
|
||||
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
|
||||
Policies:
|
||||
Readers:
|
||||
Type: Signature
|
||||
|
|
@ -88,90 +170,267 @@ Organizations:
|
|||
Admins:
|
||||
Type: Signature
|
||||
Rule: OR('auditor.admin')
|
||||
Endorsement:
|
||||
Type: Signature
|
||||
Rule: "OR('auditor.peer')"
|
||||
|
||||
# leave this flag set to true.
|
||||
AnchorPeers:
|
||||
# AnchorPeers defines the location of peers which can be used
|
||||
# for cross org gossip communication. Note, this value is only
|
||||
# encoded in the genesis block in the Application section context
|
||||
- Host: irs-auditor
|
||||
Port: 7051
|
||||
|
||||
- &rrprovider
|
||||
# DefaultOrg defines the organization which is used in the sampleconfig
|
||||
# of the fabric.git development environment
|
||||
Name: rrprovider
|
||||
|
||||
# ID to load the MSP definition as
|
||||
ID: rrprovider
|
||||
|
||||
MSPDir: crypto-config/peerOrganizations/rrprovider.example.com/msp
|
||||
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For organization policies, their canonical path is usually
|
||||
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
|
||||
Policies:
|
||||
Readers:
|
||||
Type: Signature
|
||||
Rule: OR('rrprovider.admin', 'rrprovider.peer', 'rrprovider.client')
|
||||
Rule: "OR('rrprovider.admin', 'rrprovider.peer', 'rrprovider.client')"
|
||||
Writers:
|
||||
Type: Signature
|
||||
Rule: OR('rrprovider.admin', 'rrprovider.client')
|
||||
Rule: "OR('rrprovider.admin', 'rrprovider.client')"
|
||||
Admins:
|
||||
Type: Signature
|
||||
Rule: OR('rrprovider.admin')
|
||||
Rule: "OR('rrprovider.admin')"
|
||||
Endorsement:
|
||||
Type: Signature
|
||||
Rule: "OR('rrprovider.peer')"
|
||||
|
||||
# leave this flag set to true.
|
||||
AnchorPeers:
|
||||
# AnchorPeers defines the location of peers which can be used
|
||||
# for cross org gossip communication. Note, this value is only
|
||||
# encoded in the genesis block in the Application section context
|
||||
- Host: irs-rrprovider
|
||||
Port: 7051
|
||||
|
||||
Channel: &ChannelDefaults
|
||||
Capabilities:
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# SECTION: Capabilities
|
||||
#
|
||||
# - This section defines the capabilities of fabric network. This is a new
|
||||
# concept as of v1.1.0 and should not be utilized in mixed networks with
|
||||
# v1.0.x peers and orderers. Capabilities define features which must be
|
||||
# present in a fabric binary for that binary to safely participate in the
|
||||
# fabric network. For instance, if a new MSP type is added, newer binaries
|
||||
# might recognize and validate the signatures from this type, while older
|
||||
# binaries without this support would be unable to validate those
|
||||
# transactions. This could lead to different versions of the fabric binaries
|
||||
# having different world states. Instead, defining a capability for a channel
|
||||
# informs those binaries without this capability that they must cease
|
||||
# processing transactions until they have been upgraded. For v1.0.x if any
|
||||
# capabilities are defined (including a map with all capabilities turned off)
|
||||
# then the v1.0.x peer will deliberately crash.
|
||||
#
|
||||
################################################################################
|
||||
Capabilities:
|
||||
# Channel capabilities apply to both the orderers and the peers and must be
|
||||
# supported by both.
|
||||
# Set the value of the capability to true to require it.
|
||||
Channel: &ChannelCapabilities
|
||||
# V1.3 for Channel is a catchall flag for behavior which has been
|
||||
# determined to be desired for all orderers and peers running at the v1.3.x
|
||||
# level, but which would be incompatible with orderers and peers from
|
||||
# prior releases.
|
||||
# Prior to enabling V1.3 channel capabilities, ensure that all
|
||||
# orderers and peers on a channel are at v1.3.0 or later.
|
||||
V1_3: true
|
||||
|
||||
# Orderer capabilities apply only to the orderers, and may be safely
|
||||
# used with prior release peers.
|
||||
# Set the value of the capability to true to require it.
|
||||
Orderer: &OrdererCapabilities
|
||||
# V1.1 for Orderer is a catchall flag for behavior which has been
|
||||
# determined to be desired for all orderers running at the v1.1.x
|
||||
# level, but which would be incompatible with orderers from prior releases.
|
||||
# Prior to enabling V1.1 orderer capabilities, ensure that all
|
||||
# orderers on a channel are at v1.1.0 or later.
|
||||
V1_1: true
|
||||
|
||||
# Application capabilities apply only to the peer network, and may be safely
|
||||
# used with prior release orderers.
|
||||
# Set the value of the capability to true to require it.
|
||||
Application: &ApplicationCapabilities
|
||||
# V2.0 for Application enables the new non-backwards compatible
|
||||
# features and fixes of fabric v2.0.
|
||||
V2_0: true
|
||||
# V1.3 for Application enables the new non-backwards compatible
|
||||
# features and fixes of fabric v1.3 (note, this need not be set if
|
||||
# later version capabilities are set)
|
||||
V1_3: false
|
||||
# V1.2 for Application enables the new non-backwards compatible
|
||||
# features and fixes of fabric v1.2 (note, this need not be set if
|
||||
# later version capabilities are set)
|
||||
V1_2: false
|
||||
# V1.1 for Application enables the new non-backwards compatible
|
||||
# features and fixes of fabric v1.1 (note, this need not be set if
|
||||
# later version capabilities are set).
|
||||
V1_1: false
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# SECTION: Application
|
||||
#
|
||||
# - This section defines the values to encode into a config transaction or
|
||||
# genesis block for application related parameters
|
||||
#
|
||||
################################################################################
|
||||
Application: &ApplicationDefaults
|
||||
|
||||
# Organizations is the list of orgs which are defined as participants on
|
||||
# the application side of the network
|
||||
Organizations:
|
||||
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For Application policies, their canonical path is
|
||||
# /Channel/Application/<PolicyName>
|
||||
Policies:
|
||||
Readers:
|
||||
Type: ImplicitMeta
|
||||
Rule: ANY Readers
|
||||
Rule: "ANY Readers"
|
||||
Writers:
|
||||
Type: ImplicitMeta
|
||||
Rule: ANY Writers
|
||||
Rule: "ANY Writers"
|
||||
Admins:
|
||||
Type: ImplicitMeta
|
||||
Rule: MAJORITY Admins
|
||||
Rule: "MAJORITY Admins"
|
||||
LifecycleEndorsement:
|
||||
Type: ImplicitMeta
|
||||
Rule: "MAJORITY Endorsement"
|
||||
Endorsement:
|
||||
Type: ImplicitMeta
|
||||
Rule: "MAJORITY Endorsement"
|
||||
|
||||
Orderer: &OrdererDefaults
|
||||
OrdererType: solo
|
||||
Capabilities:
|
||||
V1_1: true
|
||||
<<: *ApplicationCapabilities
|
||||
################################################################################
|
||||
#
|
||||
# SECTION: Orderer
|
||||
#
|
||||
# - This section defines the values to encode into a config transaction or
|
||||
# genesis block for orderer related parameters
|
||||
#
|
||||
################################################################################
|
||||
Orderer: &OrdererDefaults
|
||||
|
||||
# Orderer Type: The orderer implementation to start
|
||||
# Available types are "solo" and "kafka"
|
||||
OrdererType: solo
|
||||
|
||||
Addresses:
|
||||
- irs-orderer:7050
|
||||
|
||||
# Batch Timeout: The amount of time to wait before creating a batch
|
||||
BatchTimeout: 2s
|
||||
|
||||
# Batch Size: Controls the number of messages batched into a block
|
||||
BatchSize:
|
||||
|
||||
# Max Message Count: The maximum number of messages to permit in a batch
|
||||
MaxMessageCount: 10
|
||||
|
||||
# Absolute Max Bytes: The absolute maximum number of bytes allowed for
|
||||
# the serialized messages in a batch.
|
||||
AbsoluteMaxBytes: 99 MB
|
||||
|
||||
# Preferred Max Bytes: The preferred maximum number of bytes allowed for
|
||||
# the serialized messages in a batch. A message larger than the preferred
|
||||
# max bytes will result in a batch larger than preferred max bytes.
|
||||
PreferredMaxBytes: 512 KB
|
||||
|
||||
Kafka:
|
||||
# Brokers: A list of Kafka brokers to which the orderer connects
|
||||
# NOTE: Use IP:port notation
|
||||
Brokers:
|
||||
- 127.0.0.1:9092
|
||||
|
||||
# Organizations is the list of orgs which are defined as participants on
|
||||
# the orderer side of the network
|
||||
Organizations:
|
||||
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For Orderer policies, their canonical path is
|
||||
# /Channel/Orderer/<PolicyName>
|
||||
Policies:
|
||||
Readers:
|
||||
Type: ImplicitMeta
|
||||
Rule: ANY Readers
|
||||
Type: ImplicitMeta
|
||||
Rule: "ANY Readers"
|
||||
Writers:
|
||||
Type: ImplicitMeta
|
||||
Rule: ANY Writers
|
||||
Type: ImplicitMeta
|
||||
Rule: "ANY Writers"
|
||||
Admins:
|
||||
Type: ImplicitMeta
|
||||
Rule: MAJORITY Admins
|
||||
Type: ImplicitMeta
|
||||
Rule: "MAJORITY Admins"
|
||||
# BlockValidation specifies what signatures must be included in the block
|
||||
# from the orderer for the peer to validate it.
|
||||
BlockValidation:
|
||||
Type: ImplicitMeta
|
||||
Rule: ANY Writers
|
||||
Organizations:
|
||||
Rule: "ANY Writers"
|
||||
|
||||
Application: &ApplicationDefaults
|
||||
Capabilities:
|
||||
V1_3: true
|
||||
################################################################################
|
||||
#
|
||||
# CHANNEL
|
||||
#
|
||||
# This section defines the values to encode into a config transaction or
|
||||
# genesis block for channel related parameters.
|
||||
#
|
||||
################################################################################
|
||||
Channel: &ChannelDefaults
|
||||
# Policies defines the set of policies at this level of the config tree
|
||||
# For Channel policies, their canonical path is
|
||||
# /Channel/<PolicyName>
|
||||
Policies:
|
||||
# Who may invoke the 'Deliver' API
|
||||
Readers:
|
||||
Type: ImplicitMeta
|
||||
Rule: ANY Readers
|
||||
Type: ImplicitMeta
|
||||
Rule: "ANY Readers"
|
||||
# Who may invoke the 'Broadcast' API
|
||||
Writers:
|
||||
Type: ImplicitMeta
|
||||
Rule: ANY Writers
|
||||
Type: ImplicitMeta
|
||||
Rule: "ANY Writers"
|
||||
# By default, who may modify elements at this config level
|
||||
Admins:
|
||||
Type: ImplicitMeta
|
||||
Rule: MAJORITY Admins
|
||||
Organizations:
|
||||
Type: ImplicitMeta
|
||||
Rule: "MAJORITY Admins"
|
||||
|
||||
# Capabilities describes the channel level capabilities, see the
|
||||
# dedicated Capabilities section elsewhere in this file for a full
|
||||
# description
|
||||
Capabilities:
|
||||
<<: *ChannelCapabilities
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Profile
|
||||
#
|
||||
# - Different configuration profiles may be encoded here to be specified
|
||||
# as parameters to the configtxgen tool
|
||||
#
|
||||
################################################################################
|
||||
Profiles:
|
||||
|
||||
IRSNetGenesis:
|
||||
<<: *ChannelDefaults
|
||||
Orderer:
|
||||
<<: *OrdererDefaults
|
||||
Organizations:
|
||||
- *orderer
|
||||
Capabilities:
|
||||
<<: *OrdererCapabilities
|
||||
Consortiums:
|
||||
SampleConsortium:
|
||||
Organizations:
|
||||
|
|
@ -182,11 +441,21 @@ Profiles:
|
|||
- *auditor
|
||||
IRSChannel:
|
||||
Consortium: SampleConsortium
|
||||
<<: *ChannelDefaults
|
||||
Application:
|
||||
<<: *ApplicationDefaults
|
||||
Organizations:
|
||||
- *partya
|
||||
- *partyb
|
||||
- *partyc
|
||||
- *rrprovider
|
||||
- *auditor
|
||||
- *partya
|
||||
- *partyb
|
||||
- *partyc
|
||||
- *rrprovider
|
||||
- *auditor
|
||||
Capabilities:
|
||||
<<: *ApplicationCapabilities
|
||||
|
||||
|
||||
|
||||
# Copyright IBM Corp. All Rights Reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ function generateChannelArtifacts() {
|
|||
|
||||
echo "######### Generating Orderer Genesis block ##############"
|
||||
mkdir channel-artifacts
|
||||
configtxgen -profile IRSNetGenesis -outputBlock ./channel-artifacts/genesis.block
|
||||
configtxgen -profile IRSNetGenesis -outputBlock ./channel-artifacts/genesis.block -channelID system-channel
|
||||
res=$?
|
||||
if [ $res -ne 0 ]; then
|
||||
echo "Failed to generate orderer genesis block..."
|
||||
|
|
|
|||
38
interest_rate_swaps/network/scripts/query-status.sh
Normal file
38
interest_rate_swaps/network/scripts/query-status.sh
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Copyright IBM Corp All Rights Reserved
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
queryStatus() {
|
||||
echo "===================== Querying approval status for ${CORE_PEER_LOCALMSPID} ===================== "
|
||||
local rc=1
|
||||
local starttime=$(date +%s)
|
||||
|
||||
# continue to poll
|
||||
# we either get a successful response, or reach TIMEOUT
|
||||
while
|
||||
test "$(($(date +%s) - starttime))" -lt "$TIMEOUT" -a $rc -ne 0
|
||||
do
|
||||
echo "Attempting to Query approval status for ${CORE_PEER_LOCALMSPID} ...$(($(date +%s) - starttime)) secs"
|
||||
set -x
|
||||
peer lifecycle chaincode queryapprovalstatus -o irs-orderer:7050 --channelID irs --signature-policy "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')" --name irscc --version 1 --init-required --sequence 1 >&log.txt
|
||||
res=$?
|
||||
set +x
|
||||
test $res -eq 0 || continue
|
||||
let rc=0
|
||||
for var in "$@"
|
||||
do
|
||||
grep "$var" log.txt &>/dev/null || let rc=1
|
||||
done
|
||||
done
|
||||
echo
|
||||
cat log.txt
|
||||
if test $rc -eq 0; then
|
||||
echo "===================== Query approval status successful for ${CORE_PEER_LOCALMSPID} ===================== "
|
||||
else
|
||||
echo "!!!!!!!!!!!!!!! Query approval status result for ${CORE_PEER_LOCALMSPID} !!!!!!!!!!!!!!!!"
|
||||
echo "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
@ -29,6 +29,15 @@ joinChannel () {
|
|||
done
|
||||
}
|
||||
|
||||
packageChaincode() {
|
||||
CORE_PEER_LOCALMSPID=partya
|
||||
CORE_PEER_ADDRESS=irs-partya:7051
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/partya.example.com/users/Admin@partya.example.com/msp
|
||||
echo "===================== Creating chaincode package ===================== "
|
||||
peer lifecycle chaincode package irscc.tar.gz --path ${CC_SRC_PATH} --lang golang --label irscc_1
|
||||
echo "===================== Chaincode packaged ===================== "
|
||||
}
|
||||
|
||||
installChaincode() {
|
||||
for org in partya partyb partyc auditor rrprovider
|
||||
do
|
||||
|
|
@ -36,18 +45,60 @@ installChaincode() {
|
|||
CORE_PEER_ADDRESS=irs-$org:7051
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/$org.example.com/users/Admin@$org.example.com/msp
|
||||
echo "===================== Org $org installing chaincode ===================== "
|
||||
peer chaincode install -n irscc -v 0 -l golang -p ${CC_SRC_PATH}
|
||||
peer lifecycle chaincode install irscc.tar.gz
|
||||
echo "===================== Org $org chaincode installed ===================== "
|
||||
done
|
||||
}
|
||||
|
||||
instantiateChaincode() {
|
||||
queryPackage() {
|
||||
CORE_PEER_LOCALMSPID=partya
|
||||
CORE_PEER_ADDRESS=irs-partya:7051
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/partya.example.com/users/Admin@partya.example.com/msp
|
||||
echo "===================== Query chaincode package ID ===================== "
|
||||
peer lifecycle chaincode queryinstalled >&log.txt
|
||||
export PACKAGE_ID=`sed -n '/Package/{s/^Package ID: //; s/, Label:.*$//; p;}' log.txt`
|
||||
echo "packgeID=$PACKAGE_ID"
|
||||
echo "===================== Query successfull ===================== "
|
||||
}
|
||||
|
||||
approveChaincode() {
|
||||
for org in partya partyb partyc auditor rrprovider
|
||||
do
|
||||
CORE_PEER_LOCALMSPID=$org
|
||||
CORE_PEER_ADDRESS=irs-$org:7051
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/$org.example.com/users/Admin@$org.example.com/msp
|
||||
echo "===================== Approving chaincode definition for $org ===================== "
|
||||
peer lifecycle chaincode approveformyorg -o irs-orderer:7050 --channelID irs --signature-policy "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')" --name irscc --version 1 --init-required --sequence 1 --package-id ${PACKAGE_ID} --waitForEvent
|
||||
echo "===================== Chaincode definition approved ===================== "
|
||||
done
|
||||
}
|
||||
|
||||
queryApproved() {
|
||||
for org in partya partyb partyc auditor rrprovider
|
||||
do
|
||||
export CORE_PEER_LOCALMSPID=$org
|
||||
export CORE_PEER_ADDRESS=irs-$org:7051
|
||||
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/$org.example.com/users/Admin@$org.example.com/msp
|
||||
queryStatus "\"partya\": true" "\"partyb\": true" "\"partyc\": true" "\"auditor\": true" "\"rrprovider\": true"
|
||||
done
|
||||
}
|
||||
|
||||
commitChaincode() {
|
||||
CORE_PEER_LOCALMSPID=partya
|
||||
CORE_PEER_ADDRESS=irs-partya:7051
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/partya.example.com/users/Admin@partya.example.com/msp
|
||||
echo "===================== Instantiating chaincode ===================== "
|
||||
peer chaincode instantiate -o irs-orderer:7050 -C irs -n irscc -l golang -v 0 -c '{"Args":["init","auditor","100000","rrprovider","myrr"]}' -P "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')"
|
||||
echo "===================== Chaincode instantiated ===================== "
|
||||
echo "===================== Commiting chaincode definition to channel ===================== "
|
||||
peer lifecycle chaincode commit -o irs-orderer:7050 --channelID irs --signature-policy "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')" --name irscc --version 1 --init-required --sequence 1 --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-partyc:7051 --peerAddresses irs-auditor:7051 --peerAddresses irs-rrprovider:7051 --waitForEvent
|
||||
echo "===================== Chaincode definition committed ===================== "
|
||||
}
|
||||
|
||||
initChaincode() {
|
||||
CORE_PEER_LOCALMSPID=partya
|
||||
CORE_PEER_ADDRESS=irs-partya:7051
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/partya.example.com/users/Admin@partya.example.com/msp
|
||||
echo "===================== Initializing chaincode ===================== "
|
||||
peer chaincode invoke -o irs-orderer:7050 --isInit -C irs --waitForEvent -n irscc --peerAddresses irs-rrprovider:7051 --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-partyc:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["init","auditor","1000000","rrprovider","myrr"]}'
|
||||
echo "===================== Chaincode initialized ===================== "
|
||||
}
|
||||
|
||||
setReferenceRate() {
|
||||
|
|
@ -64,7 +115,7 @@ createSwap() {
|
|||
CORE_PEER_ADDRESS=irs-partya:7051
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/partya.example.com/users/User1@partya.example.com/msp
|
||||
echo "===================== Invoking chaincode ===================== "
|
||||
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["createSwap","myswap","{\"StartDate\":\"2018-09-27T15:04:05Z\",\"EndDate\":\"2018-09-30T15:04:05Z\",\"PaymentInterval\":395,\"PrincipalAmount\":10,\"FixedRate\":400,\"FloatingRate\":500,\"ReferenceRate\":\"myrr\"}", "partya", "partyb"]}'
|
||||
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["createSwap","myswap","{\"StartDate\":\"2018-09-27T15:04:05Z\",\"EndDate\":\"2018-09-30T15:04:05Z\",\"PaymentInterval\":395,\"PrincipalAmount\":100000,\"FixedRate\":400,\"FloatingRate\":500,\"ReferenceRate\":\"myrr\"}", "partya", "partyb"]}'
|
||||
echo "===================== Chaincode invoked ===================== "
|
||||
}
|
||||
|
||||
|
|
@ -95,13 +146,35 @@ createChannel
|
|||
echo "Having all peers join the channel..."
|
||||
joinChannel
|
||||
|
||||
## Install chaincode on all peers
|
||||
echo "Installing chaincode..."
|
||||
## Package the chaincode
|
||||
echo "packaging chaincode..."
|
||||
packageChaincode
|
||||
|
||||
## Query chaincode packageID
|
||||
echo "Querying packageID..."
|
||||
installChaincode
|
||||
|
||||
# Instantiate chaincode
|
||||
echo "Instantiating chaincode..."
|
||||
instantiateChaincode
|
||||
## Install chaincode on all peers
|
||||
echo "Installing chaincode..."
|
||||
queryPackage
|
||||
|
||||
# Approve chaincode definition
|
||||
echo "Approving chaincode..."
|
||||
approveChaincode
|
||||
|
||||
. scripts/query-status.sh
|
||||
|
||||
# Query approval status
|
||||
echo "querying approval status..."
|
||||
queryApproved
|
||||
|
||||
# Commit chaincode definition
|
||||
echo "Committing chaincode definition..."
|
||||
commitChaincode
|
||||
|
||||
# Init chaincode
|
||||
echo "Initialize chaincode..."
|
||||
initChaincode
|
||||
|
||||
echo "Setting myrr reference rate"
|
||||
sleep 3
|
||||
|
|
|
|||
Loading…
Reference in a new issue