Skip to content
wowok-ai edited this page May 15, 2024 · 1 revision

Vote provides collective decision-making data for the wowok protocol.

Definition

struct Vote has key {
    id: UID,
    description: String,
    // Options: what object to vote for
    reference: Option<address>, 
    // Voting deadline
    deadline: u64, 
    // Voting weights; key-value pairs of guard id and weight; if not set, any address can vote with a weight of 1
    guard: VecMap<address, u64>, 
    // Voting options, key-value pairs of voting option names and information
    agrees: VecMap<String, Result>,
    // Addresses that have voted, key-value pairs of voting addresses and weights
    voted: Table<address, u64>,  
    // Whether to lock the vote, once locked the vote will not be editable
    bOptions_locked_for_voting: bool, 
    // Whether to lock the vote.deadline, once locked it will not be extendable
    bdeadline_locked: bool,
    // Whether to lock the vote.guard, once locked it will not be editable
    bLockedGuard: bool, 
    // The maximum number of vote.agrees that can be voted at one time, default is 1
    max_choice_count: u8, 
    // Permission table
    permission: address, 
}

// Voting Option Information
struct Result has store, copy, drop {
    // The object that the option can be voted for
    forWhat: Option<address>, // vote for what, used for arbitration
    // Total number of votes received
    votes: u64, 
    // Number of times voted
    count: u64, 
}

// Maximum number of voting options
const MAX_AGREES_COUNT: u64 = 200;
// Maximum number of choices for a multiple-choice vote
const MAX_CHOICE_COUNT: u64 = 200;

Operations

Launch vote (shared object)

create(vote: Vote) : address

Vote

vote(vote:&mut Vote, agrees: vector<String>, ctx:&mut TxContext) 

Vote; if the passport does not match a Guard in vote.guard, return false

vote_with_passport(passport:&mut Passport, vote:&mut Vote, agrees: vector<String>, ctx:&mut TxContext) : bool  

Set a new permission. The operation permission must satisfy being the builder of the old permission.

permission_set(vote: &mut Vote, old: &Permission, new: &Permission, ctx: &mut TxContext)

[Permission index: 150] Creat a new Vote

new(description: String, reference: Option<address>, clock: &Clock, minutes_duration: u64, max_choice_count: u8, permission: &Permission, ctx: &mut TxContext) : Vote

[Permission index: 151] Set description

description_set(vote: &mut Vote, description: String, permission: &Permission, ctx: &mut TxContext)

[Permission index: 152] Set the voting reference object

reference_set(vote: &mut Vote, reference: Option<address>, permission: &Permission, ctx: &mut TxContext)

[Permission index: 153] Set guard and corresponding voting weight

guard_add(vote: &mut Vote, guard: &Guard, vote_weight: u64, permission: &Permission, ctx: &mut TxContext)

[Permission index: 154] Remove guard

guard_remove(vote: &mut Vote, guard: vector<address>, permission: &Permission, ctx: &mut TxContext)
guard_remove_all(vote: &mut Vote, permission: &Permission, ctx: &mut TxContext)

[Permission index: 155] Add voting option

agrees_add(vote: &mut Vote, agree: String, forWhat: Option<address>, permission: &Permission, ctx: &mut TxContext)

[Permission index: 156] Remove voting option

agrees_remove(vote: &mut Vote, agrees: vector<String>, permission: &Permission, ctx: &mut TxContext)
agrees_remove_all(vote: &mut Vote, permission: &Permission, ctx: &mut TxContext)

[Permission index: 157] Set the maximum number of multiple-choice votes

max_choice_count_set(vote: &mut Vote, max_choice_count: u8, permission: &Permission, ctx: &mut TxContext)

[Permission index: 158] Lock the vote, making it non-editable and starting the voting

options_locked_for_voting(vote: &mut Vote, permission: &Permission, ctx: &mut TxContext)

[Permission index: 159] Lock vote.deadline, making it non-extendable

deadline_locked(vote: &mut Vote, clock: &Clock, permission: &Permission, ctx: &mut TxContext)

[Permission index: 160] Extend vote.deadline time

deadline_expand(vote: &mut Vote, minutes_expand: u64, permission: &Permission, ctx: &mut TxContext)

[Permission index: 161] Lock vote.guard, making it non-editable

guard_locked(vote: &mut Vote, permission: &Permission, ctx: &mut TxContext)

Operations with passport

