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
-
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.boolean
invalidate
(org.hyperledger.fabric.contract.Context context, String electionId) Invalidate the given code for the given election passed in a transient map.boolean
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
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
adnseed
.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 blankALREADY_GENERATED_CODE
payload 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:userId
andcode
.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:userId
andcode
.electionId
- the election identifier- Returns:
- the result outcome.
- Throws:
org.hyperledger.fabric.shim.ChaincodeException
- withALREADY_INVALIDATED_CODE
payload if the given code has already been invalidatedINCORRECT_INPUT
payload 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:userId
andcode
.electionId
- the election identifier- Returns:
- true if the given code is correct, false otherwise.
-