Code

The Code for Decentralized Decisions provides several software structures for voting and autonomous governance.

Python

The main programming language used for Decentralized Decisions development is Python. Python is a general purpose interpreted programming language. However, other languages such as JavaScript may also be used for variations of the software.

Hash Function

# Hash function to secure data using quantum secure hash. 
def hash(item):
    # Assumes the default UTF-8.
    # This encodes the string with the SHA-512 scheme.
    hash_object = hashlib.sha512(item.encode()) 
    # This returns the hexadecimal encode as a string.
    item = hash_object.hexdigest() 
    return item

The hash function converts a string to a secure code using the SHA-512 cryptographic scheme. SHA-512 is a post-quantum cryptographic scheme, thus ensuring that private information is made secure from malicious attackers.

Vote Functions

# The voting function allows the decision to happen.
def choice_vote(sender, key, receiver,amount,comment):
    parameters = algod_client.suggested_params() # Sets suggested parameters
    transaction = AssetTransferTxn(sender, parameters, receiver, amount, choice_id,note=comment)
    # Defines an inital transaction for Choice Coin
    signature = transaction.sign(key)
    # Signs the transaction with the senders private key
    algod_client.send_transaction(signature)
    # Sends the transaction with the signature
    final = transaction.get_txid()
    return True, final

The choice_vote function defines a stateless smart contract on the Algorand Network. It sends Choice Coin to the appropriate destination address based on user input.

Here, the vote function uses a simple binary to send one Choice to an address with a positive vote, or takes no action with a negative vote. The amount is set to 100 to account for the two decimals places associate with the Choice asset. Below is another vote function, which uses two addresses instead of one.

Here, each option has an associated address. This allows for a simple count of each address to determine the total number of votes.

Results Functions

This function counts the total number of votes to return a statement regarding which candidate has won. This model may apply to both corporate or electoral voting.

Here, the check_results function checks the amount the asset in the account, to determine the total number of votes for the particular address.

Links

Decentralized Decisions GitHub: https://github.com/ChoiceCoin/Voting

Decentralized Decisions White Paper: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3913316

Python GitHub: https://github.com/python

Last updated