51微投票的投票程序代码的期望
A发起智能合约,设定选择项目(比如 1,2,3,4)
A设定那些人可以进行投票,先对可以进行投票的人授权
已经被授权的人可以投票,没被授权的人投票无效
计算最终那个选项投票数最多
合约代码

pragma solidity ^0.4.16;

/// @title Voting with delegation.
contract Ballot {
// This declares a new complex type which will
// be used for variables later.
// It will represent a single voter.
struct Voter {
uint weight; // weight is accumulated by delegation
bool voted; http://www.aivote.com/ // if true, that person already voted
address delegate; // person delegated to
uint vote; // index of the voted proposal
}

// This is a type for a single proposal.
struct Proposal {bytes32 name;   // short name (up to 32 bytes)uint voteCount; // number of accumulated votes
}address public chairperson;// This declares a state variable that
// stores a `Voter` struct for each possible address.
mapping(address => Voter) public voters;// A dynamically-sized array of `Proposal` structs.
Proposal[] public proposals;/// Create a new ballot to choose one of `proposalNames`.
function Ballot(bytes32[] proposalNames) public {chairperson = msg.sender;voters[chairperson].weight = 1;// For each of the provided proposal names,// create a new proposal object and add it// to the end of the array.for (uint i = 0; i < proposalNames.length; i++) {// `Proposal({...})` creates a temporary// Proposal object and `proposals.push(...)`// appends it to the end of `proposals`.proposals.push(Proposal({name: proposalNames[i],voteCount: 0}));}
}// Give `voter` the right to vote on this ballot.
// May only be called by `chairperson`.
function giveRightToVote(address voter) public {// If the argument of `require` evaluates to `false`,// it terminates and reverts all changes to// the state and to Ether balances. It is often// a good idea to use this if functions are// called incorrectly. But watch out, this// will currently also consume all provided gas// (this is planned to change in the future).require((msg.sender == chairperson) &&!voters[voter].voted &&(voters[voter].weight == 0));voters[voter].weight = 1;
}/// Delegate your vote to the voter `to`.
function delegate(address to) public {// assigns referenceVoter storage sender = voters[msg.sender];require(!sender.voted);// Self-delegation is not allowed.require(to != msg.sender);// Forward the delegation as long as// `to` also delegated.// In general, such loops are very dangerous,// because if they run too long, they might// need more gas than is available in a block.// In this case, the delegation will not be executed,// but in other situations, such loops might// cause a contract to get "stuck" completely.while (voters[to].delegate != address(0)) {to = voters[to].delegate;// We found a loop in the delegation, not allowed.require(to != msg.sender);}// Since `sender` is a reference, this// modifies `voters[msg.sender].voted`sender.voted = true;sender.delegate = to;Voter storage delegate_ = voters[to];if (delegate_.voted) {// If the delegate already voted,// directly add to the number of votesproposals[delegate_.vote].voteCount += sender.weight;} else {// If the delegate did not vote yet,// add to her weight.delegate_.weight += sender.weight;}
}/// Give your vote (including votes delegated to you)
/// to proposal `proposals[proposal].name`.
function vote(uint proposal) public {Voter storage sender = voters[msg.sender];require(!sender.voted);require(sender.weight == 1);sender.voted = true;sender.vote = proposal;// If `proposal` is out of the range of the array,// this will throw automatically and revert all// changes.proposals[proposal].voteCount += sender.weight;
}/// @dev Computes the winning proposal taking all
/// previous votes into account.
function winningProposal() public viewreturns (uint winningProposal_)
{uint winningVoteCount = 0;for (uint p = 0; p < proposals.length; p++) {if (proposals[p].voteCount > winningVoteCount) {winningVoteCount = proposals[p].voteCount;winningProposal_ = p;}}
}// Calls winningProposal() function to get the index
// of the winner contained in the proposals array and then
// returns the name of the winner
function winnerName() public viewreturns (bytes32 winnerName_)
{winnerName_ = proposals[winningProposal()].name;
}

}

