Coder Social home page Coder Social logo

ibm / decentralized-energy-composer Goto Github PK

View Code? Open in Web Editor NEW
129.0 27.0 134.0 3.41 MB

WARNING: This repository is no longer maintained :warning: We are no longer showing the Hyperledger Composer Service.

Home Page: https://developer.ibm.com/code/patterns/decentralized-energy-hyperledger-composer/

License: Apache License 2.0

TypeScript 48.74% JavaScript 13.65% CSS 0.88% HTML 21.98% Shell 14.74%
ibmcode hyperledger-fabric hyperledger-composer blockchain

decentralized-energy-composer's Introduction

WARNING: This repository is no longer maintained ⚠️

Read this in other languages: 中文.

Decentralized Energy with Hyperledger Composer

A key application of Blockchain being currently explored is a Decentralized Energy network. The idea stems from a neighborhood where certain Residents are producing energy through Solar panels or other means, and can sell excess energy to Residents needing energy. The transactions would be based on coins in each Resident's account. As per a pre-determined contract and rate, the coins would be debited from the consumer and credited to the producer, for a certain billing period. Each transaction would need to be atomic and added to a Blockchain ledger for trust and verification. The network can include Banks to transact coins for Fiat currency (USD). The network can have Utility Company who can buy or provide energy through the network.

In this code pattern, we will create such a Blockchain application using Hyperledger Composer. The network consists of Residents, Banks and Utility Companies. Residents can exchange coins for energy among each other. The application assumes a pre-paid system where transactions occur after the energy is consumed and the values are updated. The Resident can exchange coins for Fiat money (USD) with Banks on the network. The Residents can also transact coins for energy with a Utility company on the network.

This code pattern is for developers looking to start building Blockchain applications with Hyperledger Composer. When the reader has completed this code pattern, they will understand how to:

  • Create business network using Hyperledge Composer and recording transactions on Blockchain ledger
  • Deploying the networking to an instance of Hyperledger Fabric
  • Building an Angular app to interact with the network through REST API

Architecture Flow

  1. The administrator interacts with Decentralized Energy UI comprising of Angular framework
  2. The application processes user requests to the network through a REST API.
  3. Implements requests to the Blockchain state database on Hyperledger Fabric v1
  4. The REST API is used to retrieve the state of the database
  5. The Angular framework gets the data through GET calls to the REST API

Included Components

  • Hyperledger Composer v0.20
  • Hyperledger Fabric v1.2
  • Angular Framework
  • Loopback

Running the Application

Follow these steps to setup and run this code pattern. The steps are described in detail below.

Prerequisite

  • Operating Systems: Ubuntu Linux 14.04 / 16.04 LTS (both 64-bit), or Mac OS 10.12
  • Docker (Version 17.03 or higher)
  • npm (v5.x)
  • Node (version 8.9 or higher - note version 9 is not supported)
    • to install specific Node version you can use nvm
  • Hyperledger Composer

Steps

  1. Clone the repo
  2. Setup Fabric
  3. Generate the Business Network Archive
  4. Deploy to Fabric
  5. Run Application
  6. Create Participants
  7. Execute Transactions

1. Clone the repo

Clone the Decentralized-Energy-Composer code locally. In a terminal, run:

git clone https://github.com/IBM/Decentralized-Energy-Composer
cd Decentralized-Energy-Composer

2. Setup Fabric

These commands will kill and remove all running containers, and should remove all previously created Hyperledger Fabric chaincode images:

docker kill $(docker ps -q)
docker rm $(docker ps -aq)
docker rmi $(docker images dev-* -q)

Set the fabric version to v1.2:

export FABRIC_VERSION=hlfv12

All the scripts will be in the directory /fabric-tools. Start fabric and create peer admin card:

cd fabric-dev-servers/
./downloadFabric.sh
./startFabric.sh
./createPeerAdminCard.sh

3. Generate the Business Network Archive

Next generate the Business Network Archive (BNA) file from the root directory:

cd ../
npm install

The composer archive create command in package.json has created a file called [email protected].

4. Deploy to Fabric

