Latest 10 txns

TxHash Age From To Value [TxFee]
0xeb570acf045960f2fe7b3ea3bdfc6de7e8447f04447a44bbac29161773978dc68 days 16 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0.1 Ether0.009235004
0x5a21dc3a9accf48c9d111e2c55f29c6587a2b062c5f10e605597991f1b51ea2211 days 22 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0 Ether0.008423204
0xae055c92ca56780e71549198934460ff24f6a210f3a9c794a48b6f5807ca899c61 days 3 hrs ago0x4095fca71b5cd0071543616149909f668d2f1a0b  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0 Ether0.000430088
0xc9cbe0b80440f7ddf041b0b6276b6d77333504a218402d4cc52273b370db1ed298 days 3 hrs ago0x4095fca71b5cd0071543616149909f668d2f1a0b  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0.1 Ether0.000230044
0xc4f60ff698cb114b28a999f0bc8a3dcf2d7039bc105d65125c7061786af10a6f98 days 3 hrs ago0x4095fca71b5cd0071543616149909f668d2f1a0b  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0.1 Ether0.000230044
0x717b5c2074d8cb1148d26f06b390ab7aa11e472e0e81497a6763140856c56c9b111 days 16 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0.1 Ether0.000920176
0x87c9df1b1ed1d1c47e584fcfa720abbbfa276d0c248155cc8f55b65fa72b90fd111 days 16 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0 Ether0.000860176
0x4544529460b01f98b451eeef03c007b7dec4128a7de653622359ba0fabab7c42111 days 16 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0.1 Ether0.000980176
0xef067c1877596cf90a2992eb57d2de4a17274b201b66a8df0fb45116957d9f11111 days 16 hrs ago0xe4e18a49c6f1210ffe9a60dbd38071c6ef78d982  IN   0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd2 Ether0.000124653
0xbad4131effc041d7079a91849fc31c4006e5c28bdd1ca4272819d3d09657c360111 days 16 hrs ago0xe4e18a49c6f1210ffe9a60dbd38071c6ef78d982  IN    Contract Creation0 Ether0.003125636
[ Download CSV Export  ] 
 Internal Transactions as a result of Contract Execution
 Latest 25 Internal Txns, Click here To View More View All