51微投票的投票程序代码相关推荐

  1. 带存储功能的数字电子琴c语言,51单片机电子琴c语言程序代码实现

    #include #define KeyPort P1 unsigned char High,Low; //定时器预装值的高8位和低8位 sbit SPK=P3^7;          //定义蜂鸣器 ...

  2. 太赞了,使用应用魔方 AppCube,我没有写一行代码就开发出了一款投票微信小程序

    低代码开发近些年非常火热,所谓低代码开发就是无需写太多的代码甚至有些简单应用不用写代码就能构建出一款应用,低代码开发平台非常多,其中我比较熟悉的就是华为的应用魔方 AppCube,本文就带着大家用应用 ...

  3. 微投票统计及投票过滤器交互实现代码

    微投票统计及投票过滤器交互实现代码.大家都知道,用户的投票不是每次都能成功,例如连续投票,因为这样的投票通常情况下为恶意投票,将导致投票的结果不真实. VoltLimitFilter类负责过滤投票者的 ...

  4. 显示微投票的进度条代码分享

    显示微投票的进度条代码分享,一个投票功能模块少不了查看投票结果,用进度条显示各个投票结果可以起到一目了然的效果.以下是我的方法,请大家不吝赐教: 1:做一张图片用于做进度条,只需要很小的一个图片就可以 ...

  5. 第三方微投票系统进度条代码

    第三方微投票系统进度条代码 一个投票功能模块少不了查看投票结果,用进度条显示各个投票结果可以起到一目了然的效果.以下是我的方法,请大家不吝赐教: 1:做一张图片用于做进度条,只需要很小的一个图片就可以 ...

  6. 第三方微投票系统投票数据展示代码

    第三方微投票系统投票数据展示代码,用一个dataReader对象dr保存取出的各项票数,用一个int 型变量sum保存取出的总票数,各项分别再定义一个double型变量用来保存单项票数除以(/)总票数 ...

  7. 投票功能+代码+java_JSP实现的简单Web投票程序代码

    这篇文章主要介绍了JSP实现的简单Web投票程序代码,较为详细的分析了JSP实现投票功能的具体步骤与相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了JSP实现的简单Web投票程序. ...

  8. 编程统计候选人的得票数。设有3个候选人zhang、li、wang(候选人姓名不区分大小写),10个选民,选民每次输入一个得票的候选人的名字,若选民输错候选人姓名,则按废票处理。选民投票结束后程序自动显

    编程统计候选人的得票数.设有3个候选人zhang.li.wang(候选人姓名不区分大小写),10个选民,选民每次输入一个得票的候选人的名字,若选民输错候选人姓名,则按废票处理.选民投票结束后程序自动显 ...

  9. 免费三加一php源码,最新微联运微信投票独立版PHP源码|基于31CMS投票系统二次开发+幸运大转盘+独立后台吸粉工具...

    源码介绍 投票系统对于微信公众号来说是一种非常有效的吸粉手段!!微信投票系统是基于网络的一种投票收集及统计的系统,比传统的投票统计更为方便.快速.准确.投票的同时 ,会有更多的朋友关注你,朋友的好友通 ...

最新文章

  1. postman 接口 403 forbidden_接口测试怎么做?
  2. vSphere PowerCLI安装及命令
  3. 计算机基础课教学心得,计算机基础教学心得
  4. 《JavaScript高级程序设计》阅读笔记(二十一):JavaScript中的XML
  5. 【MySQL】计算 TPS,QPS 的方式
  6. [New Portal]Windows Azure Virtual Machine (18) Azure Virtual Machine内部IP和外部IP
  7. Oracle中to_char()函数的用法
  8. linux文件共享之samba,nfs的搭建
  9. Linux交叉编译+粤嵌LCD实现三色图
  10. 登录emc磁阵提示java版本低_安装完打开 eclipse 提示 JVM 版本较低
  11. [Hadoop] - Win7下提交job到集群上去
  12. ccproxy8.0破解版
  13. viper4Android md风格,ViPER4Android音效驱动
  14. mybatis (高级映射 缓存 延迟加载)
  15. 教你如何求一个集合的所有非空子集的方差和
  16. 解决某物流企业二维码打印问题
  17. 基于深度残差学习的图像识别 Deep Residual Learning for Image Recognition
  18. 《塔木德智慧全书》--艾格
  19. 全球及中国铁路建设行业运营管理模式与未来总体规划报告2022版
  20. Lightdb Pgpool-II 读写分离使用

热门文章

  1. 在电脑上考试怎么调用计算机,如何使用电脑考科目一
  2. 2023年全年放假时间表:日历备忘录随时查看
  3. PyQt:快速转换路径中的斜杠(斜杠(/)与反斜杠(\)转换)
  4. Ablation Study 解释
  5. MATLAB水果品质自动分级系统
  6. 魔百盒MG100、M101、UNT400、MG101刷机固件及教程
  7. 究竟什么是马德里商标
  8. echarts象形柱状图
  9. 2022最新nft数字藏品系统源码,商业运营版
  10. CISSP考点拾遗——BCP/DRP演练层次问题