Code Monkey home page Code Monkey logo

ibm / blockchain_for_telcoroaming Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 27.0 238 KB

This blockchain Hyperledger Composer project shows you how to create a Hyperledger Fabric with smart contracts that govern the transactions between CSPs acting as home operators and roaming partners to track the activities of mobile users on the network.

Home Page: https://developer.ibm.com/patterns/blockchain-for-telecom-roaming-fraud-and-overage-management/

Gherkin 18.92% JavaScript 81.08%
blockchain hyperledger-fabric hyperledger-composer composer-playground cloud

blockchain_for_telcoroaming's Introduction

BlockchainforTelecomRoaming

This is a proof of concept to demonstrate how Blockchain brings the CSPs on single Blockchain Hyperledger network which enables direct exchange of information with transactions that are immutable and executed based on consensus model using smart contract rules.

This business network defines:

Participants: Home Operator Roaming Partner

Assets: Subscriber Sims

Transactions: discovery authentication updaterate callout overagecheck callend callpay addUser

Bussines Network

There are four scenarions covered :

  1. Roaming Subscriber Identification A subscriber moves to a new location out of home network. Is discovered by Roaming Partner. discovery transaction is executed. Roaming Partner authenticates Roaming Subscriber as a visitor from Home Operator. authentication transaction is executed. Home Operator register Roaming Subscriber accordingly. updaterate transaction is executed.
  2. Roaming Subscriber Billing Now that authorized, Roaming Subscriber uses Roaming Partner network to initiate a call. callout and callend transactions are executed. The charges for network usage are instantaneously recorded between Home Operator and Roaming Partner based on their agreement. callpay transaction is executed.
  3. Fraud Identification Addition of a Fraudulent Subscriber is simulated. addUser transaction is executed. Fraudulent Subscriber tries to registered to access the Home Operator network using the same MSISDN of an existing user Authentication step identifies the subscriber and prevent the fraud. authentication transaction is executed.
  4. Overage Management A roaming subscriber intiates a call/ Smart contract recognizes that subscriber is potentially reaching overage threshold. callout transaction is executed. Operator notifies the Overage Subscriber of the potential tariff change. overagecheck transaction is executed.

Audience level : Intermediate Developers

If you have an IBM cloud lite account, you can also use the Starter Plan for 30 days to do this pattern.

Included Components

  • Hyperledger Fabric
  • Hyperledger Composer

Included technologies

  • Blockchain
  • Containers
  • Cloud

Application Workflow Diagram

Application Workflow

  • Install Hyperledger Composer development tools
  • Configure and start Hyperledger Fabric network
  • Generate the Business Network Archive file
  • Deploy the Business Network Archive using Composer Playground
  • (Alternative method) Deploy the Business Network Archive on Hyperledger Composer running locally

Steps

  1. Generate the Business Network Archive (BNA)
  2. Deploy the Business Network Archive using Composer Playground
  3. Deploy the Business Network Archive on Hyperledger Composer running locally

1. Generate the Business Network Archive (BNA)

To check that the structure of the files is valid, you can now generate a Business Network Archive (BNA) file for your business network definition. The BNA file is the deployable unit -- a file that can be deployed to the Composer runtime for execution.

Use the following command to generate the network archive:

npm install

You should see the following output:

Creating Business Network Archive

Looking for package.json of Business Network Definition
	Input directory: /Users/<user-name>/Documents/git-demo/roaming

Found:
	Description: Telecom Roaming Demo
	Name: my-network
	Identifier: [email protected]

Written Business Network Definition Archive file to
	Output file: ./dist/my-network.bna

Command succeeded

The composer archive create command has created a file called my-network.bna in the dist folder.

You can test the business network definition against the embedded runtime that stores the state of 'the blockchain' in-memory in a Node.js process. From your project working directory, open the file test/foodTest.js and run the following command:

npm test

You should see the following output :

> [email protected] test /Users/<user-name>/Documents/demo/roaming
> mocha --recursive

  #composer.food.supply
    ✓ Transfer ProductListing to Importer (67ms)
    ✓ Exempt Check for ProductListing (98ms)
    ✓ Transfer ProductListing to Retailer (95ms)

  3 passing (2s)

2. Deploy the Business Network Archive using Composer Playground

Hyperledger Composer is a programming model containing a modeling language, and a set of APIs to quickly define and deploy business networks and applications that allow participants to send transactions that exchange assets. You can experience Hyperledger Composer with the browser-based UI called Hyperledger Composer Playground. Playground is available as a hosted version (no install necessary) or a local install (good for editing and testing sample business networks offline).

Open Composer Playground, by default the Basic Sample Network is imported. If you have previously used Playground, be sure to clear your browser local storage by running localStorage.clear() in your browser Console.

Now import the my-network.bna file and click on Deploy button.

You can also setup Composer Playground locally.

Once the bna is deployed , go to the Test tab

To test your Business Network Definition, first click on the Test tab:

