新DApp《骰子游戏》申请上线


  • SBP

    1.DApp的名称:骰子游戏/Dice Game

    2.DApp的介绍:
    游戏介绍:
    骰子游戏币圈热门玩法,欢迎体验!

    游戏规则:
    每次投注前选择预测的点数,可选择大于指定点数或小于指定点数,界面中会展示出预测点数对应的胜率与赔率。投注后开奖点数符合预测点数范围则为中奖。
    骰子开奖点数与投注玩家及金额大小均无关系,采用Vite公有链生成随机数进取余计算,中奖概率公开公平。

    3.上线状态:否

    4.DApp的合约地址:vite_9f983edba1c3ffc142e5b7aaa8bdf20381fa81f8433c188381
    源代码已认证:https://explorer.vite.net/account/vite_9f983edba1c3ffc142e5b7aaa8bdf20381fa81f8433c188381

    5.合约代码如下:

    pragma soliditypp ^0.4.2;
    contract ViteBet {
        address owner;
    
        struct BetLimit {
            uint256 lowerLimit;
            uint256 upperLimit;
            uint256 tipPer;
        }
    
        tokenId[] tokens = ["tti_5649544520544f4b454e6e40"];
        mapping(tokenId => BetLimit) public tokenMap;
    
        event win(address indexed addr, uint8 betType, uint256 rollTarget, uint256 betAmount, uint64 random64, uint64 rollNum, uint256 winAmount);
        event lose(address indexed addr, uint8 betType, uint256 rollTarget, uint256 betAmount, uint64 random64, uint64 rollNum);
        event suspendBet(address indexed addr, uint8 betType, uint256 rollTarget, uint256 betAmount);
    
        constructor() public {
            owner = msg.sender;
            tokenMap["tti_5649544520544f4b454e6e40"].lowerLimit = 1 vite;
            tokenMap["tti_5649544520544f4b454e6e40"].upperLimit = 5000 vite;
            tokenMap["tti_5649544520544f4b454e6e40"].tipPer = 4;
        }
    
        onMessage () payable {}
    
        onMessage configBetLimit(uint256 ll, uint256 ul, uint256 tp) {
            require(owner == msg.sender);
            require(ll > 0 && ll <= ul);
            require(tp >= 0 && tp <= 20);
            if (tokenMap[msg.tokenid].lowerLimit == 0)
                tokens.push(msg.tokenid);
            tokenMap[msg.tokenid].lowerLimit = ll;
            tokenMap[msg.tokenid].upperLimit = ul;
            tokenMap[msg.tokenid].tipPer = tp;
        }
    
        onMessage DrawMoney(uint256 amount) {
            require(owner == msg.sender);
            require(amount <= balance(msg.tokenid));
            msg.sender.transfer(msg.tokenid, amount);
        }
    
        getter getBetLimit(tokenId token) returns(uint256 ll, uint256 ul, uint256 tipPer) {
            return (tokenMap[token].lowerLimit, tokenMap[token].upperLimit, tokenMap[token].tipPer);
        }
    
        getter getTokenList() returns(tokenId[] memory) {
            return tokens;
        }
    
        onMessage BetAndRoll(uint8 betType, uint256 rollTargets) payable {
            uint256 betAmount = msg.amount;
            address betAddr = msg.sender;
            uint256 ll = tokenMap[msg.tokenid].lowerLimit;
            uint256 ul = tokenMap[msg.tokenid].upperLimit;
            require(ll > 0 && ll <= ul);
            require(betAmount >= ll && betAmount <= ul);
            require(rollTargets >= 4 && rollTargets <= 95);
            require(betAmount == 1 vite || betAmount == 10 vite || betAmount == 50 vite || betAmount == 100 vite || betAmount == 500 vite || betAmount == 1000 vite || betAmount == 5000 vite);
    
            require(betType == 0 || betType == 1);
    
            uint64 randomNumber = random64();
            uint64 rollNum = randomNumber % 100;
            bool winBet = false;
            uint256 winAmount = 0;
    
            if (betType == 0) {
                if (rollTargets > rollNum) {
                    winBet = true;
                    winAmount = betAmount * 100 / (rollTargets) * (100 - tokenMap[msg.tokenid].tipPer) / 100;
                }
            } else {
                if (rollTargets < rollNum) {
                    winBet = true;
                    winAmount = betAmount * 100 / (99 - rollTargets) * (100 - tokenMap[msg.tokenid].tipPer) / 100;
                }
            }
    
            if (winBet == false) {
                emit lose(betAddr, betType, rollTargets, betAmount, randomNumber, rollNum);
            } else if (winBet == true && winAmount > balance(msg.tokenid)) {
                betAddr.transfer(msg.tokenid, betAmount);
                emit suspendBet(betAddr, betType, rollTargets, betAmount);
            } else {
                betAddr.transfer(msg.tokenid, winAmount);
                emit win(betAddr, betType, rollTargets, betAmount, randomNumber, rollNum, winAmount);
            }
        }
    
    }
    

Log in to reply