├── README.md ├── eosbocai2222.cpp ├── eosbocai2222.hpp ├── eosio.token.hpp ├── pradata.hpp ├── types.hpp └── utils.hpp /README.md: -------------------------------------------------------------------------------- 1 | # 代碼有被攻擊,目前還沒有查明原因。別用! 2 | -------------------------------------------------------------------------------- /eosbocai2222.cpp: -------------------------------------------------------------------------------- 1 | #include "eosbocai2222.hpp" 2 | 3 | void eosbocai2222::reveal(const uint64_t &id) 4 | { 5 | require_auth(_self); 6 | st_bet bet = find_or_error(id); 7 | uint8_t random_roll = random(bet.player, bet.id); 8 | asset payout = asset(0, bet.amount.symbol); 9 | if (random_roll < bet.roll_under) 10 | { 11 | payout = compute_payout(bet.roll_under, bet.amount); 12 | action(permission_level{_self, N(active)}, 13 | bet.amount.contract, 14 | N(transfer), 15 | make_tuple(_self, bet.player, payout, winner_memo(bet))) 16 | .send(); 17 | } 18 | if (iseostoken(bet.amount)) 19 | { 20 | issue_token(bet.player, bet.amount, "mining! eosdice.vip"); 21 | unlock(bet.amount); 22 | } 23 | 24 | st_result result{.bet_id = bet.id, 25 | .player = bet.player, 26 | .referrer = bet.referrer, 27 | .amount = bet.amount, 28 | .roll_under = bet.roll_under, 29 | .random_roll = random_roll, 30 | .payout = payout}; 31 | 32 | action(permission_level{_self, N(active)}, 33 | LOG, 34 | N(result), 35 | result) 36 | .send(); 37 | action(permission_level{_self, N(active)}, 38 | bet.amount.contract, 39 | N(transfer), 40 | std::make_tuple(_self, DEV, compute_dev_reward(bet), std::string("for dev"))) 41 | .send(); 42 | action(permission_level{_self, N(active)}, 43 | bet.amount.contract, 44 | N(transfer), 45 | make_tuple(_self, 46 | bet.referrer, 47 | compute_referrer_reward(bet), 48 | referrer_memo(bet))) 49 | .send(); 50 | remove(bet.id); 51 | } 52 | void eosbocai2222::reveal1(const uint64_t &id) 53 | { 54 | require_auth(_self); 55 | send_defer_action(permission_level{_self, N(active)}, 56 | _self, 57 | N(reveal), 58 | id); 59 | } 60 | 61 | void eosbocai2222::onTransfer(account_name from, 62 | account_name to, 63 | extended_asset quantity, 64 | string memo) 65 | { 66 | if (from == _self || to != _self) 67 | { 68 | return; 69 | } 70 | if (memo.substr(0, 4) != "dice") 71 | { 72 | return; 73 | } 74 | checkAccount1(from); 75 | uint8_t roll_under; 76 | account_name referrer; 77 | parse_memo(memo, &roll_under, &referrer); 78 | eosio_assert(is_account(referrer), "referrer account does not exist"); 79 | // //check referrer 80 | eosio_assert(referrer != from, "referrer can not be self"); 81 | 82 | // //check roll_under 83 | assert_roll_under(roll_under, quantity); 84 | // //check quantity 85 | assert_quantity(quantity); 86 | 87 | const st_bet _bet{.id = next_id(), 88 | .player = from, 89 | .referrer = referrer, 90 | .amount = quantity, 91 | .roll_under = roll_under, 92 | .created_at = now()}; 93 | save(_bet); 94 | if (iseostoken(quantity)) 95 | { 96 | //count player 97 | iplay(from, quantity); 98 | 99 | //vip check 100 | vipcheck(from, quantity); 101 | 102 | lock(quantity); 103 | fomo(_bet); 104 | } 105 | 106 | action(permission_level{_self, N(active)}, 107 | _bet.amount.contract, 108 | N(transfer), 109 | std::make_tuple(_self, N(eosbocai1111), compute_pool_reward(_bet), std::string("Dividing pool"))) 110 | .send(); 111 | send_defer_action(permission_level{_self, N(active)}, 112 | _self, 113 | N(reveal1), 114 | _bet.id); 115 | } 116 | void eosbocai2222::addtoken(account_name contract, asset quantity) 117 | { 118 | require_auth(_self); 119 | _tokens.emplace(_self, [&](auto &r) { 120 | r.contract = contract; 121 | r.symbol = quantity.symbol; 122 | r.minAmout = quantity.amount; 123 | }); 124 | } 125 | void eosbocai2222::init() 126 | { 127 | require_auth(_self); 128 | st_global global = _global.get_or_default(); 129 | 130 | global.current_id = 515789; 131 | global.nexthalve = 7524000000 * 1e4; 132 | global.eosperdice = 100; 133 | global.initStatu = 1; 134 | global.lastPlayer = N(eosbocai1111); 135 | global.endtime = now() + 60 * 5; 136 | global.fomopool = asset(0, EOS_SYMBOL); 137 | _global.set(global, _self); 138 | } 139 | -------------------------------------------------------------------------------- /eosbocai2222.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "eosio.token.hpp" 4 | #include "types.hpp" 5 | #include "pradata.hpp" 6 | 7 | class eosbocai2222 : public contract 8 | { 9 | public: 10 | eosbocai2222(account_name self) 11 | : contract(self), 12 | _bets(_self, _self), 13 | _users(_self, _self), 14 | _fund_pool(_self, _self), 15 | _tokens(_self, _self), 16 | _global(_self, _self){}; 17 | 18 | // @abi action 19 | void transfer(account_name from, 20 | account_name to, 21 | asset quantity, 22 | string memo); 23 | 24 | void onTransfer(account_name from, 25 | account_name to, 26 | extended_asset quantity, 27 | string memo); 28 | 29 | // @abi action 30 | void reveal(const uint64_t &id); 31 | // @abi action 32 | void reveal1(const uint64_t &id); 33 | 34 | // @abi action 35 | void addtoken(account_name contract, asset quantity); 36 | 37 | // @abi action 38 | void init(); 39 | 40 | void apply(account_name code, action_name action); 41 | 42 | private: 43 | tb_bets _bets; 44 | tb_uesrs _users; 45 | tb_fund_pool _fund_pool; 46 | tb_global _global; 47 | tb_tokens _tokens; 48 | 49 | void parse_memo(string memo, 50 | uint8_t *roll_under, 51 | account_name *referrer) 52 | { 53 | // remove space 54 | memo.erase(std::remove_if(memo.begin(), 55 | memo.end(), 56 | [](unsigned char x) { return std::isspace(x); }), 57 | memo.end()); 58 | 59 | size_t sep_count = std::count(memo.begin(), memo.end(), '-'); 60 | eosio_assert(sep_count == 3, "invalid memo"); 61 | 62 | size_t pos; 63 | string container; 64 | pos = sub2sep(memo, &container, '-', 0, true); 65 | pos = sub2sep(memo, &container, '-', ++pos, true); 66 | pos = sub2sep(memo, &container, '-', ++pos, true); 67 | eosio_assert(!container.empty(), "no roll under"); 68 | *roll_under = stoi(container); 69 | container = memo.substr(++pos); 70 | if (container.empty()) 71 | { 72 | *referrer = PRIZEPOOL; 73 | } 74 | else 75 | { 76 | *referrer = string_to_name(container.c_str()); 77 | } 78 | } 79 | 80 | asset compute_referrer_reward(const st_bet &bet) { return bet.amount * 2 / 1000; } //10% for ref 81 | asset compute_dev_reward(const st_bet &bet) { return bet.amount * 4 / 1000; } // 20% for dev 82 | asset compute_pool_reward(const st_bet &bet) { return bet.amount * 12 / 1000; } // 60% for pool 83 | asset compute_fomopool_reward(const st_bet &bet) { return bet.amount * 2 / 1000; } // 10% for fomo pool 84 | 85 | uint64_t next_id() 86 | { 87 | st_global global = _global.get_or_default(); 88 | global.current_id += 1; 89 | _global.set(global, _self); 90 | return global.current_id; 91 | } 92 | 93 | string referrer_memo(const st_bet &bet) 94 | { 95 | string memo = "bet id:"; 96 | string id = uint64_string(bet.id); 97 | memo.append(id); 98 | memo.append(" player: "); 99 | string player = name{bet.player}.to_string(); 100 | memo.append(player); 101 | memo.append(" referral reward! eosdice.vip"); 102 | return memo; 103 | } 104 | 105 | string winner_memo(const st_bet &bet) 106 | { 107 | string memo = "bet id:"; 108 | string id = uint64_string(bet.id); 109 | memo.append(id); 110 | memo.append(" player: "); 111 | string player = name{bet.player}.to_string(); 112 | memo.append(player); 113 | memo.append(" winner! eosdice.vip"); 114 | return memo; 115 | } 116 | 117 | void assert_quantity(const extended_asset &quantity) 118 | { 119 | auto itr = _tokens.find(quantity.contract + quantity.symbol); 120 | eosio_assert(itr != _tokens.end(), "Non-existent token"); 121 | eosio_assert(quantity.is_valid(), "quantity invalid"); 122 | eosio_assert(quantity.amount >= itr->minAmout, "transfer quantity must be greater than minimum"); 123 | } 124 | bool iseostoken(const extended_asset &quantity) 125 | { 126 | if ((quantity.contract == N(eosio.token)) && (quantity.symbol == EOS_SYMBOL)) 127 | { 128 | return true; 129 | } 130 | return false; 131 | } 132 | 133 | void assert_roll_under(const uint8_t &roll_under, const extended_asset &quantity) 134 | { 135 | eosio_assert(roll_under >= 2 && roll_under <= 96, 136 | "roll under overflow, must be greater than 2 and less than 96"); 137 | eosio_assert( 138 | max_payout(roll_under, quantity) <= max_bonus(quantity), 139 | "offered overflow, expected earning is greater than the maximum bonus"); 140 | } 141 | 142 | void unlock(const asset &amount) 143 | { 144 | st_fund_pool pool = get_fund_pool(); 145 | pool.locked -= amount; 146 | eosio_assert(pool.locked.amount >= 0, "fund unlock error"); 147 | _fund_pool.set(pool, _self); 148 | } 149 | 150 | void lock(const asset &amount) 151 | { 152 | st_fund_pool pool = get_fund_pool(); 153 | pool.locked += amount; 154 | _fund_pool.set(pool, _self); 155 | } 156 | 157 | asset compute_payout(const uint8_t &roll_under, const extended_asset &offer) 158 | { 159 | return min(max_payout(roll_under, offer), max_bonus(offer)); 160 | } 161 | asset max_payout(const uint8_t &roll_under, const asset &offer) 162 | { 163 | const double ODDS = 98 / ((double)roll_under - 1.0); 164 | return asset(ODDS * offer.amount, offer.symbol); 165 | } 166 | 167 | asset max_bonus(const extended_asset &quantity) { return available_balance(quantity) / 10; } //Transfer balance to secure account 168 | 169 | asset available_balance(const extended_asset &quantity) 170 | { 171 | auto token = eosio::token(quantity.contract); 172 | const asset balance = 173 | token.get_balance(_self, symbol_type(quantity.symbol).name()); 174 | asset available; 175 | if (iseostoken(quantity)) 176 | { 177 | const asset locked = get_fund_pool().locked; 178 | available = balance - locked; 179 | } 180 | else 181 | { 182 | available = balance; 183 | } 184 | eosio_assert(available.amount >= 0, "fund pool overdraw"); 185 | return available; 186 | } 187 | 188 | st_fund_pool get_fund_pool() 189 | { 190 | st_fund_pool fund_pool{.locked = asset(0, EOS_SYMBOL)}; 191 | return _fund_pool.get_or_create(_self, fund_pool); 192 | } 193 | 194 | template 195 | void send_defer_action(Args &&... args) 196 | { 197 | transaction trx; 198 | trx.actions.emplace_back(std::forward(args)...); 199 | trx.delay_sec = 1; 200 | trx.send(next_id(), _self, false); 201 | } 202 | 203 | uint64_t getDiceSupply() 204 | { 205 | auto eos_token = eosio::token(DICETOKEN); 206 | auto supply = eos_token.get_supply(symbol_type(DICE_SYMBOL).name()); 207 | return supply.amount; 208 | } 209 | uint8_t random(account_name name, uint64_t game_id) 210 | { 211 | auto mixd = tapos_block_prefix() * tapos_block_num() + name + game_id - current_time(); 212 | const char *mixedChar = reinterpret_cast(&mixd); 213 | checksum256 result; 214 | sha256((char *)mixedChar, sizeof(mixedChar), &result); 215 | 216 | uint64_t random_num = *(uint64_t *)(&result.hash[0]) + *(uint64_t *)(&result.hash[8]) + *(uint64_t *)(&result.hash[16]) + *(uint64_t *)(&result.hash[24]); 217 | return (uint8_t)(random_num % 100 + 1); 218 | } 219 | void issue_token(account_name to, 220 | asset quantity, 221 | string memo) 222 | { 223 | st_global global = _global.get_or_default(); 224 | auto supply = getDiceSupply(); 225 | auto nexthalve = global.nexthalve; 226 | if ((DICESUPPLY - supply) <= nexthalve) 227 | { 228 | global.nexthalve = global.nexthalve * 95 / 100; 229 | global.eosperdice = global.eosperdice * 3 / 4; 230 | _global.set(global, _self); 231 | } 232 | 233 | asset sendAmout = asset(quantity.amount * global.eosperdice, DICE_SYMBOL); 234 | action(permission_level{_self, N(active)}, 235 | DICETOKEN, 236 | N(issue), 237 | make_tuple(to, sendAmout, memo)) 238 | .send(); 239 | } 240 | void iplay(account_name from, asset quantity) 241 | { 242 | tb_uesrs1 _users1(_self, from); 243 | auto v = _users1.get_or_create(_self, st_user1{}); 244 | v.amount += quantity; 245 | v.count += 1; 246 | _users1.set(v, _self); 247 | } 248 | void fomo(const st_bet &bet) 249 | { 250 | st_global global = _global.get_or_default(); 251 | global.fomopool += compute_fomopool_reward(bet); 252 | if (bet.amount.amount > global.fomopool.amount / 1000) 253 | { 254 | if (now() > global.endtime) //winner winner chicken dinner 255 | { 256 | action(permission_level{_self, N(active)}, 257 | N(eosio.token), 258 | N(transfer), 259 | std::make_tuple(_self, global.lastPlayer, global.fomopool / 2, std::string("Congratulations, win the fomo award! eosdice.vip "))) 260 | .send(); 261 | global.fomopool /= 2; 262 | } 263 | 264 | global.lastPlayer = bet.player; 265 | global.endtime = now() + 60 * 60; 266 | } 267 | _global.set(global, _self); 268 | } 269 | void save(const st_bet &bet) 270 | { 271 | _bets.emplace(_self, [&](st_bet &r) { 272 | r.id = bet.id; 273 | r.player = bet.player; 274 | r.referrer = bet.referrer; 275 | r.amount = bet.amount; 276 | r.roll_under = bet.roll_under; 277 | r.created_at = bet.created_at; 278 | }); 279 | } 280 | void remove(const uint64_t bet_id) { _bets.erase(_bets.find(bet_id)); } 281 | st_bet find_or_error(const uint64_t &id) 282 | { 283 | auto itr = _bets.find(id); 284 | eosio_assert(itr != _bets.end(), "bet not found"); 285 | return *itr; 286 | } 287 | void vipcheck(account_name from, asset quantity) 288 | { 289 | tb_uesrs1 _users1(_self, from); 290 | auto v = _users1.get_or_create(_self, st_user1{}); 291 | uint64_t amount = v.amount.amount / 1e4; 292 | asset checkout = asset(0, EOS_SYMBOL); 293 | if (amount < 1000) 294 | { 295 | return; 296 | } 297 | else if (amount < 5000) 298 | { 299 | checkout = asset(quantity.amount * 1 / 10000, EOS_SYMBOL); 300 | } 301 | else if (amount < 10000) 302 | { 303 | checkout = asset(quantity.amount * 2 / 10000, EOS_SYMBOL); 304 | } 305 | else if (amount < 50000) 306 | { 307 | checkout = asset(quantity.amount * 3 / 10000, EOS_SYMBOL); 308 | } 309 | else if (amount < 100000) 310 | { 311 | checkout = asset(quantity.amount * 4 / 10000, EOS_SYMBOL); 312 | } 313 | else if (amount < 500000) 314 | { 315 | checkout = asset(quantity.amount * 5 / 10000, EOS_SYMBOL); 316 | } 317 | else if (amount < 1000000) 318 | { 319 | checkout = asset(quantity.amount * 7 / 10000, EOS_SYMBOL); 320 | } 321 | else if (amount < 5000000) 322 | { 323 | checkout = asset(quantity.amount * 9 / 10000, EOS_SYMBOL); 324 | } 325 | else if (amount < 10000000) 326 | { 327 | checkout = asset(quantity.amount * 11 / 10000, EOS_SYMBOL); 328 | } 329 | else if (amount < 50000000) 330 | { 331 | checkout = asset(quantity.amount * 13 / 10000, EOS_SYMBOL); 332 | } 333 | else 334 | { 335 | checkout = asset(quantity.amount * 15 / 10000, EOS_SYMBOL); 336 | } 337 | action(permission_level{_self, N(active)}, 338 | N(eosio.token), 339 | N(transfer), 340 | std::make_tuple(_self, from, checkout, std::string("for vip! eosdice.vip"))) 341 | .send(); 342 | } 343 | void checkAccount1(account_name from) 344 | { 345 | auto db = prochain::rating_index(N(rating.pra), N(rating.pra)); 346 | auto me = db.find(from); 347 | if (me != db.end()) 348 | { 349 | auto account_type = me->account_type; 350 | eosio_assert(account_type == 0, "Human only"); 351 | } 352 | } 353 | }; 354 | struct st_transfer 355 | { 356 | account_name from; 357 | account_name to; 358 | asset quantity; 359 | string memo; 360 | }; 361 | 362 | void eosbocai2222::apply(account_name code, action_name action) 363 | { 364 | auto &thiscontract = *this; 365 | 366 | if (action == N(transfer)) 367 | { 368 | auto transfer_data = unpack_action_data(); 369 | onTransfer(transfer_data.from, transfer_data.to, extended_asset(transfer_data.quantity, code), transfer_data.memo); 370 | return; 371 | } 372 | 373 | if (code != _self) 374 | return; 375 | switch (action) 376 | { 377 | EOSIO_API(eosbocai2222, (reveal)(init)(reveal1)(addtoken)); 378 | }; 379 | } 380 | 381 | extern "C" 382 | { 383 | [[noreturn]] void apply(uint64_t receiver, uint64_t code, uint64_t action) { 384 | eosbocai2222 p(receiver); 385 | p.apply(code, action); 386 | eosio_exit(0); 387 | } 388 | } 389 | -------------------------------------------------------------------------------- /eosio.token.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @copyright defined in eos/LICENSE.txt 4 | */ 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace eosiosystem 13 | { 14 | class system_contract; 15 | } 16 | 17 | namespace eosio 18 | { 19 | 20 | using std::string; 21 | 22 | class token : public contract 23 | { 24 | public: 25 | token(account_name self) : contract(self) {} 26 | 27 | void create(account_name issuer, 28 | asset maximum_supply); 29 | 30 | void issue(account_name to, asset quantity, string memo); 31 | 32 | void retire(asset quantity, string memo); 33 | 34 | void transfer(account_name from, 35 | account_name to, 36 | asset quantity, 37 | string memo); 38 | 39 | void close(account_name owner, symbol_type symbol); 40 | 41 | inline asset get_supply(symbol_name sym) const; 42 | 43 | inline asset get_balance(account_name owner, symbol_name sym) const; 44 | 45 | private: 46 | struct account 47 | { 48 | asset balance; 49 | 50 | uint64_t primary_key() const { return balance.symbol.name(); } 51 | }; 52 | 53 | struct currency_stats 54 | { 55 | asset supply; 56 | asset max_supply; 57 | account_name issuer; 58 | 59 | uint64_t primary_key() const { return supply.symbol.name(); } 60 | }; 61 | 62 | typedef eosio::multi_index accounts; 63 | typedef eosio::multi_index stats; 64 | 65 | void sub_balance(account_name owner, asset value); 66 | void add_balance(account_name owner, asset value, account_name ram_payer); 67 | 68 | public: 69 | struct transfer_args 70 | { 71 | account_name from; 72 | account_name to; 73 | asset quantity; 74 | string memo; 75 | }; 76 | }; 77 | 78 | asset token::get_supply(symbol_name sym) const 79 | { 80 | stats statstable(_self, sym); 81 | const auto &st = statstable.get(sym); 82 | return st.supply; 83 | } 84 | 85 | asset token::get_balance(account_name owner, symbol_name sym) const 86 | { 87 | accounts accountstable(_self, owner); 88 | const auto &ac = accountstable.get(sym); 89 | return ac.balance; 90 | } 91 | 92 | } // namespace eosio 93 | -------------------------------------------------------------------------------- /pradata.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace prochain 7 | { 8 | 9 | // @abi table trating i64 10 | struct Rating 11 | { 12 | account_name account; //eos account name 13 | uint8_t account_type; //enum_account_type: 0, normal account; 1, code account; 14 | uint8_t normal_account_level; //rating level for normal account, from 0 to 10 15 | uint8_t code_account_level; //rating level for code account, from 0 to 10 16 | 17 | uint64_t primary_key() const { return account; } 18 | EOSLIB_SERIALIZE(Rating, (account)(account_type)(normal_account_level)(code_account_level)); 19 | }; 20 | typedef eosio::multi_index rating_index; 21 | 22 | //account type 23 | enum enum_account_type 24 | { 25 | normal_account = 0, // 0: normal account 26 | code_account, // 1: code account 27 | account_type_count 28 | }; 29 | 30 | //level defined for both normal and code account 31 | uint8_t BP_BLACKLIST = 0; 32 | 33 | //level defined for normal account 34 | uint8_t PRABOX_BLACKLIST = 2; 35 | uint8_t PRABOX_GREYLIST = 3; 36 | uint8_t PRABOX_AUTH_VERYFIED = 6; 37 | uint8_t PRABOX_KYC_VERYFIED = 6; 38 | 39 | //level defined for code account 40 | uint8_t MALICIOUS_CODE_ACCOUNT = 0; 41 | 42 | //call back results 43 | std::string RESULT_FOUND = "FOUND"; 44 | std::string RESULT_NOTFOUND = "NOTFOUND"; 45 | 46 | } // namespace prochain 47 | -------------------------------------------------------------------------------- /types.hpp: -------------------------------------------------------------------------------- 1 | #include "utils.hpp" 2 | #include 3 | 4 | #define EOS_SYMBOL S(4, EOS) 5 | #define DICE_SYMBOL S(4, BOCAI) 6 | #define LOG N(eosbocailogs) 7 | #define DICETOKEN N(eosbocai1111) 8 | #define DEV N(eosbocaidevv) 9 | #define PRIZEPOOL N(eosbocai1111) 10 | #define DICESUPPLY 88000000000000 11 | #define FOMOTIME 24 * 60 * 60 12 | 13 | typedef uint32_t eostime; 14 | using eosio::extended_asset; 15 | using eosio::singleton; 16 | 17 | // @abi table bets i64 18 | struct st_bet 19 | { 20 | uint64_t id; 21 | account_name player; 22 | account_name referrer; 23 | extended_asset amount; 24 | uint8_t roll_under; 25 | uint64_t created_at; 26 | uint64_t primary_key() const { return id; } 27 | }; 28 | // @abi table tokens i64 29 | struct st_tokens 30 | { 31 | account_name contract; // 合约账号 32 | symbol_type symbol; // 代币名称 33 | uint64_t minAmout; //最小允许投注的值 34 | uint64_t primary_key() const { return contract + symbol; } 35 | }; 36 | typedef multi_index tb_tokens; 37 | 38 | // @abi table users1 i64 39 | struct st_user1 40 | { 41 | asset amount = asset(0, EOS_SYMBOL); 42 | uint32_t count = 0; 43 | }; 44 | 45 | // @abi table users i64 46 | struct st_user 47 | { 48 | account_name owner; 49 | asset amount; 50 | uint32_t count; 51 | uint64_t primary_key() const { return owner; } 52 | }; 53 | typedef singleton tb_uesrs1; 54 | 55 | struct st_result 56 | { 57 | uint64_t bet_id; 58 | account_name player; 59 | account_name referrer; 60 | asset amount; 61 | uint8_t roll_under; 62 | uint8_t random_roll; 63 | asset payout; 64 | }; 65 | 66 | // @abi table fundpool i64 67 | struct st_fund_pool 68 | { 69 | asset locked; 70 | }; 71 | 72 | // @abi table global i64 73 | struct st_global 74 | { 75 | uint64_t current_id; 76 | double eosperdice; 77 | uint64_t nexthalve; 78 | uint64_t initStatu; 79 | account_name lastPlayer; 80 | eostime endtime; 81 | asset fomopool; 82 | }; 83 | 84 | // typedef multi_index tb_uesrs; 85 | typedef multi_index tb_bets; 86 | typedef multi_index tb_uesrs; 87 | 88 | typedef singleton tb_fund_pool; 89 | typedef singleton tb_global; 90 | -------------------------------------------------------------------------------- /utils.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace eosio; 10 | using namespace std; 11 | 12 | string uint64_string(uint64_t input) 13 | { 14 | string result; 15 | uint8_t base = 10; 16 | do 17 | { 18 | char c = input % base; 19 | input /= base; 20 | if (c < 10) 21 | c += '0'; 22 | else 23 | c += 'A' - 10; 24 | result = c + result; 25 | } while (input); 26 | return result; 27 | } 28 | 29 | size_t sub2sep(const string &input, 30 | string *output, 31 | const char &separator, 32 | const size_t &first_pos = 0, 33 | const bool &required = false) 34 | { 35 | eosio_assert(first_pos != string::npos, "invalid first pos"); 36 | auto pos = input.find(separator, first_pos); 37 | if (pos == string::npos) 38 | { 39 | eosio_assert(!required, "parse memo error"); 40 | return string::npos; 41 | } 42 | *output = input.substr(first_pos, pos - first_pos); 43 | return pos; 44 | } 45 | --------------------------------------------------------------------------------