Skip to content

Commit

Permalink
[FAB-15199] Update interest rate sample
Browse files Browse the repository at this point in the history
Update interest rate sample for chaincode
lifecycle

Change-Id: I8e481dda11a757d5fe76105098307141a67dff60
Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com>
  • Loading branch information
NIKHIL E GUPTA committed Jun 12, 2019
1 parent f0dca20 commit 7c5f5d3
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 61 deletions.
34 changes: 24 additions & 10 deletions interest_rate_swaps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Loading

0 comments on commit 7c5f5d3

Please sign in to comment.