GithubHelp home page GithubHelp logo

fabriciomind / loyalty-points-network Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tyrell/loyalty-points-network

0.0 0.0 0.0 28 KB

Demo: The Loyalty Points Network allows partners and members to transact using points earning offers.

License: Other

Shell 3.64% JavaScript 96.36%

loyalty-points-network's Introduction

Loyalty Points Network

The example code in this repository supplements my blog post 10 years on, #Blockchain is ready for Business use... thanks to the #Hyperledger project! found at http://www.tyrell.co/2018/01/10-years-on-blockchain-is-ready-for-business.html.


The Loyalty Points Network allows partners and members to transact using points earning offers. Members shop with the Partner businesses and will earn points for their loyalty. Members can then redem these points when Partner businesses offer ponts redemption offers. The points are carried and tracked in a membership card.

This business network defines:

Participants Partner Member

Assets Card Offer

Transactions IssuePoints RedeemPoints

The IssuePoints transaction between a Member and a Partner will add points to the Member's Card as specified in the Offer.

The RedeemPoints transaction between a Member and a Partner will reduce points in the Member's Card as specified in the Offer.

To test this Business Network Definition in the Test tab:

Create a Member participant:

{
  "$class": "co.tyrell.loyalty.Member",
  "email": "[email protected]",
  "firstName": "John",
  "lastName": "Doe",
  "dateOfBirth": "01-11-1975"
}

Create a Partner participant:

{
  "$class": "co.tyrell.loyalty.Partner",
  "partnerId": "4514",
  "partnerName": "Coles Supermarkets"
}

Create a Card asset using the above new Member's email as the id:

{
  "$class": "co.tyrell.loyalty.Card",
  "cardNumber": "8623",
  "pointBalance": 0,
  "owner": "resource:co.tyrell.loyalty.Member#[email protected]"
}

Create a Offer asset using the above new Partner's partnerId as the id and pointsAmount set to 1:

{
  "$class": "co.tyrell.loyalty.Offer",
  "offerId": "3832",
  "pointsAmount": 1,
  "partner": "resource:co.tyrell.loyalty.Partner#4514"
}

Submit a IssuePoints transaction using the offerId from the above new Offer and cardNumber from the above new Card:

{
  "$class": "co.tyrell.loyalty.IssuePoints",
  "pointsOffer": "resource:co.tyrell.loyalty.Offer#3832",
  "receivingCard": "resource:co.tyrell.loyalty.Card#8623"
}

The IssuePoints transaction above will increase the pointBalance of the Member's Card by 1 in the Asset Registry.

Congratulations!

Running our Business Network

  1. Install a runtime for our business network.

composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName loyalty-points-network

  1. Deploy our network archive file (.bna) and start the business network.

composer network start -c PeerAdmin@hlfv1 -A admin -S adminpw -a ./dist/loyalty-points-network.bna -f networkadmin.card

  1. Import the business network card generated above into the composer.

composer card import -f networkadmin.card

  1. Ping the network to confirm that it's running.

composer network ping -c admin@loyalty-points-network

If all went well, you will see a new Docker container spinning up.

  CONTAINER ID        IMAGE                                                                                                                       COMMAND                  CREATED             STATUS              PORTS                                            NAMES
  38c256b0e43a        dev-peer0.org1.example.com-loyalty-points-network-0.16.1-53f00d9f9c0a1a0da850bca1c48edcf1ed0607d9b5fb24b51944db551372b354   "chaincode -peer.a..."   4 minutes ago       Up 5 minutes                                                         dev-peer0.org1.example.com-loyalty-points-network-0.16.1
  fdf1ebde3533        hyperledger/composer-playground                                                                                             "pm2-docker compos..."   7 minutes ago       Up 8 minutes        0.0.0.0:8080->8080/tcp                           composer
  7f8f694dfcdf        hyperledger/fabric-peer:x86_64-1.0.4                                                                                        "peer node start -..."   7 minutes ago       Up 8 minutes        0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp   peer0.org1.example.com
  d693bea5725a        hyperledger/fabric-couchdb:x86_64-1.0.4                                                                                     "tini -- /docker-e..."   7 minutes ago       Up 8 minutes        4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp       couchdb
  619a883e8852        hyperledger/fabric-ca:x86_64-1.0.4                                                                                          "sh -c 'fabric-ca-..."   7 minutes ago       Up 8 minutes        0.0.0.0:7054->7054/tcp                           ca.org1.example.com
  b1f381ee6934        hyperledger/fabric-orderer:x86_64-1.0.4                                                                                     "orderer"                7 minutes ago       Up 8 minutes        0.0.0.0:7050->7050/tcp                           orderer.example.com

Generating the REST server

  Tyrells-MacBook-Air:loyalty-points-network tyrell$ composer-rest-server
  ? Enter the name of the business network card to use: admin@loyalty-points-network
  ? Specify if you want namespaces in the generated REST API: never use namespaces
  ? Specify if you want to enable authentication for the REST API using Passport: No
  ? Specify if you want to enable event publication over WebSockets: Yes
  ? Specify if you want to enable TLS security for the REST API: No

  To restart the REST server using the same options, issue the following command:
    composer-rest-server -c admin@loyalty-points-network -n never -w true

  Discovering types from business network definition ...
  Discovered types from business network definition
  Generating schemas for all types in business network definition ...
  Generated schemas for all types in business network definition
  Adding schemas for all types to Loopback ...
  Added schemas for all types to Loopback
  Web server listening at: http://localhost:3000
  Browse your REST API at http://localhost:3000/explorer

loyalty-points-network's People

Contributors

tyrell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.