Now, we are ready to deploy the business network to Hyperledger Fabric. This requires the Hyperledger Composer chaincode to be installed on the peer, then the business network archive (.bna) must be sent to the peer, and a new participant, identity, and associated card must be created to be the network administrator. Finally, the network administrator business network card must be imported for use, and the network can then be pinged to check it is responding.

First, install the business network:

composer network install --card PeerAdmin@hlfv1 --archiveFile [email protected]

Start the business network:

composer network start --networkName decentralized-energy-network --networkVersion 0.1.15 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card

Import the network administrator identity as a usable business network card:

composer card import --file networkadmin.card

Check that the business network has been deployed successfully, run the following command to ping the network:

composer network ping --card admin@decentralized-energy-network

5. Run Application

First, go into the angular-app folder and install the dependency:

cd angular-app/
npm install

To start the application:

npm start

The application should now be running at: http://localhost:4200


The REST server to communicate with network is available here: http://localhost:3000/explorer/

6. Create Participants

Once the application opens, create participants and fill in dummy data. Create Residents, Banks and Utility Companies.

7. Execute Transactions

Execute transactions manually between Residents, Resident and Bank, and Resident and Utility Company. After executing transactions, ensure the participants account values are updated.

At the end of your session, stop fabric:

cd ~/fabric-tools
./stopFabric.sh
./teardownFabric.sh

Extending Code Pattern

This application demonstrates a basic idea of a decentralized energy network using Blockchain and can be expanded in several ways:

  • Adding specific permissions and participant access
  • Setting up real time transactions among participants
  • Integrating with IoT to read from power meter and distribute energy

Deploy to IBM Cloud

The blockchain network can be deployed to IBM Cloud. You can use the IBM Blockchain platform and start for free under Starter Membership Plan. Follow these instructions to deploy the business network to IBM Blockchain platform.

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

decentralized-energy-composer's People

Contributors

andycyao avatar dolph avatar ishangulhane avatar kant avatar ljbennett62 avatar raheelzubairy avatar wwalisa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

decentralized-energy-composer's Issues

Gettting REST call error when deployed to a Ubuntu server

When I set up the app in a Ubuntu 16.04 LTS server and run it, I got this error when doing "Add Resident".
Could not connect to REST server. Please check your configuration details

From Chrom I see the Coin API call is still pointing to port 3000 on localhost.
http://localhost:3000/api/Coins

Is there way to configure the Angular app to use the domain name and port of my own choosing to do the API calls?

Thanks!

Dummy data cannot be created

Hi, I have succeeded to run the angular app.
But, somewhat I can create a participant, but I cannot create another one.
In other words, after the creation of resident, I cannot create a utility company at all.

What is wrong?

Migration to fabric-shim

As composer will no longer be getting updates from Fabric version 1.3, several people and projects, I imagine, would be looking to shift to either using go or nodejs for the chaincode.

I myself am migrating to nodejs and would like to create a public repository to demonstrate this exact same code base using nodejs but will require some additional collaborators to help out. Looking for some guidance.

Not sure where to post this so I opened an issue over here, hope that is ok with you. I am keen to learn and thought this is a good way to give back as well.

angular works incorrectly using nginx reverse proxy

when started angular, it can be accessed from http://localhost:4200. but it cannot work correctly using ngnix reverse proxy. open http://mysite.com/angular in the browser, it can only display Load .... while http://mysite.com/explorer works ok. so i think there is something wrong with angular or nginx.

here is my configuration.

server {
         listen 80;
         server_name mysite.com;

         location /explorer {
             proxy_pass http://localhost:3000;
         }

         location /angular {
             proxy_pass http://localhost:4200;
         }
     }

Composer network start Not Working. Unable to initalize channel

I tried to deploy the fabric, but I couldn't create a channel. with the following error:

✖ Starting business network definition. This may take a minute...
Error: Error trying to start business network. Error: Unable to initalize channel. Attempted to contact 1 Peers. Last error was Error: Error: Failed to connect before the deadline
Command failed

Install issue

I am able to go thru the first two steps in the installation instructions on my MacBook.

In step three I then do:
Step 1: cd ../ // which brings me to the Decentralized-Energy-Composer directory
Step 2: npm install //which works fine
Step 3: composer archive create -a dist/decentralized-energy-network.bna --sourceType dir --sourceName .

