Skip to content

Commit

Permalink
stdlib: add script function to revote partial votes
Browse files Browse the repository at this point in the history
  • Loading branch information
nanne007 committed Jul 27, 2021
1 parent a6d936d commit 248228e
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 31 deletions.
Binary file modified vm/stdlib/compiled/latest/stdlib/34_Account.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/43_DaoVoteScripts.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions vm/stdlib/modules/DaoVoteScripts.move
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module DaoVoteScripts {
Dao::cast_vote<Token, ActionT>(&signer, proposer_address, proposal_id, votes, agree);
}

/// revoke all votes on a proposal
public ( script ) fun revoke_vote<Token: copy + drop + store, Action: copy + drop + store>(
signer: signer,
proposer_address: address,
Expand All @@ -32,6 +33,18 @@ module DaoVoteScripts {
Account::deposit(sender, my_token);
}

/// revoke some votes on a proposal
public ( script ) fun revoke_vote_of_power<Token: copy + drop + store, Action: copy + drop + store>(
signer: signer,
proposer_address: address,
proposal_id: u64,
power: u128,
) {
let sender = Signer::address_of(&signer);
let my_token = Dao::revoke_vote<Token, Action>(&signer, proposer_address, proposal_id, power);
Account::deposit(sender, my_token);
}

public ( script ) fun unstake_vote<Token: copy + drop + store, Action: copy + drop + store>(
signer: signer,
proposer_address: address,
Expand Down
34 changes: 3 additions & 31 deletions vm/stdlib/modules/doc/Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ The module for the account resource that governs every account
- [Function `create_account_with_address`](#0x1_Account_create_account_with_address)
- [Function `make_account`](#0x1_Account_make_account)
- [Function `create_signer`](#0x1_Account_create_signer)
- [Function `destroy_signer`](#0x1_Account_destroy_signer)
- [Function `create_account_with_initial_amount`](#0x1_Account_create_account_with_initial_amount)
- [Function `create_account_with_initial_amount_v2`](#0x1_Account_create_account_with_initial_amount_v2)
- [Function `deposit_to_self`](#0x1_Account_deposit_to_self)
Expand Down Expand Up @@ -793,7 +792,7 @@ Genesis authentication_key is zero bytes.
Release genesis account signer


<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_release_genesis_signer">release_genesis_signer</a>(genesis_account: signer)
<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_release_genesis_signer">release_genesis_signer</a>(_genesis_account: signer)
</code></pre>


Expand All @@ -802,8 +801,7 @@ Release genesis account signer
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_release_genesis_signer">release_genesis_signer</a>(genesis_account: signer){
<a href="Account.md#0x1_Account_destroy_signer">destroy_signer</a>(genesis_account);
<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_release_genesis_signer">release_genesis_signer</a>(_genesis_account: signer){
}
</code></pre>

Expand Down Expand Up @@ -862,7 +860,6 @@ reserved address for the MoveVM.
<a href="Account.md#0x1_Account_do_accept_token">do_accept_token</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(&new_account);
};
<a href="Account.md#0x1_Account_do_accept_token">do_accept_token</a>&lt;TokenType&gt;(&new_account);
<a href="Account.md#0x1_Account_destroy_signer">destroy_signer</a>(new_account);
}
</code></pre>

Expand Down Expand Up @@ -934,28 +931,6 @@ reserved address for the MoveVM.



</details>

<a name="0x1_Account_destroy_signer"></a>

## Function `destroy_signer`



<pre><code><b>fun</b> <a href="Account.md#0x1_Account_destroy_signer">destroy_signer</a>(sig: signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="Account.md#0x1_Account_destroy_signer">destroy_signer</a>(sig: signer);
</code></pre>



</details>

<a name="0x1_Account_create_account_with_initial_amount"></a>
Expand Down Expand Up @@ -1090,10 +1065,7 @@ It's a reverse operation of <code>withdraw_with_metadata</code>.
to_deposit: <a href="Token.md#0x1_Token">Token</a>&lt;TokenType&gt;,
metadata: vector&lt;u8&gt;,
) <b>acquires</b> <a href="Account.md#0x1_Account">Account</a>, <a href="Account.md#0x1_Account_Balance">Balance</a> {
// Check that the `to_deposit` token is non-zero
<b>let</b> deposit_value = <a href="Token.md#0x1_Token_value">Token::value</a>(&to_deposit);
<b>assert</b>(deposit_value &gt; 0, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Account.md#0x1_Account_ECOIN_DEPOSIT_IS_ZERO">ECOIN_DEPOSIT_IS_ZERO</a>));

// Deposit the `to_deposit` token
<a href="Account.md#0x1_Account_deposit_to_balance">deposit_to_balance</a>&lt;TokenType&gt;(borrow_global_mut&lt;<a href="Account.md#0x1_Account_Balance">Balance</a>&lt;TokenType&gt;&gt;(receiver), to_deposit);

Expand Down Expand Up @@ -2203,7 +2175,7 @@ It collects gas and bumps the sequence number
### Function `release_genesis_signer`


<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_release_genesis_signer">release_genesis_signer</a>(genesis_account: signer)
<pre><code><b>public</b> <b>fun</b> <a href="Account.md#0x1_Account_release_genesis_signer">release_genesis_signer</a>(_genesis_account: signer)
</code></pre>


Expand Down
34 changes: 34 additions & 0 deletions vm/stdlib/modules/doc/DaoVoteScripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

- [Function `cast_vote`](#0x1_DaoVoteScripts_cast_vote)
- [Function `revoke_vote`](#0x1_DaoVoteScripts_revoke_vote)
- [Function `revoke_vote_of_power`](#0x1_DaoVoteScripts_revoke_vote_of_power)
- [Function `unstake_vote`](#0x1_DaoVoteScripts_unstake_vote)
- [Specification](#@Specification_0)

Expand Down Expand Up @@ -54,6 +55,7 @@

## Function `revoke_vote`

revoke all votes on a proposal


<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="DaoVoteScripts.md#0x1_DaoVoteScripts_revoke_vote">revoke_vote</a>&lt;<a href="Token.md#0x1_Token">Token</a>: <b>copy</b>, drop, store, Action: <b>copy</b>, drop, store&gt;(signer: signer, proposer_address: address, proposal_id: u64)
Expand All @@ -79,6 +81,38 @@



</details>

<a name="0x1_DaoVoteScripts_revoke_vote_of_power"></a>

## Function `revoke_vote_of_power`

revoke some votes on a proposal


<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="DaoVoteScripts.md#0x1_DaoVoteScripts_revoke_vote_of_power">revoke_vote_of_power</a>&lt;<a href="Token.md#0x1_Token">Token</a>: <b>copy</b>, drop, store, Action: <b>copy</b>, drop, store&gt;(signer: signer, proposer_address: address, proposal_id: u64, power: u128)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> ( <b>script</b> ) <b>fun</b> <a href="DaoVoteScripts.md#0x1_DaoVoteScripts_revoke_vote_of_power">revoke_vote_of_power</a>&lt;<a href="Token.md#0x1_Token">Token</a>: <b>copy</b> + drop + store, Action: <b>copy</b> + drop + store&gt;(
signer: signer,
proposer_address: address,
proposal_id: u64,
power: u128,
) {
<b>let</b> sender = <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(&signer);
<b>let</b> my_token = <a href="Dao.md#0x1_Dao_revoke_vote">Dao::revoke_vote</a>&lt;<a href="Token.md#0x1_Token">Token</a>, Action&gt;(&signer, proposer_address, proposal_id, power);
<a href="Account.md#0x1_Account_deposit">Account::deposit</a>(sender, my_token);
}
</code></pre>



</details>

<a name="0x1_DaoVoteScripts_unstake_vote"></a>
Expand Down

0 comments on commit 248228e

Please sign in to comment.