ParentTxHash Block Age From To Value
0xf6bd618cac809d494a853c69d46cb21bb04841c638bfbfc6815667aa311af8e438562958 days 16 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe4e18a49c6f1210ffe9a60dbd38071c6ef78d9820.002 Ether
0xf6bd618cac809d494a853c69d46cb21bb04841c638bfbfc6815667aa311af8e438562958 days 16 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe222f441cb42bcfe8e46fdecad0e633c70246bd30.198 Ether
0xf6bd618cac809d494a853c69d46cb21bb04841c638bfbfc6815667aa311af8e438562958 days 16 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xf6bd618cac809d494a853c69d46cb21bb04841c638bfbfc6815667aa311af8e438562958 days 16 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0 Ether
0xeb570acf045960f2fe7b3ea3bdfc6de7e8447f04447a44bbac29161773978dc638562948 days 16 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0xeb570acf045960f2fe7b3ea3bdfc6de7e8447f04447a44bbac29161773978dc638562948 days 16 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xbda8c6a9b68ab5ea1bd49488a4899ce5f49d9113aa63fb295241efb73e73dc39383753411 days 22 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xbda8c6a9b68ab5ea1bd49488a4899ce5f49d9113aa63fb295241efb73e73dc39383753411 days 22 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0 Ether
0x5a21dc3a9accf48c9d111e2c55f29c6587a2b062c5f10e605597991f1b51ea22383753311 days 22 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0x5a21dc3a9accf48c9d111e2c55f29c6587a2b062c5f10e605597991f1b51ea22383753311 days 22 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xf4b6fd95147021bacd897d5ea92c8910a2254811aeab8895e00861f17bdd42cb355425761 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xf4b6fd95147021bacd897d5ea92c8910a2254811aeab8895e00861f17bdd42cb355425761 days 3 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0 Ether
0xae055c92ca56780e71549198934460ff24f6a210f3a9c794a48b6f5807ca899c355425661 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0xae055c92ca56780e71549198934460ff24f6a210f3a9c794a48b6f5807ca899c355425661 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xd59a26acf3a4cfa8942d4a27180d98bb0c134f00b44d408d1733ccbc9870e139334110698 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe4e18a49c6f1210ffe9a60dbd38071c6ef78d9820.00105 Ether
0xd59a26acf3a4cfa8942d4a27180d98bb0c134f00b44d408d1733ccbc9870e139334110698 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0x4095fca71b5cd0071543616149909f668d2f1a0b0.10421 Ether
0xd59a26acf3a4cfa8942d4a27180d98bb0c134f00b44d408d1733ccbc9870e139334110698 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xd59a26acf3a4cfa8942d4a27180d98bb0c134f00b44d408d1733ccbc9870e139334110698 days 3 hrs ago0x1882d681b01e13f2cb3a5b1f8c05496ec02ea0350x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0 Ether
0xc9cbe0b80440f7ddf041b0b6276b6d77333504a218402d4cc52273b370db1ed2334110598 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0x1882d681b01e13f2cb3a5b1f8c05496ec02ea0350 Ether
0xc9cbe0b80440f7ddf041b0b6276b6d77333504a218402d4cc52273b370db1ed2334110598 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0x14790144b122031936c9b1b890c99651941adae671d3c588dd8aba286dc9e936334110098 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0x14790144b122031936c9b1b890c99651941adae671d3c588dd8aba286dc9e936334110098 days 3 hrs ago0x1882d681b01e13f2cb3a5b1f8c05496ec02ea0350x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0 Ether
0xc4f60ff698cb114b28a999f0bc8a3dcf2d7039bc105d65125c7061786af10a6f334109998 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0x1882d681b01e13f2cb3a5b1f8c05496ec02ea0350 Ether
0xc4f60ff698cb114b28a999f0bc8a3dcf2d7039bc105d65125c7061786af10a6f334109998 days 3 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xf965242848b65c100b18a9d64810a8b8bf6c737f185b569c880205e1ec677d063263127111 days 16 hrs ago0x0bbd2256f1710a55d8070b1c3c063cc46f889ffd0xe987926a226932dfb1f71fa316461db272e053170 Ether
[ Download CSV Export  ] 
Contract Source Code Verified (Exact Match)
Contract Name: SimpleDice
Compiler Version: v0.4.25+commit.59dbf8f1
Optimization Enabled: Yes
Runs (Optimiser):  200



  Contract Source Code   Find Similiar Contracts

pragma solidity ^0.4.24;

