Option Module

class hivemind.option.HivemindOption(cid: str | None = None)[source]

Bases: IPFSDict

A class representing a voting option in the Hivemind protocol.

This class handles the creation and validation of voting options, supporting various types of answers including strings, booleans, integers, floats, and complex types.

Variables:
  • value (str | bool | int | float | Dict[str, Any] | None) – The value of the option

  • text (str) – Additional text description of the option

  • _hivemind_issue (HivemindIssue | None) – The associated hivemind issue

  • _answer_type (str) – Type of the answer (‘String’, ‘Bool’, ‘Integer’, etc.)

  • hivemind_id (str | None) – The IPFS hash of the associated hivemind issue

__init__(cid: str | None = None) None[source]

Initialize a new HivemindOption.

Parameters:

cid (str | None) – The IPFS multihash of the Option

Returns:

None

static _is_valid_ipfs_hash(hash_str: str) bool[source]

Check if a string is a valid IPFS hash.

Parameters:

hash_str (str) – The string to check

Returns:

True if valid, False otherwise

Return type:

bool

cid() str | None[source]

Get the IPFS CID of this option.

Returns:

The IPFS CID

Return type:

str | None

get_answer_type() str[source]

Get the answer type of the option.

Returns:

The answer type

Return type:

str

info() str[source]

Get information about the option.

Returns:

A string containing formatted information about the option

Return type:

str

is_valid_address_option() bool[source]

Check if the option is a valid address option.

Returns:

True if valid, False otherwise

Return type:

bool

is_valid_bool_option() bool[source]

Check if the option is a valid boolean option.

Returns:

True if valid, False otherwise

Return type:

bool

is_valid_complex_option() bool[source]

Check if the option is a valid complex option according to the specifications in the constraints.

Returns:

True if valid, False otherwise

Return type:

bool

is_valid_file_option() bool[source]

Check if the option is a valid file option.

Returns:

True if valid, False otherwise

Return type:

bool

is_valid_float_option() bool[source]

Check if the option is a valid float option.

Returns:

True if valid, False otherwise

Return type:

bool

is_valid_hivemind_option() bool[source]

Check if the option is a valid hivemind option.

Returns:

True if valid, False otherwise

Return type:

bool

is_valid_integer_option() bool[source]

Check if the option is a valid integer option.

Returns:

True if valid, False otherwise

Return type:

bool

is_valid_string_option() bool[source]

Check if the option is a valid string option.

Returns:

True if valid, False otherwise

Return type:

bool

load(cid: str) None[source]

Load the option from IPFS.

Parameters:

cid (str) – The IPFS multihash to load

Returns:

None

set(value: str | bool | int | float | Dict[str, Any]) None[source]

Set the value of this option.

Parameters:

value (str | bool | int | float | Dict[str, Any]) – The value to set

Raises:

Exception – If the value is invalid for the answer type

Returns:

None

set_issue(hivemind_issue_cid: str) None[source]

Set the hivemind issue for this option.

Parameters:

hivemind_issue_cid (str) – The IPFS hash of the hivemind issue

Returns:

None

valid() bool[source]

Check if the option is valid according to its type and constraints.

Returns:

True if valid, False otherwise

Return type:

bool

Raises:

Exception – If no hivemind issue is set or if constraints are violated