Vous êtes sur la page 1sur 25

Chapter Seven

System Implementation and Test

Oman Voting Network

The Oman Voting Network allows the voters to cast their vote for a candidate for a
particular election. The voter Participant and the candidate Participant must are approved
by Election Authority Participant to participate in the election. The candidate will request
for nomination through candidate Nomination Request transaction. The Election
Authority will approve the nomination request. Through election Authority Nomination
Approval Transaction or reject the nomination request through Election Authority
Nomination Reject Transaction. There are certain rules that must be applied for candidate
nomination approval. Once the candidate nomination is approved, the voter can cast their
vote for a particular candidate using the candidate Nomination ID with vote casting
transaction. Again, set of rules are applied before a voter can cast a vote. Once the vote is
casted, the candidate total votes are incremented by 1 vote. The figure 7.1 illustrates the
transaction for each participant.

Figure Error! No text of specified style in document..1: The transaction (Tx) for each participant
Oman Voting Network defines

Participants: voter, candidate, electionAuthority

Figure Error! No text of specified style in document..2: Oman Voting Network Participants
Hierarchal Details

Assets: Election, candidateNomination, voteCasting

Figure Error! No text of specified style in document..3: Oman Voting Network Asset Hierarchal
Details

Transactions: The figure 7.1 illustrates the transaction for each participant. The
transactions as following:

 candidateCitizenRequestApprovalTrans: The transaction done by candied


who request from election authority to approve their citizen.
 candidateNominationRequestTrans: candidate request for nomination in
election
 electionAuthorityNominationApprovalTrans: Election Authority approve
candidate nomination request.
 electionAuthorityNominationRejectTrans: Election Authority reject
candidate nomination request.
 voteCastingTrans: this transaction for voter to vote only one vote for each
election. For example for election 2018 each voter has to cast only one vote.
 voterCitizenRequestApprovalTrans: The transaction is invoked by elwction
authority to approve the citizenship of a voter.
 SetupDemo: This transaction use for test purpose. It will insert some sample
data into the system.

Oman Voting Network flow

1. adminOfTheNetwork will add the Election,


voter, candidate and electionAuthority data. The admin of the Network will
also create identities for all the voter, candidate and election Authority
participants so that they will be able to login into the system and use it. Without
this master data and identities, no election process can be started.
a. electionAuthority will confirm the citizenship of all the voters and
candidates using
the voterCitizenRequestApprovalTrans andcandidateCitizenRequestAppro
valTrans transactions .
2. Candidate participant submits a nomination request to electionAuthority using
the candidateNominationRequestTrans transaction.
3. electionAuthority invokes
the electionAuthorityNominationApprovalTrans transaction to approve the
nomination request or invokes
the electionAuthorityNominationRejectTrans transaction to reject the nomination
request.
4. Voter participant invokes the voteCastingTrans to cast the vote for a particular
candidate. After successfull transaction, the candidate total votes are incremented
with one vote. Note: setupDemo transaction is provided to authomatically insert
some voters, elections, candidates and electionAuthority for testing purpose.

Prototype Files

Model file

A model file of Hyperledger Composer modeling language uses to specify the


participants who will execute transactions, the assets across the network, and the
transactions and also it include namespace. In my voting application, the participants
include candidate, election authority and voter. The transaction is the act of voting is
(Model.CTO).

Configure namespace

namespace om.oman.voting

Defined Participants

There are three participant in system include voter, candidate, and ElectionAuthority.
Figure 7.3 example of defining voter in module file.
Figure Error! No text of specified style in document..4: define voter participant in Model file

Defined asset

There are four asset in system include Election, Candidate Nomination, Nominating
Approval, and vote Casting. Figure 7.4 indicted defined candidate nomination asset

Figure Error! No text of specified style in document..5: Defined candidate nomination asset

Defined System transaction

The transaction consist candidate request citizen and nomination, voter request citizen
and voter cast vote, also election authority have to approved or rejected nomination.

The script file

The script file use JavaScript to define the actual e-voting system logic and functionality
of the voting application. For the voting application, the script file defines the voting
logic and rules. For instant, the election authority proves or rejects the nomination
candidate. Example of electionAuthorityNominationApprovalTrans Transactions
illustrate in figure.

Figure Error! No text of specified style in document..6: Transactions for election Authority to
approval Nomination

Prototype Test

To test the voting system prototype in Hyperledger Composer Playground by create


assets, add participants, and do transactions using JOSIN format.

Figure Error! No text of specified style in document..7: The web for voting-business-network

Administrator Add wallet to participants manual as illustrated in figure there are eight
wallets one for admin, three for candidate (C1, C2, and C3), three Voter (V1, V2, and
V3), and one election authority (E1) wallet. Each wallet have different account