// Util functions imported in OnChainSDK for caller to use.
library utils {
    uint constant UINT256MAX = ~uint(0);
    
    // A decimal byte to uint. Return value of 10 indicating invalid input.
    function byte2Uint(byte b) internal pure returns(uint) {
        if (b >= '0' && b <= '9') {
            return uint(b) - 48;  // '0'
        }
        // Indicating invalid input.
        return 10;
    }
    // Return value of 16 indicating invalid input.
    function hexByte2Uint(byte b) internal pure returns(uint) {
        if (b >= '0' && b <= '9') {
            return uint(b) - 48;  // '0'
        } else if (b >= 'A' && b <= 'F') {
            return uint(b) - 55;
        } else if (b >= 'a' && b <= 'f') {
            return uint(b) - 87;
        }
        // Indicating invalid input.
        return 16;
    }
    
    /// StringToXXX helpers.
    
    // A decimal string (charset c in [0-9]) to uint. Like atoi(),
    // 1. processing stops once encountering character not in charset c.
    // 2. returns UINT256MAX when overflow.
    function str2Uint(string a) internal pure returns(uint) {
        bytes memory b = bytes(a);
        uint res = 0;
        for (uint i = 0; i < b.length; i++) {
            uint tmp = byte2Uint(b[i]);
            if (tmp >= 10) {
                return res;
            } else {
                // Overflow.
                if (res >= UINT256MAX / 10) {
                    return UINT256MAX;
                }
                res = res * 10 + tmp;
            }
        }
        return res;
    }
    
    // Hex string (charset c in [0-9A-Za-z]) to uint. Like atoi(),
    // 1. processing stops once encountering character not in charset c.
    // 2. returns UINT256MAX when overflow.
    function hexStr2Uint(string a) internal pure returns(uint) {
        bytes memory b = bytes(a);
        uint res = 0;
        uint i = 0;
        if (b.length >= 2 && b[0] == '0' && (b[1] == 'x' || b[1] == 'X')) {
            i += 2;
        }
        for (; i < b.length; i++) {
            uint tmp = hexByte2Uint(b[i]);
            if (tmp >= 16) {
                return res;
            } else {
                // Overflow.
                if (res >= UINT256MAX / 16) {
                    return UINT256MAX;
                }
                res = res * 16 + tmp;
            }
        }
        return res;
    }
    
    // Input: 20-byte hex string without or with 0x/0X prefix (40 characters or 42 characters)
    // Example: '0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263' => address(0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263)
    // address is of uint160.
    function str2Addr(string a) internal pure returns(address) {
        bytes memory b = bytes(a);
        require(b.length == 40 || b.length == 42, "Invalid input, should be 20-byte hex string");
        uint i = 0;
        if (b.length == 42) {
            i += 2;
        }
        
        uint160 res = 0;
        for (; i < b.length; i += 2) {
            res *= 256;
            
            uint160 b1 = uint160(hexByte2Uint(b[i]));
            uint160 b2 = uint160(hexByte2Uint(b[i+1]));
            require(b1 < 16 && b2 < 16, "address string with invalid character");
            
            res += b1 * 16 + b2;
        }
        return address(res);
    }
    
    /// XXXToString() helpers.
    
    // Example: 12 -> 'c' (without 0x/0X prefix).
    function uint2HexStr(uint x) internal pure returns(string) {
        if (x == 0) return '0';
        
        uint j = x;
        uint len;
        while (j != 0) {
            len++;
            j /= 16;
        }
        
        bytes memory b = new bytes(len);
        uint k = len - 1;
        while (x != 0) {
            uint curr = (x & 0xf);
            b[k--] = curr > 9 ? byte(55 + curr) : byte(48 + curr);
            x /= 16;
        }
        return string(b);
    }
    
    // Example: 12 -> "12"
    function uint2Str(uint x) internal pure returns(string) {
        if (x == 0) return '0';
        
        uint j = x;
        uint len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        
        bytes memory b = new bytes(len);
        uint k = len - 1;
        while (x != 0) {
            b[k--] = byte(48 + x % 10);
            x /= 10;
        }
        return string(b);
    }
    
    // Example: address(0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263) => '0e7ad63d2a305a7b9f46541c386aafbd2af6b263'
    function addr2Str(address x) internal pure returns(string) {
        bytes memory b = new bytes(20);
        for (uint i = 0; i < 20; i++) {
            b[i] = byte(uint8(uint(x) / (2**(8*(19 - i)))));
        }
        return string(b);
    }
    
    /// bytes/string helpers.
    
    function bytesConcat(bytes a, bytes b) internal pure returns(bytes) {
        bytes memory concated = new bytes(a.length + b.length);
        uint i = 0;
        uint k = 0;
        while (i < a.length) { concated[k++] = a[i++]; }
        i = 0;
        while(i < b.length) { concated[k++] = b[i++]; }
        return concated;
    }
    
    function strConcat(string a, string b) internal pure returns(string) {
        bytes memory aa = bytes(a);
        bytes memory bb = bytes(b);
        return string(bytesConcat(aa, bb));
    }
    
    function bytesCompare(bytes a, bytes b) internal pure returns(int) {
        uint len = a.length < b.length ? a.length : b.length;
        for (uint i = 0; i < len; i++) {
            if (a[i] < b[i]) {
                return -1;
            } else if (a[i] > b[i]) {
                return 1;
            }
        }
        if (a.length < b.length) {
            return -1;
        } else if (a.length > b.length) {
            return 1;
        } else {
            return 0;
        }
    }
    
    // "abd" > "abcde"
    function strCompare(string a, string b) internal pure returns(int) {
        bytes memory aa = bytes(a);
        bytes memory bb = bytes(b);
        return bytesCompare(aa, bb);
    }
    
    function bytesEqual(bytes a, bytes b) internal pure returns(bool) {
        return (a.length == b.length) && (bytesCompare(a, b) == 0);
    }
    
    function strEqual(string a, string b) internal pure returns(bool) {
        bytes memory aa = bytes(a);
        bytes memory bb = bytes(b);
        return bytesEqual(aa, bb);
    }

    // Return the index of needle's first occurrance in haystack. Return value
    // of -1 indicating no occurrance.
    // Useful in case of parsing float string "123.45".
    // Example:
    //   indexOf('123', '') => 0
    //   indexOf('', '45') => -1
    //   indexOf('123', '1234') => -1
    //   indexOf('123.45', '.') => 3
    function indexOf(string haystack, string needle) internal pure returns(int) {
        bytes memory b_haystack = bytes(haystack);
        bytes memory b_needle = bytes(needle);
        return indexOf(b_haystack, b_needle);
    }

    function indexOf(bytes haystack, bytes needle) internal pure returns(int) {
        if (needle.length == 0) {
            return 0;
        } else if (haystack.length < needle.length) {
            return -1;
        }
        // Instead of O(haystack.length x needle.length), saving gas using KMP:
        // O(haystack.length + needle.length)
        uint[] memory pi = new uint[](needle.length + 1);
        pi[1] = 0;
        uint k = 0;
        // KMP pre-processing
        for(uint q = 2; q <= needle.length; q++) {
            while(k > 0 && needle[k] != needle[q-1]) {
                k = pi[k];
            }
            if(needle[k] == needle[q-1]) {
                k++;
            }
            pi[q] = k;
        }
        // KMP matching
        q = 0;
        for(uint i = 0; i < haystack.length; i++) {
            while(q > 0 && needle[q] != haystack[i]) {
                q = pi[q];
            }
            if(needle[q] == haystack[i]) {
                q++;
            }
            // Match
            if(q == needle.length) {
                return int(i - q + 1);
            }
        }
        // No match
        return -1;
    }

    // subStr("1234567890", 2, 5) => "34567"
    // [start, start + len), index starting from 0.
    function subStr(bytes a, uint start, uint len) internal pure returns(bytes) {
       require(start < a.length && start + len > start && start + len <= a.length,
               "Invalid start index or length out of range");
       bytes memory res = new bytes(len);
       for (uint i = 0; i < len; i++) {
           res[i] = a[start + i];
       }
       return res;
    }

    // string num = "123.4567";
    // subStr(num, indexOf(num, '.') + 1) => "4567"
    function subStr(bytes a, uint start) internal pure returns(bytes) {
        require(start < a.length, "Invalid start index out of range");
        return subStr(a, start, a.length - start);
    }

    function subStr(string a, uint start, uint len) internal pure returns(string) {
        bytes memory aa = bytes(a);
        return string(subStr(aa, start, len));
    }

    function subStr(string a, uint start) internal pure returns(string) {
        bytes memory aa = bytes(a);
        return string(subStr(aa, start));
    }
}