But there is no "composer" command in the Decentralized-Energy-Composer directory. On the other hand I can find a number of composer directories in the node-modules directory.

Any idea what might be the trouble?

incorrect permissions in the ACL

//Banks to have read access to all coins assets
rule BankAccessCoinsRecord {
    description: "Allow banks read access to all coins assets"
    participant: "org.decentralized.energy.network.Bank"
    operation: READ
    resource: "org.decentralized.energy.network.Coins"
    action: ALLOW
}

//Banks to have read/update access to all cash assets
rule BankAccessCashRecord {
    description: "Allow banks read access to all cash assets"
    participant: "org.decentralized.energy.network.Bank"
    operation: READ
    resource: "org.decentralized.energy.network.Cash"
    action: ALLOW
}

Shouldn't the operation for both of them also include UPDATE?

While adding resident Error: Could not connect to REST server. Please check your configuration details

screenshot from 2018-08-18 17-34-25
I got this error while adding Resident. Error: Could not connect to REST server. Please check your configuration details.

While npm start in angular-app got following error:
Error: Composer runtime (0.19.14) is not compatible with client (0.20.0)
[1] It will be retried for the next request.
[1] Exception: Error: Error trying to ping. Error: Composer runtime (0.19.14) is not compatible with client (0.20.0)
[1] Error: Error trying to ping. Error: Composer runtime (0.19.14) is not compatible with client (0.20.0)
[1] at _checkRuntimeVersions.then.catch (/home/r1/Decentralized-Energy-Composer/angular-app/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:806:34)
[1] at
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! errno 1
[1] npm ERR! [email protected] app: composer-rest-server -c admin@decentralized-energy-network -n never -w true
[1] npm ERR! Exit status 1
npm ERR!
[1] npm ERR! Failed at the [email protected] app script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[1]
[1] npm ERR! A complete log of this run can be found in:

$ npm list -g --depth=0
/home/r1/.nvm/versions/node/v8.9.4/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

npm ERR! invalid: [email protected] /home/r1/.nvm/versions/node/v8.9.4/lib/node_modules/npm/node_modules/tar/node_modules/minizlib

Can anyone Please Help...

Everything except Transactions work

Question, is it possible to add a window where the blockchain blocks show up as one adds transactions? That would be really great so one can show how the blocks are added to the blockchain as one runs the transactions.

It would really just be a list of the transaction IDs as far as I can see. It usually drives home how the blockchain works.

Something like this:

Blockchain:
7c299bbd-09ae-456f-8e97-30016ab6cec10
7c299bbd-09ae-456f-8e97-30016ab6cec9
7c299bbd-09ae-456f-8e97-30016ab6cec8
7c299bbd-09ae-456f-8e97-30016ab6cec7
7c299bbd-09ae-456f-8e97-30016ab6cec6
7c299bbd-09ae-456f-8e97-30016ab6cec5

Growing as te demo progresses.

--defaultchain flag should be removed

--defaultchain flag was removed from the latest fabric. so the docker-composer.yml file should be revised in the configuration of peer0.org1.example.com. the start command can changed from
command: peer node start --peer-defaultchain=false
to be
command: peer node start

Ubuntu 16.04 - Command "runtime" is not defined

Got following error after following the instructions on Ubuntu 16.04 VPS
root@blockchain:~/Energy/Decentralized-Energy-Composer/dist# composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName decentralized-energy-network
Do not run Composer as root/super user! See https://getcomposer.org/root for details

