繁体   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