interface DOSProxyInterface {
    function query(address, uint, string, string) external returns (uint);
    function requestRandom(address, uint8, uint) external returns (uint);
}

interface DOSAddressBridgeInterface {
    function getProxyAddress() external view returns (address);
}

contract DOSOnChainSDK {
    using utils for *;

    DOSProxyInterface dosProxy;
    DOSAddressBridgeInterface dosAddrBridge =
        DOSAddressBridgeInterface(0xe987926A226932DFB1f71FA316461db272E05317);

    modifier resolveAddress {
        dosProxy = DOSProxyInterface(dosAddrBridge.getProxyAddress());
        _;
    }

    function fromDOSProxyContract() internal view returns (address) {
        return dosAddrBridge.getProxyAddress();
    }

    // @dev: Call this function to get a unique queryId to differentiate
    //       parallel requests. A return value of 0x0 stands for error and a
    //       related event would be emitted.
    // @timeout: Estimated timeout in seconds specified by caller; e.g. 15.
    //           Response is not guaranteed if processing time exceeds this.
    // @dataSource: Data source destination specified by caller.
    //              E.g.: 'https://api.coinbase.com/v2/prices/ETH-USD/spot'
    // @selector: A selector expression provided by caller to filter out
    //            specific data fields out of the raw response. The response
    //            data format (json, xml/html, and more) is identified from
    //            the selector expression.
    //            E.g. Use "$.data.amount" to extract "194.22" out.
    //             {
    //                  "data":{
    //                          "base":"ETH",
    //                          "currency":"USD",
    //                          "amount":"194.22"
    //                  }
    //             }
    //            Check below documentation for details.
    //            (https://dosnetwork.github.io/docs/#/contents/blockchains/ethereum?id=selector).
    function DOSQuery(uint timeout, string dataSource, string selector)
        resolveAddress
        internal
        returns (uint)
    {
        return dosProxy.query(this, timeout, dataSource, selector);
    }

    // @dev: Must override __callback__ to process a corresponding response. A
    //       user-defined event could be added to notify the Dapp frontend that
    //       the response is ready.
    // @queryId: A unique queryId returned by DOSQuery() for callers to
    //           differentiate parallel responses.
    // @result: Response for the specified queryId.
    function __callback__(uint queryId, bytes result) external {
        // To be overridden in the caller contract.
    }

    // @dev: Call this function to request either a fast but insecure random
    //       number or a safe and secure random number delivered back
    //       asynchronously through the __callback__ function.
    //       Depending on the mode, the return value would be a random number
    //       (for fast mode) or a requestId (for safe mode).
    // @mode: 1: safe mode - The asynchronous but safe way to generate a new
    //                       secure random number by a group of off-chain
    //                       clients using VRF and Threshold Signature. There
    //                       would be a fee to run in safe mode.
    //        0: fast mode - Return a random number in one invocation directly.
    //                       The returned random is the sha3 hash of latest
    //                       generated random number by DOS Network combining
    //                       with the optional seed.
    //                       Thus the result should NOT be considered safe and
    //                       is for testing purpose only. It's free of charge.
    // @seed: Optional random seed provided by caller.
    function DOSRandom(uint8 mode, uint seed)
        resolveAddress
        internal
        returns (uint)
    {
        return dosProxy.requestRandom(this, mode, seed);
    }

    // @dev: Must override __callback__ to process a corresponding random
    //       number. A user-defined event could be added to notify the Dapp
    //       frontend that a new secure random number is generated.
    // @requestId: A unique requestId returned by DOSRandom() for requester to
    //             differentiate random numbers generated concurrently.
    // @generatedRandom: Generated secure random number for the specific
    //                   requestId.
    function __callback__(uint requestId, uint generatedRandom) external {
        // To be overridden in the caller contract.
    }
}

