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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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 a ElectionInfo.
    it.unibo.ds.chainvote.elections.ElectionInfo
    deleteElectionInfo(org.hyperledger.fabric.contract.Context ctx, String electionId)
    Delete an ElectionInfo from the ledger.
    List<it.unibo.ds.chainvote.elections.ElectionInfo>
    getAllElectionInfo(org.hyperledger.fabric.contract.Context ctx)
    Return all the existing ElectionInfos.
    it.unibo.ds.chainvote.elections.ElectionInfo
    readElectionInfo(org.hyperledger.fabric.contract.Context ctx, String electionId)
    Return the ElectionInfo.

    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 a ElectionInfo. 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 - the Context.
      goal - the goal of the ElectionInfo to build.
      votersNumber - the number of voters that could cast a vote in the ElectionInfo to build.
      sDate - the String representing the encoded (ISO format) start date.
      eDate - the String representing the encoded (ISO format) end date.
      choices - the List of Choice that the ElectionInfo to build has. The List must contains at least two different Choices different from the FixedVotes.INFORMAL_BALLOT. If FixedVotes.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 an ElectionInfo 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 the ElectionInfo. Expected JSON input in the following format:
       {
            "function": "ElectionInfoContract:readElectionInfo",
            "Args": [
                "your_election_id"
            ]
       }
       
      Constraints: String must be non-empty.
      Parameters:
      ctx - the Context.
      electionId - the electionId of the ElectionInfo to retrieve.
      Returns:
      the ElectionInfo.
      Throws:
      org.hyperledger.fabric.shim.ChaincodeException - with ELECTION_INFO_NOT_FOUND as payload if no ElectionInfo is labeled by the given electionId.
    • deleteElectionInfo

      public it.unibo.ds.chainvote.elections.ElectionInfo deleteElectionInfo(org.hyperledger.fabric.contract.Context ctx, String electionId)
      Delete an ElectionInfo 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 - the Context.
      electionId - the electionId of the ElectionInfo to delete.
      Returns:
      the ElectionInfo deleted.
      Throws:
      org.hyperledger.fabric.shim.ChaincodeException - with ELECTION_INFO_NOT_FOUND as payload if there isn't an ElectionInfo labeled by the given electionId.
    • getAllElectionInfo

      public List<it.unibo.ds.chainvote.elections.ElectionInfo> getAllElectionInfo(org.hyperledger.fabric.contract.Context ctx)
      Return all the existing ElectionInfos. Expected JSON input in the following format:
       {
            "function": "ElectionInfoContract:getAllElectionInfo",
            "Args": []
       }
       
      Parameters:
      ctx - the Context.
      Returns:
      all the ElectionInfos retrieved from the ledger as List.