Issue Module
- class hivemind.issue.HivemindIssue(cid: str | None = None)[source]
Bases:
IPFSDict
A class representing a voting issue in the Hivemind protocol.
This class handles the creation and management of voting issues, including questions, constraints, and restrictions on who can vote.
- Variables:
questions (List[str]) – List of questions associated with this issue
name (str | None) – Name of the issue
description (str) – Description of the issue
tags (List[str]) – List of tags associated with this issue
answer_type (str) – Type of answer expected (‘String’, ‘Integer’, ‘Float’, ‘Bool’, ‘Hivemind’, ‘File’, ‘Complex’, ‘Address’)
constraints (Dict[str, str | int | float | list] | None) – Constraints on voting
restrictions (Dict[str, List[str] | int] | None) – Restrictions on who can vote
on_selection (str | None) – Action to take when an option is selected
author (str | None) – Bitcoin address of the author who can finalize the hivemind
- __init__(cid: str | None = None) None [source]
Initialize a new HivemindIssue.
- Parameters:
cid (str | None) – The IPFS multihash of the hivemind issue
- Returns:
None
- add_question(question: str) None [source]
Add a question to the hivemind issue.
- Parameters:
question (str) – The question text to add
- Returns:
None
- Raises:
ValueError – If question is invalid or already exists
- get_identification_cid(name: str) str [source]
Get the identification CID so that a participant can self-identify for this issue.
Creates an IPFS dictionary containing the hivemind ID and participant name, then saves it to IPFS and returns the resulting CID.
- save() str [source]
Save the hivemind issue to IPFS.
Validates the issue before saving to ensure it meets all requirements.
- set_constraints(constraints: Dict[str, str | int | float | list] | None) None [source]
Set constraints for the hivemind issue.
Constraints can include various limitations on the answers, such as: - min_length/max_length: For string answers - min_value/max_value: For numeric answers - decimals: For float answers - regex: For string pattern validation - true_value/false_value: For boolean answers - specs: For complex answer types - choices: For predefined answer options - block_height: For blockchain-related constraints - filetype: For file answer types
- set_restrictions(restrictions: Dict[str, List[str] | int] | None) None [source]
Set voting restrictions for the hivemind issue.
Restrictions can include: - addresses: List of Bitcoin addresses allowed to vote - options_per_address: Maximum number of options each address can submit
- valid() bool [source]
Check if the hivemind issue is valid.
Validates all properties of the issue including: - name: Must be a non-empty string ≤ 50 characters - description: Must be a string ≤ 5000 characters - tags: Must be a list of unique strings without spaces, each ≤ 20 characters - questions: Must be a non-empty list of unique strings, each ≤ 255 characters - answer_type: Must be one of the allowed types - on_selection: Must be one of the allowed values