contract SimpleDice is DOSOnChainSDK {
    address public devAddress = 0xe4E18A49c6F1210FFE9a60dBD38071c6ef78d982;
    uint public devContributed = 0;
    // 1% winning payout goes to developer account
    uint public developCut = 1;
    // precise to 4 digits after decimal point.
    uint public decimal = 4;
    // gameId => gameInfo
    mapping(uint => DiceInfo) public games;

    struct DiceInfo {
        uint rollUnder;  // betted number, player wins if random < rollUnder
        uint amountBet;  // amount in wei
        address player;  // better address
    }

    event ReceivedBet(
        uint gameId,
        uint rollUnder,
        uint weiBetted,
        address better
    );
    event PlayerWin(uint gameId, uint generated, uint betted, uint amountWin);
    event PlayerLose(uint gameId, uint generated, uint betted);

    modifier auth {
        // Filter out malicious __callback__ callers.
        require(msg.sender == fromDOSProxyContract(), "Unauthenticated response");
        _;
    }

    modifier onlyDev {
        require(msg.sender == devAddress);
        _;
    }
    
    function min(uint a, uint b) internal pure returns(uint) {
        return a < b ? a : b;
    }
    // Only receive bankroll funding from developer.
    function() public payable onlyDev {
        devContributed += msg.value;
    }
    // Only developer can withdraw the amount up to what he has contributed.
    function devWithdrawal() public onlyDev {
        uint withdrawalAmount = min(address(this).balance, devContributed);
        devContributed = 0;
        devAddress.transfer(withdrawalAmount);
    }
    
    // 100 / (rollUnder - 1) * (1 - 0.01) => 99 / (rollUnder - 1)
    // Not using SafeMath as this function cannot overflow anyway.
    function computeWinPayout(uint rollUnder) public view returns(uint) {
        return 99 * (10 ** decimal) / (rollUnder - 1);
    }

    // 100 / (rollUnder - 1) * 0.01
    function computeDeveloperCut(uint rollUnder) public view returns(uint) {
        return 10 ** decimal / (rollUnder - 1);
    }

    function play(uint rollUnder) public payable {
        // winChance within [1%, 95%]
        require(rollUnder >= 2 && rollUnder <= 96, "rollUnder should be in 2~96");
        // Make sure contract has enough balance to cover payouts before game.
        // Not using SafeMath as I'm not expecting this demo contract's
        // balance to be very large.
        require(address(this).balance * (10 ** decimal) >= msg.value * computeWinPayout(rollUnder),
                "Game contract doesn't have enough balance, decrease rollUnder");

        // Request a safe, unmanipulatable random number from DOS Network with
        // optional seed.
        uint gameId = DOSRandom(1, now);

        games[gameId] = DiceInfo(rollUnder, msg.value, msg.sender);
        // Emit event to notify Dapp frontend
        emit ReceivedBet(gameId, rollUnder, msg.value, msg.sender);
    }

    function __callback__(uint requestId, uint generatedRandom) external auth {
        address player = games[requestId].player;
        require(player != address(0x0));

        uint gen_rnd = generatedRandom % 100 + 1;
        uint rollUnder = games[requestId].rollUnder;
        uint betted = games[requestId].amountBet;
        delete games[requestId];

        if (gen_rnd < rollUnder) {
            // Player wins
            uint payout = betted * computeWinPayout(rollUnder) / (10 ** decimal);
            uint devPayout = betted * computeDeveloperCut(rollUnder) / (10 ** decimal);

            emit PlayerWin(requestId, gen_rnd, rollUnder, payout);
            player.transfer(payout);
            devAddress.transfer(devPayout);
        } else {
            // Lose
            emit PlayerLose(requestId, gen_rnd, rollUnder);
        }
    }
}

    Contract ABI  
