Package it.unibo.ds.chainvote.contract
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 -
Method Summary
Modifier and TypeMethodDescriptiongenerateCodeFor(org.hyperledger.fabric.contract.Context context, String electionId) Generate a new one-time-code for the given election and user.booleaninvalidate(org.hyperledger.fabric.contract.Context context, String electionId) Invalidate the given code for the given election passed in a transient map.booleanCheck if the given code is still valid, i.e.booleanverifyCodeOwner(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, waitMethods inherited from interface org.hyperledger.fabric.contract.ContractInterface
afterTransaction, beforeTransaction, createContext, unknownTransaction
-
Constructor Details
-
CodesManagerContract
public CodesManagerContract()
-
-
Method Details
-
generateCodeFor
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:userIdadnseed.electionId- the election identifier- Returns:
- a string representation of the generated one-time-code.
- Throws:
org.hyperledger.fabric.shim.ChaincodeException- with:INCORRECT_INPUTpayload if the given election doesn't exist or the seed is blankALREADY_GENERATED_CODEpayload if a code for the given election and user has already been generated
-
isValid
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:userIdandcode.electionId- the election identifier- Returns:
- true if the given code is still valid, false otherwise.
-
invalidate
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:userIdandcode.electionId- the election identifier- Returns:
- the result outcome.
- Throws:
org.hyperledger.fabric.shim.ChaincodeException- withALREADY_INVALIDATED_CODEpayload if the given code has already been invalidatedINCORRECT_INPUTpayload if the given code is not valid anymore
-
verifyCodeOwner
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:userIdandcode.electionId- the election identifier- Returns:
- true if the given code is correct, false otherwise.
-