Opinion Module

class hivemind.opinion.HivemindOpinion(cid: str | None = None)[source]

Bases: IPFSDict

A class representing a voter’s opinion in the Hivemind protocol.

This class handles the storage and management of a voter’s ranked choices for a particular hivemind issue question.

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

  • question_index (int) – The index of the question this opinion is for

  • ranking (Ranking) – The ranking of options for this opinion

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

Initialize a new HivemindOpinion.

Parameters:

cid (str | None) – The IPFS hash of the Opinion object

Returns:

None

info() str[source]

Get the details of this Opinion object in string format.

Returns:

Formatted string containing the opinion details

Return type:

str

load(cid: str) None[source]

Load the opinion from IPFS.

This method handles the conversion of the stored ranking dictionary back into a Ranking object.

Parameters:

cid (str) – The IPFS hash to load

Returns:

None

save() str[source]

Save the opinion to IPFS.

This method handles the conversion of the Ranking object into a JSON-serializable dictionary before saving the opinion to IPFS.

Returns:

The IPFS hash of the saved opinion

Return type:

str

set_question_index(question_index: int) None[source]

Set the question index for this opinion.

Parameters:

question_index (int) – The index of the question

Returns:

None

to_dict() Dict[str, Any][source]

Get a JSON-serializable representation of this opinion.

Returns:

Dictionary containing the opinion data

Return type:

Dict[str, Any]