项目作者: Capgemini-AIE

项目描述 :
Blockchain Car Insurance with Smart Contracts on Hyperledger
高级语言: JavaScript
项目地址: git://github.com/Capgemini-AIE/blockchain-insurance.git
创建时间: 2017-02-06T14:30:37Z
项目社区:https://github.com/Capgemini-AIE/blockchain-insurance

开源协议:

下载


Blockchain Insurance

A proof of concept Blockchain project around Car Insurance.

Deploy this to Bluemix

Deploy to Bluemix

To deploy to Bluemix:

1) Hit the button above.
2) Open the created pipeline, inspect the ‘credentials’ step & add missing environment property values.

  1. APIKEY=EDMUNDS API KEY (sign up for one),
  2. GCM_KEY=Google cloud messaging key for webpush.

3) Open ‘deploy’ and add a basic CF deploy job.
4) Run the pipeline from the start.
5) If errors occur, bind an instance of IBM’s blockchain service to the application & restage.

Development Environment

We’re building on the docker-compose from https://github.com/IBM-Blockchain/fabric-images.

See also these instructions for using a local hyperledger network.

To run a single node network using Docker Compose -

  1. docker-compose -f docker-compose/single-peer-ca.yaml up -d

For a four node + CA network:

  1. docker-compose -f four-peer-ca.yaml up -d

To test it is up and running properly hit http://localhost:7050/chain

Configuring users in local (dev mode) docker instance

Execute the following commands after running docker-compose (from the docker-compose folder)

  1. docker cp membersrvc/membersrvc.yaml dockercompose_membersrvc_1:/opt/gopath/src/github.com/hyperledger/fabric/membersrvc
  2. docker exec -i -t dockercompose_membersrvc_1 /bin/bash
  3. rm -rf /var/hyperledger/production
  4. exit
  5. docker restart dockercompose_membersrvc_1
  6. docker exec -i -t dockercompose_vp0_1 /bin/bash
  7. rm -rf /var/hyperledger/production
  8. exit
  9. docker restart dockercompose_vp0_1

7 users will then be created:

  1. claimant1
  2. claimant2
  3. garage1
  4. garage2
  5. insurer1
  6. insurer2
  7. superuser

In order for the correct username/role to be established within the chaincode (in dev mode), an attributes
value has to be added to the REST request. Example:

  1. curl -H "Content-Type: application/json" -X POST -d '{
  2. "jsonrpc": "2.0",
  3. "method": "query",
  4. "params": {
  5. "type": 1,
  6. "chaincodeID": {
  7. "name": "insurance"
  8. },
  9. "ctorMsg": {
  10. "function": "retrieveAllPolicies"
  11. },
  12. "secureContext": "claimant2",
  13. "attributes": ["username","claimant2","role","policyholder"]
  14. },
  15. "id": 4
  16. }' http://localhost:7050/chaincode

Deploying chaincode for development (Only currently working in the 4 peer environment)

To run chaincode locally without having to deploy from a github url:

1) Build your chaincode

  1. go build ./

2) Register the chaincode with a peer

  1. CORE_CHAINCODE_ID_NAME=insurance CORE_PEER_ADDRESS=0.0.0.0:7051 ./insurance_main

3) Send a REST request to enroll a user

  1. POST: http://localhost:7050/registrar
  2. {
  3. "enrollId": "bob",
  4. "enrollSecret": "NOE63pEQbL25"
  5. }

4) Send a REST deploy request

  1. POST: http://localhost:7050/chaincode
  2. {
  3. "jsonrpc": "2.0",
  4. "method": "deploy",
  5. "params": {
  6. "type": 1,
  7. "chaincodeID":{
  8. "name": "insurance"
  9. },
  10. "ctorMsg": {
  11. "function":"init"
  12. },
  13. "secureContext": "bob"
  14. },
  15. "id": 1
  16. }

5) The chaincode should now be deployed and ready to accept INVOKE or QUERY requests.

Running Blockchain Explorer

If you want to view your blockchian locally you can use the blockchain explorer.

To build the Docker image, run -

  1. git clone https://github.com/hyperledger/blockchain-explorer.git
  2. cd blockchain-explorer/explorer_1
  3. docker build -t hyperledger/blockchain-explorer .

To run it first you will need to find out which network your hyperledger fabric peers are running on.
To do this run:

  1. docker network ls

Grab the Docker Compose network name and use it below:

  1. docker run -p 9090:9090 -itd --network=dockercompose_default -e HYP_REST_ENDPOINT=http://vp0:7050 hyperledger/blockchain-explorer

The explorer should then be available on http://localhost:9090.

Configuring the vehicle value oracle

In order to use the car value oracle to obtain actual vehicle values from Edmunds you must:

1) Obtain an Edmunds api key and set the env variable. (Note: this step can be skipped, and the oracle service will then just callback with a hardcoded value.)

  1. EDMUNDS_API_KEY

2) Deploy the chain code with an init argument specifying the host address of the oracle service (including port)

3) Configure the node app with the correct blockchain settings (in default.json).

4) Run the app.js node app

  1. npm install
  2. node app.js