竞猜活动区块链方案探索

简介: 合约实现了报名,退出,参加人数控制,竞猜次数控制,公布答案,获奖名单等等功能

竞猜活动区块链方案探索

本文节选自电子书《Netkiller Blockchain 手札》

Netkiller Blockchain 手札

本文作者最近在找工作,有意向致电 13113668890

Mr. Neo Chan, 陈景峯(BG7NYT)

中国广东省深圳市龙华新区民治街道溪山美地 518131 +86 13113668890 <netkiller@msn.com>

文档始创于2018-02-10

版权 © 2018 Netkiller(Neo Chan). All rights reserved.

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

微信订阅号 netkiller-ebook (微信扫描二维码)

QQ:13721218 请注明“读者”

QQ群:128659835 请注明“读者”

网站:http://www.netkiller.cn

合约实现了报名,退出,参加人数控制,竞猜次数控制,公布答案,获奖名单等等功能

pragma solidity ^0.4.20;
// Author netkiller<netkiller@msn.com>
// Home http://www.netkiller.cn
contract Guess {

    address public owner;
    
    string name;        //活动名称
    bool start = false;	//合约锁
    uint number;			//参赛人数统计
    uint public quota;	//名额限定
    mapping (address => string) public registrantsPaid; //参加活动 
    uint maxCounter = 3;	//最大竞猜次数
    mapping (address  => uint) counter; //竞猜次数统计

    string public question; //竞猜问题 
    mapping (uint  => string) public options; //选项 
    
    // 答案结构
    struct Answer {
        address player;
        uint answer;
    }
    
    mapping (uint  => Answer) public answer; //答案 
    uint answerIndex = 0;
    
    //公布最终答案
    uint public expose;
    
    //获奖名单
    mapping (address  => uint) winner;

    function Guess(string _name, uint _quota) public {
        name = _name;
        quota = _quota;
        number = 0;
	}
	
	modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }
	
    // 获取活动名称
    function getName() public view returns(string){
        return name;
    }
    function setStatus(bool _start) onlyOwner public {
        start = _start;
    }
    function setQuestion(string _question) public {
        question = _question;
    }
    // 增加人物属性,例如肤色,眼睛,头发等等
    function putOptions(uint _key, string _value) onlyOwner public{
        if(start == false){
        	options[_key] = _value;
        }
    }
    function join(string _password) onlyOwner public returns (bool success) {
    		require(start == ture);
        if (number >= quota) { return false; }
        registrantsPaid[msg.sender] = _password;
        number++;
    
        return true;
      }
      function changeQuota(uint _quota) onlyOwner public {
        quota = _quota;
      }
    function quit() onlyOwner public {
    		require(start == false);
        //require (registrantsPaid[msg.sender] == _password);
        delete registrantsPaid[msg.sender];
        number--;
    }
    function setGuess(uint _answer) public{
        require(start == ture);
        if(maxCounter > counter[msg.sender]){
            counter[msg.sender]++;
            answer[answerIndex] = Answer(msg.sender, _answer);
            answerIndex++;
        }
        
    }
    //揭秘答案 
    function setExpose(uint _expose) onlyOwner public {
	    require(start == ture);
        expose = _expose;  
        
        for(uint i=0;i<answerIndex;i++)
        {
            Answer memory ans = answer[i];
            if(ans.answer == expose){
                winner[ans.player] = ans.answer;
            }
        }
    }
	
	// 数量
	function getCount() public view returns(uint){
	    return number;
	}

}
目录
相关文章
|
3月前
|
安全 区块链
区块链农场游戏系统开发运营版/玩法详情/规则方案/案例设计/项目源码
Developing a blockchain farm game system is an interesting and challenging task. Here is a design solution that can help you get started developing such a system
|
2月前
|
供应链 区块链
区块链DAPP质押合约代币系统开发|模式方案
智能合约是一种数字化的合约,它将合约内容写入区块链中,保证了合约的公开透明
|
3月前
|
安全 中间件 测试技术
Web3.0区块链技术开发方案:mint铭文铭刻制度开发
Web3.0区块链技术开发方案:mint铭文铭刻制度开发
|
4月前
|
安全 数据挖掘 区块链
区块链商城源码搭建开发技术方案丨成熟讲解
区块链积分商城系统开发技术丨成熟方案
114 0
|
4月前
|
算法 区块链 Python
区块链代币DAPP逻辑系统开发技术方案丨单边上扬模式开发逻辑
区块链代币DAPP逻辑系统开发技术方案丨单边上扬模式开发逻辑
|
7月前
|
存储 算法 安全
数字货币区块链合约系统开发指南与方案
区块链的工作原理是通过共识算法来解决网络中的节点之间的信任问题
|
8月前
|
安全 区块链 数据安全/隐私保护
区块链Swap博饼交易所兑换系统开发项目方案详情
Web3则是一种更高级的互联网技术,它基于区块链技术,并通过去中心化
|
8月前
|
开发框架 区块链 数据安全/隐私保护
哈希竞猜游戏系统开发规则详细(区块链游戏dapp开发)丨哈希竞猜游戏源码方案
哈希竞猜游戏dapp系统开发,是一种基于区块链技术的去中心化应用。它具有公开、透明、不可篡改的特点。该系统的开发采用了基于以太坊智能合约的DAPP开发框架,使用了Solidity语言进行合约编写。
|
8月前
|
SQL 安全 网络安全
区块链交易所系统开发(稳定版)/开发案例/详细逻辑/规则方案丨区块链链交易所源码项目
The source code parsing of blockchain exchanges involves a large amount of technical details and complexity. The following is an overview and explanation of the common components and functions of blockchain exchange source code
|
8月前
|
区块链 安全
区块链交易所系统开发详细指南丨交易所系统开发功能逻辑/方案介绍/案例设计/逻辑项目/源码出售
User experience: The interface and user experience of blockchain exchanges should be intuitive, user-friendly, and easy to use and navigate. The platform should provide a simple and clear trading interface to facilitate users' buying and selling operations.

热门文章

最新文章