Create CSPs using transaction resetCSP

Model:
resetCSP {
$class (string, optional): The class identifier for this type ,
noneed (string),
transactionId (string, optional): The instance identifier for this type ,
timestamp (string, optional)
}

Example Value:
{
  "$class": "org.gsc.roaming.resetCSP",
  "noneed": "string",
  "transactionId": "string",
  "timestamp": "2017-10-05T07:24:24.743Z"
}

Create Subscribers using transaction resetMSISDN

Model:
resetMSISDN {
$class (string, optional): The class identifier for this type ,
noneed (string),
transactionId (string, optional): The instance identifier for this type ,
timestamp (string, optional)
}

Example Value:
{
  "$class": "org.gsc.roaming.resetMSISDN",
  "noneed": "string",
  "transactionId": "string",
  "timestamp": "2017-10-05T07:24:24.749Z"
}

Scenario 1 :

execute transaction discovery

{
  "$class": "org.gsc.roaming.discovery",
  "asset": "string",
  "rp": "string",
  "location": "string",
  "lat": "string",
  "long": "string",
  "transtype": "string",
  "transactionId": "string",
  "timestamp": "2017-10-05T07:24:24.724Z"
}

execute transaction authentication

{
  "$class": "org.gsc.roaming.authentication",
  "asset": "string",
  "rp": "string",
  "transtype": "string",
  "roaming": "string",
  "flag": "string",
  "transactionId": "string",
  "timestamp": "2017-10-05T07:24:24.657Z"
}

execute transaction updaterate

{
  "$class": "org.gsc.roaming.updaterate",
  "asset": "string",
  "rp": "string",
  "ratetype": "string",
  "transtype": "string",
  "transactionId": "string",
  "timestamp": "2017-10-05T07:24:24.811Z"
}

Similar for other three scenarios.

3. Deploy the Business Network Archive on Hyperledger Composer running locally

Please start the local Fabric using the instructions. Now change directory to the dist folder containing my-network.bna file and type:

cd dist
composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName my-network
composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile food-supply.bna --file networkadmin.card
composer card import --file networkadmin.card

You can verify that the network has been deployed by typing:

composer network ping --card admin@my-network

You should see the the output as follows:

The connection to the network was successfully tested: events
	version: 0.18.1
	participant: org.hyperledger.composer.system.NetworkAdmin#admin
	identity: org.hyperledger.composer.system.Identity#1f95efceac5421ad34d73130c8f16fbc2d29b7dce0c3425afb3b5f077242b1fc

Command succeeded

To create the REST API we need to launch the composer-rest-server and tell it how to connect to our deployed business network. Now launch the server by changing directory to the roaming folder and type:

cd ..
composer-rest-server

Answer the questions posed at startup. These allow the composer-rest-server to connect to Hyperledger Fabric and configure how the REST API is generated.

  • Enter admin@my-network as the card name.
  • Select never use namespaces when asked whether to use namespaces in the generated API.
  • Select No when asked whether to secure the generated API.
  • Select Yes when asked whether to enable event publication.
  • Select No when asked whether to enable TLS security.

Test REST API

If the composer-rest-server started successfully you should see these two lines are output:

Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer

Open a web browser and navigate to http://localhost:3000/explorer

You should see the LoopBack API Explorer, allowing you to inspect and test the generated REST API. Follow the instructions to test Business Network Definition as mentioned above in the composer section.

Additional Resources

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

blockchain_for_telcoroaming's People

Contributors

amanrubalibm avatar kant avatar ljbennett62 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blockchain_for_telcoroaming's Issues

Not able to generate the bna file

Following are the versions installed in my environment.
node version - v8.4.0
python version - 2.7.10
composer - v0.19.5
But unable to create bna file with npm install

npm install problem

Hi, I'm a new developer of blockchain.
When I run the npm install in the "Generate the Business Network Archive (BNA)" process, it shows:

In file included from ../src/hashtable.cpp:1:
../src/hashtable.h:7:10: fatal error: 'tr1/unordered_map' file not found
#include <tr1/unordered_map>
^~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/native/src/hashtable.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/dada/.nvm/versions/node/v8.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/Users/dada/.nvm/versions/node/v8.15.0/bin/node" "/Users/dada/.nvm/versions/node/v8.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /Users/dada/Blockchain_for_TelcoRoaming-master/node_modules/hashtable
gyp ERR! node -v v8.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp configure build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/dada/.npm/_logs/2019-01-16T09_23_16_524Z-debug.log

Is there something wrong with nvm or nodejs? Hope anyone can guide me to solve the problem.

remove the .vs_code directory

this is editor/user specific settings, and do not need to be in the repo, remove the directory and optionally add a .vs_code entry to .gitignore.

IBM Blockchain Deployment

Some of the demos for hyperledger come with a bluemix deployment config/script. Would it be possible to get this deployed on IBM Blockchain?

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.