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
-
Method Summary
Modifier and TypeMethodDescriptionit.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
.it.unibo.ds.chainvote.elections.ElectionInfo
deleteElectionInfo
(org.hyperledger.fabric.contract.Context ctx, String electionId) Delete anElectionInfo
from the ledger.List<it.unibo.ds.chainvote.elections.ElectionInfo>
getAllElectionInfo
(org.hyperledger.fabric.contract.Context ctx) Return all the existingElectionInfo
s.it.unibo.ds.chainvote.elections.ElectionInfo
readElectionInfo
(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, wait
Methods 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 theElectionInfo
to build.votersNumber
- the number of voters that could cast a vote in theElectionInfo
to build.sDate
- theString
representing the encoded (ISO format) start date.eDate
- theString
representing the encoded (ISO format) end date.choices
- theList
ofChoice
that theElectionInfo
to build has. TheList
must contains at least two differentChoice
s different from theFixedVotes.INFORMAL_BALLOT
. IfFixedVotes.INFORMAL_BALLOT
is not present, it will be added by the system.- Returns:
- the
ElectionInfo
built. - Throws:
org.hyperledger.fabric.shim.ChaincodeException
- with-
ELECTION_INFO_ALREADY_EXISTS
as payload if it has already been created anElectionInfo
with same arguments INVALID_ARGUMENT
as 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 theElectionInfo
to retrieve.- Returns:
- the
ElectionInfo
. - Throws:
org.hyperledger.fabric.shim.ChaincodeException
- withELECTION_INFO_NOT_FOUND
as payload if noElectionInfo
is labeled by the given electionId.
-
deleteElectionInfo
public it.unibo.ds.chainvote.elections.ElectionInfo deleteElectionInfo(org.hyperledger.fabric.contract.Context ctx, String electionId) Delete anElectionInfo
from 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 theElectionInfo
to delete.- Returns:
- the
ElectionInfo
deleted. - Throws:
org.hyperledger.fabric.shim.ChaincodeException
- withELECTION_INFO_NOT_FOUND
as payload if there isn't anElectionInfo
labeled by the given electionId.
-
getAllElectionInfo
public List<it.unibo.ds.chainvote.elections.ElectionInfo> getAllElectionInfo(org.hyperledger.fabric.contract.Context ctx) Return all the existingElectionInfo
s. Expected JSON input in the following format:{ "function": "ElectionInfoContract:getAllElectionInfo", "Args": [] }
- Parameters:
ctx
- theContext
.- Returns:
- all the
ElectionInfo
s retrieved from the ledger asList
.
-