[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"games","outputs":[{"name":"rollUnder","type":"uint256"},{"name":"amountBet","type":"uint256"},{"name":"player","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"requestId","type":"uint256"},{"name":"generatedRandom","type":"uint256"}],"name":"__callback__","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"rollUnder","type":"uint256"}],"name":"computeDeveloperCut","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"rollUnder","type":"uint256"}],"name":"computeWinPayout","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"devWithdrawal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"developCut","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"devAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"rollUnder","type":"uint256"}],"name":"play","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"queryId","type":"uint256"},{"name":"result","type":"bytes"}],"name":"__callback__","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimal","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"devContributed","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"gameId","type":"uint256"},{"indexed":false,"name":"rollUnder","type":"uint256"},{"indexed":false,"name":"weiBetted","type":"uint256"},{"indexed":false,"name":"better","type":"address"}],"name":"ReceivedBet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"gameId","type":"uint256"},{"indexed":false,"name":"generated","type":"uint256"},{"indexed":false,"name":"betted","type":"uint256"},{"indexed":false,"name":"amountWin","type":"uint256"}],"name":"PlayerWin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"gameId","type":"uint256"},{"indexed":false,"name":"generated","type":"uint256"},{"indexed":false,"name":"betted","type":"uint256"}],"name":"PlayerLose","type":"event"}]

  Contract Creation Code Switch To Opcodes View