new_with_passport(passport:&mut Passport, description:String, reference: Option<address>, clock:&Clock, minutes_duration:u64, max_choice_count:u8, permission:&Permission, ctx:&mut TxContext) : Vote
description_set_with_passport(passport:&mut Passport, vote:&mut Vote, description:String, permission:&Permission, ctx:&mut TxContext) 
reference_set_with_passport(passport:&mut Passport, vote:&mut Vote, reference: Option<address>, permission:&Permission, ctx:&mut TxContext) 
guard_add_with_passport(passport:&mut Passport, vote:&mut Vote, guard:&Guard, vote_weight:u64, permission:&Permission, ctx:&mut TxContext)
guard_remove_with_passport(passport:&mut Passport, vote:&mut Vote, guard:vector<address>, permission:&Permission, ctx:&mut TxContext)
guard_remove_all_with_passport(passport:&mut Passport, vote:&mut Vote, permission:&Permission, ctx:&mut TxContext)
agrees_add_with_passport(passport:&mut Passport, vote:&mut Vote, agree:String, forWhat:Option<address>, permission:&Permission, ctx:&mut TxContext) 
agrees_remove_with_passport(passport:&mut Passport, vote:&mut Vote, agrees:vector<String>, permission:&Permission, ctx:&mut TxContext) 
agrees_remove_all_with_passport(passport:&mut Passport, vote:&mut Vote, permission:&Permission, ctx:&mut TxContext)  
max_choice_count_set_with_passport(passport:&mut Passport, vote:&mut Vote, max_choice_count:u8, permission:&Permission, ctx:&mut TxContext)
options_locked_for_voting_with_passport(passport:&mut Passport, vote:&mut Vote, permission:&Permission, ctx:&mut TxContext)
deadline_locked_with_passport(passport:&mut Passport, vote:&mut Vote, clock:&Clock, permission:&Permission, ctx:&mut TxContext)
deadline_expand_with_passport(passport:&mut Passport, vote:&mut Vote, minutes_expand:u64, permission:&Permission, ctx:&mut TxContext) 
guard_locked_with_passport(passport:&mut Passport, vote:&mut Vote, permission:&Permission, ctx:&mut TxContext) 

On-chain query for Guard

[Query: 1] Vote permission [address]; input: none

[Query: 2] Vote.bOptions_locked_for_voting[bool]; input: none

[Query: 3] Vote.bdeadline_locked[bool]; input: none

[Query: 4] Vote.bLockedGuard[bool]; input: none

[Query: 5] Vote.max_choice_count[u8]; input: none

[Query: 6] Vote.deadline[u64]; input: none

[Query: 7] Whether vote.reference is set[bool]. input: none

[Query: 8] Vote.reference[address]; Requires [Query: 7]; input: none

[Query: 9] Whether vote guard is set to a certain Guard[bool]; input: guard id[address]

[Query: 10] Weight of voting corresponding to a certain guard[u64]; Requires [Query: 9]; input: guard id[address]

[Query: 11] Whether a certain address has participated in the vote[bool]; input: User address[address]

[Query: 12] Weight of vote completion for a certain address[u64]; Requires [Query: 11]. input: User address[address]

[Query: 13] Whether vote.agrees exists for a certain voting option[bool]; input: Voting option name[string]

[Query: 14] Whether the voting option contains a referenced object[bool]; Requires [Query: 13]; input: Voting option name[string]

[Query: 15] Address of the referenced object of the voting option; Requires [Query: 13] and [Query: 14]. input: Voting option name[string]

[Query: 16] Number of votes received by an option[u64]; input: Voting option name[string]

[Query: 17] Number of votes received by an option[u64]; input: Voting option name[string]

[Query: 18] Number of participants in the vote[u64]; input: none

[Query: 19] Name of the option ranked first by number of votes[u64]; input: none

[Query: 20] Number of votes received by the option ranked first by number of votes[u64]; input: none

[Query: 21] Name of the option ranked first by number of votes[u64]; input: none

[Query: 22] Number of votes received by the option ranked first by number of votes[u64]; input: none

Errors

105000: Vote is locked, voting is open, cannot be edited
105002: Maximum number of options reached
105004: Vote guard is locked, cannot be modified
105006: Vote deadline is locked, cannot be modified
105008: Vote agrees has no options
105010: Voting deadline has passed
105012: Invalid voting option
105014: Voting weight must be greater than 0
165022: Address has already completed voting
165024: No votes have been generated yet
165026: Single vote count is too high
165028: Voting has not been enabled