Figure Error! No text of specified style in document..8: voting business network wallets

The Transactions Test

No transactions apply

For example if voter (v1) one want to cast vote for candidate (1) one thy have to approve
their citizen from election authority. Then candidate have to request nomination.
Candidate1 (C1) has citizen approval

Figure Error! No text of specified style in document..9: Candidate 1 has citizen approval

Candidate 1(C1) Nomination request.

Figure Error! No text of specified style in document..10: Candidate 1(C1) Nomination request

Election autority found asset or request from candidate 1 to approved


Figure Error! No text of specified style in document..11: Candidate nomination Asset need to
approved

Election authority Check the candidate1 caritera and create nomination approval.

Figure Error! No text of specified style in document..12: Approved asset 1

Voter 1 (V1) have citizen approval and able cast vote.

Figure Error! No text of specified style in document..13: citizen approval of Voter 1 (V1)
Voter 1 cast vote for candidate 1

Figure
Error! No text of specified style in document..14: cast vote

Totalvotes increase by one for candidate nominationtion 1

Figure Error! No text of specified style in document..15: increase total of vote in the candidate 1
wallet

All tansaction recorded.


Figure Error! No text of specified style in document..16: all transactions had been record

Conclusion

This chapter provides possible application of the implementation E-voting system.


However due to time constraints, the true applicability could not be fully tested, but it is
proved the possibility of implement e-voting system in Blockchain Hyperledger Fabric.
Appendix E: Test data

1.1 Prototype Test

To test this Business Network Voting Network Definition in the Test tab: run the
setupDemo transaction using the admin user. This will create the following participants
and assets;

5 candidate with candidateID (1,2,3,4,5)

5 voter with voterID (1,2,3,4,5)

1 electionAuthority with electionAuthroriyID (1)

Create identities for all of the voter, candidate and electionAuthority participants. login
with candidateID1 and submit the candidateNominationRequestTrans transaction.

{
"$class": "om.oman.voting.candidateNominationRequestTrans",
"Election": "resource:om.oman.voting.Election#1",
"candidateNominationID": "1",
"candidateApplyDate": "2018-09-15T07:29:59.583Z",
"candidate": "resource:om.oman.voting.candidate#1"
}
The candidate ElectionAuthorityCitizenApproval will be set to Requested.

electionAuthorityNominationApprovalTrans

Now login with electionAughority1 and approve the nomination request by invoking
the electionAuthorityNominationApprovalTrans transaction.

{
"$class": "om.oman.voting.electionAuthorityNominationApprovalTrans",
"candidateNomination": "resource:om.oman.voting.candidateNomination#1",
"NominationApproveRejectDate": "2018-09-15T07:33:08.870Z"
}
This will approve the candidate nomination request. Now the voter can vote for that
candidate.

voteCastingTrans

Login as voter1 and invoke the voteCastingTrans transaction to cast the vote.

{
"$class": "om.oman.voting.voteCastingTrans",
"voter": "resource:om.oman.voting.voter#1",
"candidateNomination": "resource:om.oman.voting.candidateNomination#2",
"voteCastingID": "1",
"VoteCastingDate": "2018-09-15T07:36:35.981Z"
}
This will cast the vote and increment the candidate total votes by 1 vote.

The rest of the other transactions can be invoked for their particular use case.
Appendix F: User guide

1.2 Oman Voting Network flow

5. adminOfTheNetwork will add the Election,


voter, candidate and electionAuthority data. The admin of the Network will
also create identities for all the voter, candidate and election Authority
participants so that they will be able to login into the system and use it. Without
this master data and identities, no election process can be started.
a. electionAuthority will confirm the citizenship of all the voters and
candidates using
the voterCitizenRequestApprovalTrans andcandidateCitizenRequestAppro
valTrans transactions .
6. Candidate participant submits a nomination request to electionAuthority using
the candidateNominationRequestTrans transaction.
7. electionAuthority invokes
the electionAuthorityNominationApprovalTrans transaction to approve the
nomination request or invokes
the electionAuthorityNominationRejectTrans transaction to reject the nomination
request.
8. Voter participant invokes the voteCastingTrans to cast the vote for a particular
candidate. After successfull transaction, the candidate total votes are incremented
with one vote. Note: setupDemo transaction is provided to authomatically insert
some voters, elections, candidates and electionAuthority for testing purpose.

1.3 Prototype Files


1.3.1 Model file

A model file of Hyperledger Composer modeling language uses to specify the


participants who will execute transactions, the assets across the network, and the
transactions and also it include namespace. In my voting application, the participants
include candidate, election authority and voter. The transaction is the act of voting is
(Model.CTO).

1.3.1.1 Configure namespace

namespace om.oman.voting

