Skip to content

Commit

Permalink
[stdlib] modify error_code for voted to others already (#1642)
Browse files Browse the repository at this point in the history
* [stdlib] modify error_code for voted to others already

* [stdlib] update genesis and compile stdlib

* [stdlib] update genesis

Co-authored-by: tiangong3624749 <tiangong3624749@163.com>
  • Loading branch information
ssyuan and tiangong3624749 authored Nov 13, 2020
1 parent 340b593 commit ae829ad
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
Binary file modified core/genesis/generated/halley/genesis
Binary file not shown.
Binary file modified core/genesis/generated/main/genesis
Binary file not shown.
Binary file modified core/genesis/generated/proxima/genesis
Binary file not shown.
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/18_Dao.mv
Binary file not shown.
11 changes: 6 additions & 5 deletions vm/stdlib/modules/Dao.move
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ module Dao {
const ERR_CONFIG_PARAM_INVALID: u64 = 1407;
const ERR_VOTE_STATE_MISMATCH: u64 = 1408;
const ERR_ACTION_MUST_EXIST: u64 = 1409;
const ERR_VOTED_OTHERS_ALREADY: u64 = 1410;

/// plugin function, can only be called by token issuer.
/// Any token who wants to has gov functionality
Expand Down Expand Up @@ -271,7 +272,7 @@ module Dao {
let sender = Signer::address_of(signer);
let total_voted = if (exists<Vote<TokenT>>(sender)) {
let my_vote = borrow_global_mut<Vote<TokenT>>(sender);
assert(my_vote.id == proposal_id, Errors::invalid_argument(ERR_PROPOSAL_ID_MISMATCH));
assert(my_vote.id == proposal_id, Errors::invalid_argument(ERR_VOTED_OTHERS_ALREADY));
assert(my_vote.agree == agree, Errors::invalid_state(ERR_VOTE_STATE_MISMATCH));

_cast_vote(proposal, my_vote, stake);
Expand Down Expand Up @@ -372,7 +373,7 @@ module Dao {
let my_vote = borrow_global_mut<Vote<TokenT>>(Signer::address_of(signer));
{
assert(my_vote.proposer == proposer_address, Errors::invalid_argument(ERR_PROPOSER_MISMATCH));
assert(my_vote.id == proposal_id, Errors::invalid_argument(ERR_PROPOSAL_ID_MISMATCH));
assert(my_vote.id == proposal_id, Errors::invalid_argument(ERR_VOTED_OTHERS_ALREADY));
};

// flip the vote
Expand Down Expand Up @@ -465,7 +466,7 @@ module Dao {
let my_vote = borrow_global_mut<Vote<TokenT>>(Signer::address_of(signer));
{
assert(my_vote.proposer == proposer_address, Errors::invalid_argument(ERR_PROPOSER_MISMATCH));
assert(my_vote.id == proposal_id, Errors::invalid_argument(ERR_PROPOSAL_ID_MISMATCH));
assert(my_vote.id == proposal_id, Errors::invalid_argument(ERR_VOTED_OTHERS_ALREADY));
};
// revoke vote on proposal
let reverted_stake =_revoke_vote(proposal, my_vote, voting_power);
Expand Down Expand Up @@ -556,7 +557,7 @@ module Dao {
);
// these checks are still required.
assert(proposer == proposer_address, Errors::requires_address(ERR_PROPOSER_MISMATCH));
assert(id == proposal_id, Errors::invalid_argument(ERR_PROPOSAL_ID_MISMATCH));
assert(id == proposal_id, Errors::invalid_argument(ERR_VOTED_OTHERS_ALREADY));
stake
}

Expand Down Expand Up @@ -791,7 +792,7 @@ module Dao {
): (bool, u128) acquires Vote {
let vote = borrow_global<Vote<TokenT>>(voter);
assert(vote.proposer == proposer_address, Errors::requires_address(ERR_PROPOSER_MISMATCH));
assert(vote.id == proposal_id, Errors::invalid_argument(ERR_PROPOSAL_ID_MISMATCH));
assert(vote.id == proposal_id, Errors::invalid_argument(ERR_VOTED_OTHERS_ALREADY));
(vote.agree, Token::value(&vote.stake))
}

Expand Down
19 changes: 14 additions & 5 deletions vm/stdlib/modules/doc/Dao.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ User vote info.



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



<pre><code><b>const</b> <a href="Dao.md#0x1_Dao_ERR_VOTED_OTHERS_ALREADY">ERR_VOTED_OTHERS_ALREADY</a>: u64 = 1410;
</code></pre>



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


Expand Down Expand Up @@ -712,7 +721,7 @@ So think twice before casting vote.
<b>let</b> sender = <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(signer);
<b>let</b> total_voted = <b>if</b> (<b>exists</b>&lt;<a href="Dao.md#0x1_Dao_Vote">Vote</a>&lt;TokenT&gt;&gt;(sender)) {
<b>let</b> my_vote = borrow_global_mut&lt;<a href="Dao.md#0x1_Dao_Vote">Vote</a>&lt;TokenT&gt;&gt;(sender);
<b>assert</b>(my_vote.id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSAL_ID_MISMATCH">ERR_PROPOSAL_ID_MISMATCH</a>));
<b>assert</b>(my_vote.id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_VOTED_OTHERS_ALREADY">ERR_VOTED_OTHERS_ALREADY</a>));
<b>assert</b>(my_vote.agree == agree, <a href="Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="Dao.md#0x1_Dao_ERR_VOTE_STATE_MISMATCH">ERR_VOTE_STATE_MISMATCH</a>));

<a href="Dao.md#0x1_Dao__cast_vote">_cast_vote</a>(proposal, my_vote, stake);
Expand Down Expand Up @@ -811,7 +820,7 @@ Let user change their vote during the voting time.
<b>let</b> my_vote = borrow_global_mut&lt;<a href="Dao.md#0x1_Dao_Vote">Vote</a>&lt;TokenT&gt;&gt;(<a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(signer));
{
<b>assert</b>(my_vote.proposer == proposer_address, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSER_MISMATCH">ERR_PROPOSER_MISMATCH</a>));
<b>assert</b>(my_vote.id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSAL_ID_MISMATCH">ERR_PROPOSAL_ID_MISMATCH</a>));
<b>assert</b>(my_vote.id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_VOTED_OTHERS_ALREADY">ERR_VOTED_OTHERS_ALREADY</a>));
};

// flip the vote
Expand Down Expand Up @@ -904,7 +913,7 @@ Revoke some voting powers from vote on <code>proposal_id</code> of <code>propose
<b>let</b> my_vote = borrow_global_mut&lt;<a href="Dao.md#0x1_Dao_Vote">Vote</a>&lt;TokenT&gt;&gt;(<a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(signer));
{
<b>assert</b>(my_vote.proposer == proposer_address, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSER_MISMATCH">ERR_PROPOSER_MISMATCH</a>));
<b>assert</b>(my_vote.id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSAL_ID_MISMATCH">ERR_PROPOSAL_ID_MISMATCH</a>));
<b>assert</b>(my_vote.id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_VOTED_OTHERS_ALREADY">ERR_VOTED_OTHERS_ALREADY</a>));
};
// revoke vote on proposal
<b>let</b> reverted_stake =<a href="Dao.md#0x1_Dao__revoke_vote">_revoke_vote</a>(proposal, my_vote, voting_power);
Expand Down Expand Up @@ -997,7 +1006,7 @@ Retrieve back my staked token voted for a proposal.
);
// these checks are still required.
<b>assert</b>(proposer == proposer_address, <a href="Errors.md#0x1_Errors_requires_address">Errors::requires_address</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSER_MISMATCH">ERR_PROPOSER_MISMATCH</a>));
<b>assert</b>(id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSAL_ID_MISMATCH">ERR_PROPOSAL_ID_MISMATCH</a>));
<b>assert</b>(id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_VOTED_OTHERS_ALREADY">ERR_VOTED_OTHERS_ALREADY</a>));
stake
}
</code></pre>
Expand Down Expand Up @@ -1287,7 +1296,7 @@ Get voter's vote info on proposal with <code>proposal_id</code> of <code>propose
): (bool, u128) <b>acquires</b> <a href="Dao.md#0x1_Dao_Vote">Vote</a> {
<b>let</b> vote = borrow_global&lt;<a href="Dao.md#0x1_Dao_Vote">Vote</a>&lt;TokenT&gt;&gt;(voter);
<b>assert</b>(vote.proposer == proposer_address, <a href="Errors.md#0x1_Errors_requires_address">Errors::requires_address</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSER_MISMATCH">ERR_PROPOSER_MISMATCH</a>));
<b>assert</b>(vote.id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_PROPOSAL_ID_MISMATCH">ERR_PROPOSAL_ID_MISMATCH</a>));
<b>assert</b>(vote.id == proposal_id, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Dao.md#0x1_Dao_ERR_VOTED_OTHERS_ALREADY">ERR_VOTED_OTHERS_ALREADY</a>));
(vote.agree, <a href="Token.md#0x1_Token_value">Token::value</a>(&vote.stake))
}
</code></pre>
Expand Down

0 comments on commit ae829ad

Please sign in to comment.