Class CodesManagerContract

java.lang.Object
it.unibo.ds.chainvote.contract.CodesManagerContract
All Implemented Interfaces:
org.hyperledger.fabric.contract.ContractInterface

public final class CodesManagerContract extends Object implements org.hyperledger.fabric.contract.ContractInterface

A Hyperledger Fabric contract to manage one-time-codes.

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
    generateCodeFor(org.hyperledger.fabric.contract.Context context, String electionId)
    Generate a new one-time-code for the given election and user.
    boolean
    invalidate(org.hyperledger.fabric.contract.Context context, String electionId)
    Invalidate the given code for the given election passed in a transient map.
    boolean
    isValid(org.hyperledger.fabric.contract.Context context, String electionId)
    Check if the given code is still valid, i.e.
    boolean
    verifyCodeOwner(org.hyperledger.fabric.contract.Context context, String electionId)
    Verifies if the given code has been generated for the given user and election passed in a transient map.

    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

    • CodesManagerContract

      public CodesManagerContract()
  • Method Details

    • generateCodeFor

      public String generateCodeFor(org.hyperledger.fabric.contract.Context context, String electionId)
      Generate a new one-time-code for the given election and user.
      Parameters:
      context - the transaction context. A transient map is expected with the following key-value pairs: userId adn seed.
      electionId - the election identifier
      Returns:
      a string representation of the generated one-time-code.
      Throws:
      org.hyperledger.fabric.shim.ChaincodeException - with:
      • INCORRECT_INPUT payload if the given election doesn't exist or the seed is blank
      • ALREADY_GENERATED_CODE payload if a code for the given election and user has already been generated
    • isValid

      public boolean isValid(org.hyperledger.fabric.contract.Context context, String electionId)
      Check if the given code is still valid, i.e. has not been consumed yet for the given election.
      Parameters:
      context - the transaction context. A transient map is expected with the following key-value entries: userId and code.
      electionId - the election identifier
      Returns:
      true if the given code is still valid, false otherwise.
    • invalidate

      public boolean invalidate(org.hyperledger.fabric.contract.Context context, String electionId)
      Invalidate the given code for the given election passed in a transient map. After calling this method the code can no longer be used.
      Parameters:
      context - the transaction context. A transient map is expected with the following key-value pairs: userId and code.
      electionId - the election identifier
      Returns:
      the result outcome.
      Throws:
      org.hyperledger.fabric.shim.ChaincodeException - with
      • ALREADY_INVALIDATED_CODE payload if the given code has already been invalidated
      • INCORRECT_INPUT payload if the given code is not valid anymore
    • verifyCodeOwner

      public boolean verifyCodeOwner(org.hyperledger.fabric.contract.Context context, String electionId)
      Verifies if the given code has been generated for the given user and election passed in a transient map.
      Parameters:
      context - the transaction context. A transient map is expected with the following key-value pairs: userId and code.
      electionId - the election identifier
      Returns:
      true if the given code is correct, false otherwise.