Giter VIP home page Giter VIP logo

hyperledger-composer-voting-app's Introduction

Usuage

Prerequisites

  1. Install Dockers
  2. Install VSCode, and VSCode Hyperledger Composer Plugin
  3. Install required npm node packages
> npm install -g composer-cli
> npm install -g generator-hyperledger-composer
> npm install -g composer-rest-server
> npm install -g yo
  1. Setting and running Hyperledger Fabric
> mkdir fabric-tools
> cd fabric-tools
> curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
> unzip fabric-dev-servers.zip
> ./downloadFabric.sh
> ./startFabric.sh
> ./createPeerAdminCard.sh

Instantiating your Business Blockchain with Composer

  1. Create a new project directory
> mkdir app
> cd app
  1. Instantiate a Business network by yo npm plugin
> yo hyperledger-composer:businessnetwork
> Business network name: voting
> Description: A simple blockchain network
> Author name:  saif
> Author email: [email protected]
> License: Apache-2.0
> Namespace: org.acme.voting
  1. Navigate to business network folder and install the dependencies
> cd voting 
> npm install

.cto file code

/**
 * Write your model definitions here
 */
namespace org.acme.voting

participant voter identified by voterID {
  o String voterID
  o String fullName
}

asset ifVoted identified by voterID {
  o String voterID
  o Boolean votedOrNot
}

asset candidateVote identified by politicalParty {
  o String politicalParty
  o Integer totalVote
}
transaction vote {
  --> candidateVote candidateVoteAsset
  --> ifVoted ifVotedAsset
}

logic.js code

'use strict';
/**
 * Write your transction processor functions here
 */

/**
 * Sample transaction
 * @param {org.acme.voting.vote} vote
 * @transaction
 */
function vote(tx) {
    if (!tx.ifVotedAsset.votedOrNot) {
        tx.candidateVoteAsset.totalVote = tx.candidateVoteAsset.totalVote + 1;
        return getAssetRegistry('org.acme.voting.candidateVote')
            .then(function (assetRegistry) {
                return assetRegistry.update(tx.candidateVoteAsset);
            })
            .then(function () {
                return getAssetRegistry('org.acme.voting.ifVoted')
                    .then(function (assetRegistry) {
                        tx.ifVotedAsset.votedOrNot = true;
                        return assetRegistry.update(tx.ifVotedAsset);
                    })
            });
    }
}
  1. Creating the .bna file
> mkdir dir
> composer archive create --sourceType dir --sourceName . -a ./dist/network.bna
  1. Deploying the .bna file on the Hyperledger Fabric Blockchain
> composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName voting
> composer network start --card PeerAdmin@hlfv1 -A admin -S adminpw -a network.bna -f networkadmin.card
> composer card import -f networkadmin.card
  1. Interfacing you blockchain with Restfull CRUD Apis
> composer-rest-server

Authors

hyperledger-composer-voting-app's People

Watchers

James Cloos avatar wassim.znaidi 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.