Skip to content

SaifRehman/composer-voting-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Learning objectives

In this tutorial you will create and deploy a voting application based on Hyperledger Composer and test on Composer Playground

Estimated time

It will take around 10 minutes roughly to create and test your application on Composer Playground

Introduction

The Hyperledger Composer Playground provides a user interface for the configuration, deployment and testing of a business network. Advanced Playground features permit users to manage the security of the business network, invite participants to business networks and connect to multiple blockchain business networks.

Steps

  1. Navigate to Composer Playground
  2. Click on Let's Blockchain 1
  3. Click on Deploy a new buisness network, then select empty-buisness-network, and click on deploy
  4. Connect to the buisness network 2
  5. Paste in the following code on models/models/cto file
/**
 * 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
}
  1. Click on add a file and add lib/script.js
  2. Paste the following code at lib/script.js
'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. Click on Deploy
  2. Now go to test tab to test your application where you can create assets, participants, and do some transactions] 3

Summary

In this tutorial we have built a quick prototype to create a voting application based on Hyperledger Composer

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published