608060405260018054600160a060020a031990811673e987926a226932dfb1f71fa316461db272e053171782556002805490911673e4e18a49c6f1210ffe9a60dbd38071c6ef78d9821790556000600355600490815560055534801561006457600080fd5b50610982806100746000396000f3006080604052600436106100ae5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663117a5b9081146100cf57806318a1908d1461010e5780631cc2ae461461012b57806320e1483614610155578063355f4aee1461016d578063374f2db3146101825780633ad10ef6146101975780636898f82b146101c85780636d112977146101d357806376809ce3146101f757806383dfb7511461020c575b600254600160a060020a031633146100c557600080fd5b6003805434019055005b3480156100db57600080fd5b506100e7600435610221565b604080519384526020840192909252600160a060020a031682820152519081900360600190f35b34801561011a57600080fd5b5061012960043560243561024b565b005b34801561013757600080fd5b50610143600435610494565b60408051918252519081900360200190f35b34801561016157600080fd5b506101436004356104b0565b34801561017957600080fd5b506101296104c8565b34801561018e57600080fd5b5061014361053d565b3480156101a357600080fd5b506101ac610543565b60408051600160a060020a039092168252519081900360200190f35b610129600435610552565b3480156101df57600080fd5b50610129600480359060248035908101910135610747565b34801561020357600080fd5b5061014361074c565b34801561021857600080fd5b50610143610752565b600660205260009081526040902080546001820154600290920154909190600160a060020a031683565b60008060008060008061025c610758565b600160a060020a031633146102d257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f556e61757468656e7469636174656420726573706f6e73650000000000000000604482015290519081900360640190fd5b600088815260066020526040902060020154600160a060020a031695508515156102fb57600080fd5b60008881526006602052604081208054600180830180548585559490556002909201805473ffffffffffffffffffffffffffffffffffffffff1916905560648a069091019650945092508385101561044957600554600a0a61035c856104b0565b840281151561036757fe5b049150600554600a0a61037985610494565b840281151561038457fe5b604080518b8152602081018990528082018890526060810186905290519290910492507f5ba6978d87d33dc48a9b903e53f9ba993afc24c3cec4662ebb049f3feb2e63c3919081900360800190a1604051600160a060020a0387169083156108fc029084906000818181858888f19350505050158015610408573d6000803e3d6000fd5b50600254604051600160a060020a039091169082156108fc029083906000818181858888f19350505050158015610443573d6000803e3d6000fd5b5061048a565b604080518981526020810187905280820186905290517f1f3b37454fb7a79fbbdb2b278d4d12861aa2568966a67fe984e44249a23953e49181900360600190a15b5050505050505050565b600060018203600554600a0a8115156104a957fe5b0492915050565b600060018203600554600a0a6063028115156104a957fe5b600254600090600160a060020a031633146104e257600080fd5b6104f830600160a060020a0316316003546107e8565b60006003819055600254604051929350600160a060020a03169183156108fc0291849190818181858888f19350505050158015610539573d6000803e3d6000fd5b5050565b60045481565b600254600160a060020a031681565b600060028210158015610566575060608211155b15156105d357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f726f6c6c556e6465722073686f756c6420626520696e20327e39360000000000604482015290519081900360640190fd5b6105dc826104b0565b3402600554600a0a30600160a060020a031631021015151561068557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603d60248201527f47616d6520636f6e747261637420646f65736e2774206861766520656e6f756760448201527f682062616c616e63652c20646563726561736520726f6c6c556e646572000000606482015290519081900360840190fd5b610690600142610800565b6040805160608181018352858252346020808401828152338587018181526000898152600685528890209651875591516001870155905160029095018054600160a060020a039690961673ffffffffffffffffffffffffffffffffffffffff19909616959095179094558451868152908101889052808501919091529081019190915290519192507f9ef9d544e790f4e334968be0722cb42b44cef6c894fb48461c64707fbcad5d16919081900360800190a15050565b505050565b60055481565b60035481565b600154604080517f43a73d9a0000000000000000000000000000000000000000000000000000000081529051600092600160a060020a0316916343a73d9a91600480830192602092919082900301818787803b1580156107b757600080fd5b505af11580156107cb573d6000803e3d6000fd5b505050506040513d60208110156107e157600080fd5b5051905090565b60008183106107f757816107f9565b825b9392505050565b600154604080517f43a73d9a0000000000000000000000000000000000000000000000000000000081529051600092600160a060020a0316916343a73d9a91600480830192602092919082900301818787803b15801561085f57600080fd5b505af1158015610873573d6000803e3d6000fd5b505050506040513d602081101561088957600080fd5b50516000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392831617808255604080517f1bf8205700000000000000000000000000000000000000000000000000000000815230600482015260ff881660248201526044810187905290519190931692631bf820579260648083019360209390929083900390910190829087803b15801561092357600080fd5b505af1158015610937573d6000803e3d6000fd5b505050506040513d602081101561094d57600080fd5b505193925050505600a165627a7a723058208dfd7c370a1e8cc09ee93ebe87ac34c901af349d0f15b22366aef9038b66900b0029

   Swarm Source:
bzzr://8dfd7c370a1e8cc09ee93ebe87ac34c901af349d0f15b22366aef9038b66900b

 

View All
Block Age transaction Difficulty GasUsed Reward
View All
Block Age UncleNumber Difficulty GasUsed Reward