[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "runtime" is not defined.

npm install failed

During step 3, npm install couldn't complete successfully. I am using node 8.4.0, npm 5.4.0 on Mac Sierra 10.12.6

npm

Extending the project to integrate IoT.

Hello, first of all I would say this is a great project, well done to the developers.
It is mentioned in the README that the code can be extended to integrate IoT devices such as smart meters. Could you guys give a little heads up as to where one would start working on to achieve that goal.

issues in angular-app where any action results in error

I receive this error by trying to interact with the web-app, so far no buttons or routing works:

core.es5.js:1020 ERROR Error: Uncaught (in promise): EmptyError: no elements in sequence
EmptyError: no elements in sequence
    at new EmptyError (EmptyError.js:27)
    at FirstSubscriber._complete (first.js:154)
    at FirstSubscriber.Subscriber.complete (Subscriber.js:121)
    at MergeMapSubscriber._complete (mergeMap.js:144)
    at MergeMapSubscriber.Subscriber.complete (Subscriber.js:121)
    at MapSubscriber.Subscriber._complete (Subscriber.js:139)
    at MapSubscriber.Subscriber.complete (Subscriber.js:121)
    at EmptyObservable._subscribe (EmptyObservable.js:82)
    at EmptyObservable.Observable._trySubscribe (Observable.js:173)
    at EmptyObservable.Observable.subscribe (Observable.js:161)
    at new EmptyError (EmptyError.js:27)
    at FirstSubscriber._complete (first.js:154)
    at FirstSubscriber.Subscriber.complete (Subscriber.js:121)
    at MergeMapSubscriber._complete (mergeMap.js:144)
    at MergeMapSubscriber.Subscriber.complete (Subscriber.js:121)
    at MapSubscriber.Subscriber._complete (Subscriber.js:139)
    at MapSubscriber.Subscriber.complete (Subscriber.js:121)
    at EmptyObservable._subscribe (EmptyObservable.js:82)
    at EmptyObservable.Observable._trySubscribe (Observable.js:173)
    at EmptyObservable.Observable.subscribe (Observable.js:161)
    at resolvePromise (zone.js:824)
    at resolvePromise (zone.js:795)
    at zone.js:873
    at ZoneDelegate.invokeTask (zone.js:425)
    at Object.onInvokeTask (core.es5.js:3881)
    at ZoneDelegate.invokeTask (zone.js:424)
    at Zone.runTask (zone.js:192)
    at drainMicroTaskQueue (zone.js:602)
    at ZoneTask.invokeTask [as invoke] (zone.js:503)
    at invokeTask (zone.js:1540)

screen shot 2017-12-03 at 12 48 59 pm

Permissions feature

These lines in permissions.acl ensure any company can read any other company's data which is not ideal. I wanted to fork this repo and make it such that the read access to other utility companies data is revoked, so competing utility companies cannot read each other's data.

It is my understanding I will need to use composer-passport to achieve this, as I will be required to juggle multiple certificates for different users. Can I have some guidance for it please sir? I would want to work on this and contribute back to the project.

//Utility Companies to have access to their own account
rule UtilityCompanyAccessOwnRecord {
    description: "Allow utilty company to access only their profile"
    participant(p): "org.decentralized.energy.network.UtilityCompany"
    operation: READ, UPDATE, DELETE
    resource(r): "org.decentralized.energy.network.UtilityCompany"
    condition: (r.getIdentifier() === p.getIdentifier())
    action: ALLOW
}

//Utility Companies to have read only access to other Utility Companies
rule UtilityCompanyReadAccessUtilityCompanies {
    description: "Allow utility companies read access to other Utility Companies"
    participant: "org.decentralized.energy.network.UtilityCompany"
    operation: READ
    resource: "org.decentralized.energy.network.UtilityCompany"
    action: ALLOW
}

Error in ./startFabric.sh

the startFabric.sh script has the following errors:

Create the channel

docker exec peer0.org1.example.com peer channel create -o orderer.example.com:70
50 -c composerchannel -f /etc/hyperledger/configtx/composer-channel.tx
Error response from daemon: Container 8a2603a405ed625b689f960bc81afa3269b54664ff
f15a587dc12cac6007c21c is not running

bna file is having error. Not able to instantiate chaincode

After generating the bna file not able to install it to fabric as it contains error.
Warning prepublish-on-install:
As of npm@5, prepublish scripts are deprecated.
Use prepare for build steps
Skipping optional dependency [email protected]

found 94 vulnerabilities

During start of business network, chaincode error (status 500, message: is not a valid endorsement system chaincode)

Windows version

Hello, could you provide a Windows OS version for this implementation please? Thank you

Question : How did you generate "angular-app" folder?

Hi ,

I just wanted to know the command you have used to generate the "angular-app" folder when I try to generate It is creating only for asset but not for participant, but in your example I can see it is generating for both of them.

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.