1.3.1.2 Defined Participants

There are three participant in system include voter, candidate, and ElectionAuthority

participant voter identified by voterID {

o String voterID

o String fullName

o Integer age

o Nationality Nationality

o ElectionAuthorityCitizenApproval ElectionAuthorityCitizenApproval default='Requested'

enum ElectionAuthorityCitizenApproval {

o Requested

o Approved

o Rejected

enum Nationality{

o Omani

o NonOmani

participant candidate identified by candidateID {

o String candidateID

o String fullName
o Integer age

o Nationality Nationality

o Residance Residance

o Reputation Reputation

o Education Education

o Integer YearsOfExperience default=0

o ElectionAuthorityCitizenApproval ElectionAuthorityCitizenApproval default='Requested'

participant ElectionAuthority identified by ElectionAuthorityID {

o String ElectionAuthorityID

o String fullName

1.3.1.3 Defined asset

There are three asset in system include Election, Candidate Nomination, Election, and
vote Casting.

asset Election identified by ElectionID {

o String ElectionID

o String YearOfElection

o DateTime ElectionDate optional

o electionStatus electionStatus

enum electionStatus {

o Enabled

o Disabled

asset candidateNomination identified by candidateNominationID {

o String candidateNominationID
-->candidate candidate

o DateTime candidateApplyDate

--> Election Election

o NominationApproval NominationApproval

o DateTime NominationApproveRejectDate optional

o Integer totalVotes

enum NominationApproval {

o Request

o Approved

o Reject

asset voteCasting identified by voteCastingID {

o String voteCastingID

-->voter voter

-->candidateNomination candidateNomination

o DateTime VoteCastingDate

1.3.1.4 Defined System transaction

The transaction consist candidate request citizen and nomination, voter request citizen an
and voter cast vote, also election authority have to approved or rejected nomination.

transaction candidateNominationRequestTrans {

--> Election Election

o String candidateNominationID

o DateTime candidateApplyDate

-->candidate candidate
}

transaction electionAuthorityNominationApprovalTrans {

--> candidateNomination candidateNomination

o DateTime NominationApproveRejectDate

transaction electionAuthorityNominationRejectTrans {

--> candidateNomination candidateNomination

o DateTime NominationApproveRejectDate

transaction voteCastingTrans {

-->voter voter

-->candidateNomination candidateNomination

// -->voteCasting voteCasting optional

o String voteCastingID

o DateTime VoteCastingDate

transaction SetupDemo {

transaction voterCitizenRequestApprovalTrans {

--> voter voter

o ElectionAuthorityCitizenApproval ElectionAuthorityCitizenApproval

transaction candidateCitizenRequestApprovalTrans {

--> candidate candidate

o ElectionAuthorityCitizenApproval ElectionAuthorityCitizenApproval

}
1.3.2 The script file

The script file use JavaScript to define the actual e-voting system logic and functionality
of the voting application. For the voting application, the script file defines the voting
logic and rules. For instant, the election authority proves or rejects the nomination
candidate

async function candidateNominationRequestTrans(tx){

if (tx.candidate.ElectionAuthorityCitizenApproval != 'Approved') {

throw new Error('This candidate citizenship is not Approved');

if (tx.Election.electionStatus != 'Enabled') {

throw new Error('You cannot apply for Disabled election.');

const factory = getFactory();

const NS = 'om.oman.voting';

const candidateNomination = factory.newResource(NS, 'candidateNomination', tx.candidateNominationID);

candidateNomination.Election=tx.Election;

candidateNomination.candidate=tx.candidate;

candidateNomination.candidateApplyDate=tx.candidateApplyDate;

candidateNomination.NominationApproval='Request';

candidateNomination.totalVotes=0;

const registry = await getAssetRegistry(candidateNomination.getFullyQualifiedType());

const invokeCandidate = getCurrentParticipant();

const AssetRegistry = await getAssetRegistry('om.oman.voting.candidateNomination');

const candidatesApplied = await AssetRegistry.getAll();

let a=0;

// if there are record exists then do for loop

if (candidatesApplied.length > 0) {
for (let i = 0; i < candidatesApplied.length; i++) {

// check if the currently login candidate already requested for nomination

if (candidatesApplied[i].candidate.getIdentifier() === invokeCandidate.getIdentifier() &&


candidatesApplied[i].Election.getIdentifier() === tx.Election.getIdentifier() ) {

a=2;

if (a===0) {

// add candidateNomination row

await registry.add(candidateNomination);

else {

throw new Error('You already had applied for this election');

/**

* electionAuthorityNominationApprovalTrans Transactions

* @param {om.oman.voting.electionAuthorityNominationApprovalTrans} electionAuthorityNominationApprovalTrans

* @transaction

*/

async function electionAuthorityNominationApprovalTrans(tx){

if(tx.candidateNomination.candidate.Nationality != 'Omani'){

throw new Error('candidate must be Omani Natinality');

else if (tx.candidateNomination.candidate.age < 30) {


throw new Error('candidate must be of age 30 years or older');

} else if (tx.candidateNomination.candidate.Residance != 'Residant'){

throw new Error('candidate must be Residant of Oman');

else if (tx.candidateNomination.candidate.YearsOfExperience <= 0){

throw new Error('candidate must have some work experience');

else if (tx.candidateNomination.candidate.Reputition == 'Bad' || tx.candidateNomination.candidate.Reputition == 'Worst'){

throw new Error('candidate is not having good repution');

//elsif (!tx.candidateNomination.candidate.Residance == 'Residant')

tx.candidateNomination.NominationApproval='Approved';

tx.candidateNomination.NominationApproveRejectDate=tx.NominationApproveRejectDate;

const assetRegistry = await getAssetRegistry('om.oman.voting.candidateNomination');

await assetRegistry.update(tx.candidateNomination);

/**

* electionAuthorityNominationRejectTrans Transactions

* @param {om.oman.voting.electionAuthorityNominationRejectTrans} electionAuthorityNominationRejectTrans

* @transaction

*/

async function electionAuthorityNominationRejectTrans(tx){

tx.candidateNomination.NominationApproval='Reject';

tx.candidateNomination.NominationApproveRejectDate=tx.NominationApproveRejectDate;

const assetRegistry = await getAssetRegistry('om.oman.voting.candidateNomination');

await assetRegistry.update(tx.candidateNomination);
}

/**

* voteCasting Transaction

* @param {om.oman.voting.voteCastingTrans} voteCastingTrans

* @transaction

*/

async function voteCastingTrans(tx){

if (tx.voter.ElectionAuthorityCitizenApproval != 'Approved') {

throw new Error('This voter citizenship is not Approved');

if (tx.candidateNomination.Election.electionStatus != 'Enabled') {

throw new Error('You cannot vote for Disabled election.');

const factory = getFactory();

const NS = 'om.oman.voting';

const voteCasting = factory.newResource(NS, 'voteCasting', tx.voteCastingID);

voteCasting.voter=tx.voter;

voteCasting.candidateNomination=tx.candidateNomination;

voteCasting.VoteCastingDate=tx.VoteCastingDate;

const registry = await getAssetRegistry(voteCasting.getFullyQualifiedType());

const registry2 = await getAssetRegistry('om.oman.voting.voteCasting');

const invokeVoter = getCurrentParticipant();

const AssetRegistry = await getAssetRegistry('om.oman.voting.voteCasting');

const voteCasted = await AssetRegistry.getAll();

let a=0;

//console.log(tx.candidateNomination.getIdentifier());

// if (!voteCasted.length <= 0) {
// throw new Error('there is no voting yest');

// }

// if there are record exists then do for loop

if (voteCasted.length > 0) {

for (let i = 0; i < voteCasted.length; i++) {

// check if the currently login voter already casted the vote

if (voteCasted[i].voter.getIdentifier() === invokeVoter.getIdentifier() && voteCasted[i].candidateNomination.getIdentifier()


=== tx.candidateNomination.getIdentifier() ) {

//continue;

a=2;

if (a===0) {

// add voteCasting row

await registry.add(voteCasting);

// increment the candidate votes

tx.candidateNomination.totalVotes+=1;

// update the candidateNomination asset

const assetRegistry = await getAssetRegistry('om.oman.voting.candidateNomination');

await assetRegistry.update(tx.candidateNomination);

else {

alert("You already had casted your vote for this election");

/**

* electionAuthorityNominationRejectTrans Transactions
* @param {om.oman.voting.voterCitizenRequestApprovalTrans} voterCitizenRequestApprovalTrans

* @transaction

*/

async function voterCitizenRequestApprovalTrans(tx){

tx.voter.ElectionAuthorityCitizenApproval=tx.ElectionAuthorityCitizenApproval;

const voterRegistry = await getParticipantRegistry('om.oman.voting.voter');

await voterRegistry.update(tx.voter);

/**

* electionAuthorityNominationRejectTrans Transactions

* @param {om.oman.voting.candidateCitizenRequestApprovalTrans} candidateCitizenRequestApprovalTrans

* @transaction

*/

async function candidateCitizenRequestApprovalTrans(tx){

tx.candidate.ElectionAuthorityCitizenApproval=tx.ElectionAuthorityCitizenApproval;

const candidateRegistry = await getParticipantRegistry('om.oman.voting.candidate');

await candidateRegistry.update(tx.candidate);

Vous aimerez peut-être aussi