簡體   English   中英

如何在以太坊上運行投票代碼並獲得結果?

[英]How can I run the voting code on Ethereum and get the result?

我在MIST以太坊錢包上執行了這里發布的代碼,問題是我找不到如何“停止”投票並獲得最終結果。 你能告訴我嗎?

在霧中轉到你的合同並運行winningProposal()函數。 這計算了考慮所有先前投票的獲勝提議。

/// @dev Computes the winning proposal taking all
/// previous votes into account.
function winningProposal() constant
        returns (uint winningProposal)
{
    uint winningVoteCount = 0;
    for (uint p = 0; p < proposals.length; p++) {
        if (proposals[p].voteCount > winningVoteCount) {
            winningVoteCount = proposals[p].voteCount;
            winningProposal = p;
        }
    }
}

請注意,mist重命名/清理函數名稱,它可以命名為Winning Proposalwinning proposal 你可以不加任何參數調用它。

它將返回投票最多的提案的ID。 查看proposals結構:

// This is a type for a single proposal.
struct Proposal
{
    bytes32 name;   // short name (up to 32 bytes)
    uint voteCount; // number of accumulated votes
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM