Package it.unibo.ds.chainvote.contract
Class ElectionInfoContract
java.lang.Object
it.unibo.ds.chainvote.contract.ElectionInfoContract
- All Implemented Interfaces:
org.hyperledger.fabric.contract.ContractInterface
public final class ElectionInfoContract
extends Object
implements org.hyperledger.fabric.contract.ContractInterface
A Hyperledger Fabric contract to manage ElectionInfo.
The API Gateway client will receive the transaction returned values wrapped inside a Response json object .
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionit.unibo.ds.chainvote.elections.ElectionInfocreateElectionInfo(org.hyperledger.fabric.contract.Context ctx, String goal, Long votersNumber, String sDate, String eDate, List<it.unibo.ds.chainvote.utils.Choice> choices) Create aElectionInfo.it.unibo.ds.chainvote.elections.ElectionInfodeleteElectionInfo(org.hyperledger.fabric.contract.Context ctx, String electionId) Delete anElectionInfofrom the ledger.List<it.unibo.ds.chainvote.elections.ElectionInfo>getAllElectionInfo(org.hyperledger.fabric.contract.Context ctx) Return all the existingElectionInfos.it.unibo.ds.chainvote.elections.ElectionInforeadElectionInfo(org.hyperledger.fabric.contract.Context ctx, String electionId) Return theElectionInfo.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hyperledger.fabric.contract.ContractInterface
afterTransaction, beforeTransaction, createContext, unknownTransaction
-
Constructor Details
-
ElectionInfoContract
public ElectionInfoContract()
-
-
Method Details
-
createElectionInfo
public it.unibo.ds.chainvote.elections.ElectionInfo createElectionInfo(org.hyperledger.fabric.contract.Context ctx, String goal, Long votersNumber, String sDate, String eDate, List<it.unibo.ds.chainvote.utils.Choice> choices) Create aElectionInfo. Expected JSON input in the following format:{ "function": "ElectionInfoContract:createElectionInfo", "Args": [ "your_goal", n, "yyyy-MM-ddThh:mm:ss", "yyyy-MM-ddThh:mm:ss", [{"choice":"your_choice1"},{"choice":"your_choice2"}*[,{"choice":"your_choiceN"}]] ] }Constraints: n > 1, String must be non-empty.- Parameters:
ctx- theContext.goal- the goal of theElectionInfoto build.votersNumber- the number of voters that could cast a vote in theElectionInfoto build.sDate- theStringrepresenting the encoded (ISO format) start date.eDate- theStringrepresenting the encoded (ISO format) end date.choices- theListofChoicethat theElectionInfoto build has. TheListmust contains at least two differentChoices different from theFixedVotes.INFORMAL_BALLOT. IfFixedVotes.INFORMAL_BALLOTis not present, it will be added by the system.- Returns:
- the
ElectionInfobuilt. - Throws:
org.hyperledger.fabric.shim.ChaincodeException- with-
ELECTION_INFO_ALREADY_EXISTSas payload if it has already been created anElectionInfowith same arguments INVALID_ARGUMENTas payload if at least one of the given arguments is not valid
-
-
readElectionInfo
public it.unibo.ds.chainvote.elections.ElectionInfo readElectionInfo(org.hyperledger.fabric.contract.Context ctx, String electionId) Return theElectionInfo. Expected JSON input in the following format:{ "function": "ElectionInfoContract:readElectionInfo", "Args": [ "your_election_id" ] }Constraints: String must be non-empty.- Parameters:
ctx- theContext.electionId- the electionId of theElectionInfoto retrieve.- Returns:
- the
ElectionInfo. - Throws:
org.hyperledger.fabric.shim.ChaincodeException- withELECTION_INFO_NOT_FOUNDas payload if noElectionInfois labeled by the given electionId.
-
deleteElectionInfo
public it.unibo.ds.chainvote.elections.ElectionInfo deleteElectionInfo(org.hyperledger.fabric.contract.Context ctx, String electionId) Delete anElectionInfofrom the ledger. Expected JSON input in the following format:{ "function": "ElectionInfoContract:deleteElectionInfo", "Args": [ "your_election_id", ] }Constraints: String must be non-empty.- Parameters:
ctx- theContext.electionId- the electionId of theElectionInfoto delete.- Returns:
- the
ElectionInfodeleted. - Throws:
org.hyperledger.fabric.shim.ChaincodeException- withELECTION_INFO_NOT_FOUNDas payload if there isn't anElectionInfolabeled by the given electionId.
-
getAllElectionInfo
public List<it.unibo.ds.chainvote.elections.ElectionInfo> getAllElectionInfo(org.hyperledger.fabric.contract.Context ctx) Return all the existingElectionInfos. Expected JSON input in the following format:{ "function": "ElectionInfoContract:getAllElectionInfo", "Args": [] }- Parameters:
ctx- theContext.- Returns:
- all the
ElectionInfos retrieved from the ledger asList.
-