├── test ├── .gitkeep └── roulette.js ├── contracts ├── .gitkeep ├── Migrations.sol └── Roulette.sol ├── .gitignore ├── bs-config.json ├── src ├── images │ ├── logo.png │ ├── wheel.png │ └── layout.png ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ ├── glyphicons-halflings-regular.woff2 │ └── glyphicons-halflings-regular.svg ├── css │ └── main.css ├── index.html └── js │ ├── app.js │ └── bootstrap.min.js ├── migrations ├── 2_deploy_contract.js └── 1_initial_migration.js ├── truffle.js ├── package.json └── README.md /test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | -------------------------------------------------------------------------------- /bs-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "server": { 3 | "baseDir": ["./src", "./build/contracts"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bordalix/ethereum-roulette/HEAD/src/images/logo.png -------------------------------------------------------------------------------- /src/images/wheel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bordalix/ethereum-roulette/HEAD/src/images/wheel.png -------------------------------------------------------------------------------- /src/images/layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bordalix/ethereum-roulette/HEAD/src/images/layout.png -------------------------------------------------------------------------------- /src/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bordalix/ethereum-roulette/HEAD/src/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bordalix/ethereum-roulette/HEAD/src/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bordalix/ethereum-roulette/HEAD/src/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bordalix/ethereum-roulette/HEAD/src/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /migrations/2_deploy_contract.js: -------------------------------------------------------------------------------- 1 | const Roulette = artifacts.require('./Roulette.sol') 2 | module.exports = function(deployer) { 3 | deployer.deploy(Roulette); 4 | } -------------------------------------------------------------------------------- /migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // for more about customizing your Truffle configuration! 4 | networks: { 5 | development: { 6 | host: "127.0.0.1", 7 | port: 7545, 8 | network_id: "*" // Match any network id 9 | } 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /src/css/main.css: -------------------------------------------------------------------------------- 1 | * { 2 | -webkit-text-size-adjust: none; 3 | } 4 | 5 | img#wheel { 6 | -webkit-transition: -webkit-transform 2s ease-out; 7 | width: auto; 8 | height: 225px; 9 | } 10 | 11 | p#warning { 12 | text-align: center; 13 | background-color: red; 14 | font-size: 1.4rem; 15 | font-weight: 600; 16 | color: white; 17 | padding: 10px; 18 | display: none; 19 | } 20 | 21 | p#warning a { 22 | color: white; 23 | text-decoration: underline; 24 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pet-shop", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "truffle.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "dev": "lite-server", 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "author": "", 14 | "license": "ISC", 15 | "devDependencies": { 16 | "lite-server": "^2.3.0" 17 | }, 18 | "dependencies": { 19 | "lodash": ">=4.17.19" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.22; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | constructor() public { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/roulette.js: -------------------------------------------------------------------------------- 1 | var Roulette = artifacts.require("Roulette"); 2 | 3 | contract('Roulette', function(accounts) { 4 | const oneEther = 1000000000000000000; 5 | const betAmount = 10000000000000000; // 0.01 ether 6 | it("get the size of the contract", function() { 7 | return Roulette.deployed().then(function(instance) { 8 | var bytecode = instance.constructor._json.bytecode; 9 | var deployed = instance.constructor._json.deployedBytecode; 10 | var sizeOfB = bytecode.length / 2; 11 | var sizeOfD = deployed.length / 2; 12 | console.log("size of bytecode in bytes = ", sizeOfB); 13 | console.log("size of deployed in bytes = ", sizeOfD); 14 | console.log("initialisation and constructor code in bytes = ", sizeOfB - sizeOfD); 15 | }); 16 | }); 17 | it("betting should increase number of bets", function() { 18 | let betsCounter; 19 | let roulette; 20 | return Roulette.deployed().then(function(instance) { 21 | roulette = instance; 22 | return roulette.getStatus.call(); 23 | }).then(function(statusArray) { 24 | betsCounter = statusArray[0].toNumber(); 25 | return roulette.addEther({value: oneEther, from: accounts[0]}); 26 | }).then(function() { 27 | return roulette.bet(13, 5, {value: betAmount, from: accounts[0]}); 28 | }).then(function() { 29 | return roulette.getStatus.call(); 30 | }).then(function(newStatusArray) { 31 | assert.equal(betsCounter + 1, newStatusArray[0].toNumber()); 32 | }) 33 | }); 34 | it("betting should increase the value of bets", function() { 35 | let betsValue; 36 | let roulette; 37 | return Roulette.deployed().then(function(instance) { 38 | roulette = instance; 39 | return roulette.getStatus.call(); 40 | }).then(function(statusArray) { 41 | betsValue = statusArray[1].toNumber(); 42 | return roulette.addEther({value: oneEther, from: accounts[0]}); 43 | }).then(function() { 44 | return roulette.bet(13, 5, {value: betAmount, from: accounts[0]}); 45 | }).then(function() { 46 | return roulette.getStatus.call(); 47 | }).then(function(newStatusArray) { 48 | assert.equal(betsValue + betAmount, newStatusArray[1].toNumber()); 49 | }) 50 | }); 51 | it("spinning the wheel should reset bets and give winnings", function() { 52 | let betsValue; 53 | let roulette; 54 | return Roulette.deployed().then(function(instance) { 55 | roulette = instance; 56 | return roulette.addEther({value: oneEther, from: accounts[0]}); 57 | }).then(function() { 58 | return roulette.bet(0, 0, {value: betAmount, from: accounts[0]}); 59 | }).then(function() { 60 | return roulette.bet(1, 0, {value: betAmount, from: accounts[0]}); 61 | }).then(function() { 62 | return roulette.spinWheel({from: accounts[0]}) 63 | }).then(function() { 64 | return roulette.getStatus.call(); 65 | }).then(function(statusArray) { 66 | assert.equal(statusArray[0].toNumber(), 0); // reseted bets length? 67 | assert.equal(statusArray[1].toNumber(), 0); // reseted bets value? 68 | assert.equal(statusArray[4].toNumber(), 2 * betAmount); // winnings? 69 | }) 70 | }); 71 | }); -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Ethereum Roulette 10 | 11 | 12 | 13 | 14 |

15 |
16 |
17 |
18 |

Ethereum Roulette

19 |

A casino roulette PoC deployed on the ethereum ropsten test network

20 |

21 | 22 | github 23 | 24 |   ·   25 | 26 | etherscan 27 | 28 |

29 |
30 |

 

31 |
32 |
33 |
34 |
35 |

ROULETTE DATA

36 |

Roulette balance:

37 |

Your balance:

38 |

39 | Your winnings: 40 | 41 |

42 |

Bets counter:

43 |

Bets value:

44 |

Time until next spin:

45 |
46 |
47 |

48 | 49 |

50 | 51 |

52 |
53 |

Click on the board to make your bet:

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |

Your bets:

107 |
108 |
109 |
110 |
111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /contracts/Roulette.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.22; 2 | 3 | contract Roulette { 4 | 5 | uint betAmount; 6 | uint necessaryBalance; 7 | uint nextRoundTimestamp; 8 | address creator; 9 | uint256 maxAmountAllowedInTheBank; 10 | mapping (address => uint256) winnings; 11 | uint8[] payouts; 12 | uint8[] numberRange; 13 | 14 | /* 15 | BetTypes are as follow: 16 | 0: color 17 | 1: column 18 | 2: dozen 19 | 3: eighteen 20 | 4: modulus 21 | 5: number 22 | 23 | Depending on the BetType, number will be: 24 | color: 0 for black, 1 for red 25 | column: 0 for left, 1 for middle, 2 for right 26 | dozen: 0 for first, 1 for second, 2 for third 27 | eighteen: 0 for low, 1 for high 28 | modulus: 0 for even, 1 for odd 29 | number: number 30 | */ 31 | 32 | struct Bet { 33 | address player; 34 | uint8 betType; 35 | uint8 number; 36 | } 37 | Bet[] public bets; 38 | 39 | constructor() public payable { 40 | creator = msg.sender; 41 | necessaryBalance = 0; 42 | nextRoundTimestamp = now; 43 | payouts = [2,3,3,2,2,36]; 44 | numberRange = [1,2,2,1,1,36]; 45 | betAmount = 10000000000000000; /* 0.01 ether */ 46 | maxAmountAllowedInTheBank = 2000000000000000000; /* 2 ether */ 47 | } 48 | 49 | event RandomNumber(uint256 number); 50 | 51 | function getStatus() public view returns(uint, uint, uint, uint, uint) { 52 | return ( 53 | bets.length, // number of active bets 54 | bets.length * betAmount, // value of active bets 55 | nextRoundTimestamp, // when can we play again 56 | address(this).balance, // roulette balance 57 | winnings[msg.sender] // winnings of player 58 | ); 59 | } 60 | 61 | function addEther() payable public {} 62 | 63 | function bet(uint8 number, uint8 betType) payable public { 64 | /* 65 | A bet is valid when: 66 | 1 - the value of the bet is correct (=betAmount) 67 | 2 - betType is known (between 0 and 5) 68 | 3 - the option betted is valid (don't bet on 37!) 69 | 4 - the bank has sufficient funds to pay the bet 70 | */ 71 | require(msg.value == betAmount); // 1 72 | require(betType >= 0 && betType <= 5); // 2 73 | require(number >= 0 && number <= numberRange[betType]); // 3 74 | uint payoutForThisBet = payouts[betType] * msg.value; 75 | uint provisionalBalance = necessaryBalance + payoutForThisBet; 76 | require(provisionalBalance < address(this).balance); // 4 77 | /* we are good to go */ 78 | necessaryBalance += payoutForThisBet; 79 | bets.push(Bet({ 80 | betType: betType, 81 | player: msg.sender, 82 | number: number 83 | })); 84 | } 85 | 86 | function spinWheel() public { 87 | /* are there any bets? */ 88 | require(bets.length > 0); 89 | /* are we allowed to spin the wheel? */ 90 | require(now > nextRoundTimestamp); 91 | /* next time we are allowed to spin the wheel again */ 92 | nextRoundTimestamp = now; 93 | /* calculate 'random' number */ 94 | uint diff = block.difficulty; 95 | bytes32 hash = blockhash(block.number-1); 96 | Bet memory lb = bets[bets.length-1]; 97 | uint number = uint(keccak256(abi.encodePacked(now, diff, hash, lb.betType, lb.player, lb.number))) % 37; 98 | /* check every bet for this number */ 99 | for (uint i = 0; i < bets.length; i++) { 100 | bool won = false; 101 | Bet memory b = bets[i]; 102 | if (number == 0) { 103 | won = (b.betType == 5 && b.number == 0); /* bet on 0 */ 104 | } else { 105 | if (b.betType == 5) { 106 | won = (b.number == number); /* bet on number */ 107 | } else if (b.betType == 4) { 108 | if (b.number == 0) won = (number % 2 == 0); /* bet on even */ 109 | if (b.number == 1) won = (number % 2 == 1); /* bet on odd */ 110 | } else if (b.betType == 3) { 111 | if (b.number == 0) won = (number <= 18); /* bet on low 18s */ 112 | if (b.number == 1) won = (number >= 19); /* bet on high 18s */ 113 | } else if (b.betType == 2) { 114 | if (b.number == 0) won = (number <= 12); /* bet on 1st dozen */ 115 | if (b.number == 1) won = (number > 12 && number <= 24); /* bet on 2nd dozen */ 116 | if (b.number == 2) won = (number > 24); /* bet on 3rd dozen */ 117 | } else if (b.betType == 1) { 118 | if (b.number == 0) won = (number % 3 == 1); /* bet on left column */ 119 | if (b.number == 1) won = (number % 3 == 2); /* bet on middle column */ 120 | if (b.number == 2) won = (number % 3 == 0); /* bet on right column */ 121 | } else if (b.betType == 0) { 122 | if (b.number == 0) { /* bet on black */ 123 | if (number <= 10 || (number >= 20 && number <= 28)) { 124 | won = (number % 2 == 0); 125 | } else { 126 | won = (number % 2 == 1); 127 | } 128 | } else { /* bet on red */ 129 | if (number <= 10 || (number >= 20 && number <= 28)) { 130 | won = (number % 2 == 1); 131 | } else { 132 | won = (number % 2 == 0); 133 | } 134 | } 135 | } 136 | } 137 | /* if winning bet, add to player winnings balance */ 138 | if (won) { 139 | winnings[b.player] += betAmount * payouts[b.betType]; 140 | } 141 | } 142 | /* delete all bets */ 143 | bets.length = 0; 144 | /* reset necessaryBalance */ 145 | necessaryBalance = 0; 146 | /* check if to much money in the bank */ 147 | if (address(this).balance > maxAmountAllowedInTheBank) takeProfits(); 148 | /* returns 'random' number to UI */ 149 | emit RandomNumber(number); 150 | } 151 | 152 | function cashOut() public { 153 | address player = msg.sender; 154 | uint256 amount = winnings[player]; 155 | require(amount > 0); 156 | require(amount <= address(this).balance); 157 | winnings[player] = 0; 158 | player.transfer(amount); 159 | } 160 | 161 | function takeProfits() internal { 162 | uint amount = address(this).balance - maxAmountAllowedInTheBank; 163 | if (amount > 0) creator.transfer(amount); 164 | } 165 | 166 | function creatorKill() public { 167 | require(msg.sender == creator); 168 | selfdestruct(creator); 169 | } 170 | 171 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ethereum Roulette 2 | 3 | A Proof of Concept casino roulette, deployed on the ropsten network. 4 | 5 | [http://ethereum-roulette.ga](http://ethereum-roulette.ga) 6 | 7 | **Table of contents** 8 | 9 | - [Motivation](#motivation) 10 | - [How to play](#how-to-play) 11 | - [Randomness](#randomness) 12 | - [Security](#security) 13 | - [Clone repo](#clone-repo) 14 | 15 | ### Motivation 16 | 17 | I decided to learn more about developing smart contracts, and since I learn by 18 | building stuff, I decided to implement a casino roulette, with the business 19 | logic being implemented in Solidity, the language of choice to develop smart 20 | contracts in the Ethereum blockchain. 21 | 22 | The frontend is a regular html page, with the web3 javascript library, which 23 | makes it possible to interact with the Ethereum blockchain via javascript. 24 | The web3 library is injected in the page by the Chrome extension 25 | [Metamask](https://metamask.io/). 26 | 27 | ### How to play 28 | 29 | You’ll have to use the Metamask Chrome extension installed, have an account 30 | on the ropsten network, have some ether (get some 31 | [here](http://faucet.ropsten.be:3001/) or [here](https://faucet.metamask.io/)), 32 | and visit the dapp url: 33 | 34 | [http://ethereum-roulette.ga](http://ethereum-roulette.ga) 35 | 36 | Every bet has a fixed amount of 0.01 ether (around €6) and you can bet by 37 | clicking on the board: 38 | 39 | - On a number (0 to 36), with a payout of 36; 40 | - On a dozen (1-12, 13-24, 25-36), with a payout of 3; 41 | - On a color (black or red), with a payout of 2; 42 | - If the number is even or odd, with a payout of 2; 43 | - On a column (left, middle or right), with a payout of 3. 44 | 45 | The roulette just accepts a bet when has sufficient funds to pay for it 46 | and every other active bet. 47 | 48 | Different people can be playing at the same time. 49 | 50 | One of the players will click the “Spin Wheel” button, which will generate 51 | a random number and all bets will be dealt with accordingly. 52 | 53 | When a player wins a bet, the payout is credited on his personal account. 54 | The player can, at any moment, click the “Cash out” button and receive 55 | their winnings. Be advised that, at a particular moment, the roulette 56 | could have insufficient funds to pay winnings for all players. Continue 57 | reading to understand why this could happen. 58 | 59 | ### Randomness 60 | 61 | True randomness is not possible in the Ethereum Virtual Machine (EVM), due to 62 | the way the virtual machine operates. When a smart contract is called, every 63 | node in the network will have to run the code, to validate it, and at the end 64 | the state must be the same for every node (consensus). If, hypothetically, 65 | there would be a true random function available, then, when every node call it, 66 | it would spill a different value, making it impossible to achieve consensus. 67 | 68 | So, we have to use the current state of the blockchain to find a fair random 69 | number, and the formula I choose was to calculate the hash of several factors, 70 | and use the reminder of the division of that hash by 37. The factors used in 71 | the hash are: 72 | 73 | - The blockhash of the previous block 74 | - The current block timestamp 75 | - The current block difficulty 76 | - The last accepted bet 77 | 78 | The problem with this approach is that everyone who can see the state of the 79 | blockchain, can calculate ("guess") the future random number, and bet on that 80 | number. 81 | 82 | ### Security 83 | 84 | So, the first security measure implemented was to make the random number 85 | dependable on the last bet. So, if for example, an attacker calculates that the 86 | random number will be13, by betting on 13 he will change the outcome of the 87 | random number, making this type of attack ineffective. 88 | 89 | But an attacker could make an inverted attack, by betting on a number and then 90 | waiting for the state of the blockchain to be one that generates that specific 91 | number. For this attack to work, the attacker must fulfill 2 conditions: 92 | 93 | 1. be able to control when is the spin of the wheel; 94 | 2. be able to accurately guess the next random number. 95 | 96 | Condition one is difficult, because anyone can spin the wheel, but there will 97 | be times where the attacker will be the only one on the roulette, making it 98 | possible. With an average time per block of 14.4 seconds, and for a bet with a 99 | payout of 36, on average the attacker will have to be alone in the roulette for 100 | 37 * 14.4 / 60 ~= 9 minutes. 101 | 102 | Condition two, is harder. Two of the factors used in calculating the 103 | “random” number refer to the current block, that will only be known 104 | **with** the spinning of the wheel, thus making it impossible to guess the 105 | “random” number. The problem is that, even unknown, the values of the 106 | current block timestamp and difficulty are strongly predictable, and even 107 | worse, can be manipulated by a miner. 108 | 109 | In a nutshell, for a regular player will be very hard to guess the random 110 | number, but the system is vulnerable to attacks by miners. So additional 111 | security measures were put in place. 112 | 113 | **Balance cap** 114 | 115 | Every time the wheel is spinned, and all payouts credited in the players 116 | accounts, the system verifies if the roulette balance is higher than 2 ether. 117 | If so, it send the excess to the contract owner (me). This way, the maximum 118 | amount of ether an attacker could steal is of 3 ether (a full roulette with 2 119 | ether, plus 100 bets of 0.01 ether). 120 | 121 | Bear in mind that the personal accounts of players (their respective winnings) 122 | are not taking in consideration when calculating the balance. In other words, 123 | a player could have more than 2 ether in their winnings accounts, but be unable 124 | to cash out since the roulette hasn’t sufficient funds to pay. 125 | 126 | This is intended to prevent a Denial of Service attack, where a player could 127 | have all the roulette money in his winnings account, preventing other players 128 | to play. It's players responsability to be aware of this, and cash out 129 | frequently. 130 | 131 | ### Clone repo 132 | 133 | You can clone the repo and running it on your own private network. 134 | 135 | **What you’ll need** 136 | 137 | - Ganache: you can download a self-contained prebuilt Ganache binary for your platform of choice using the "Download" button on the [Ganache website](http://truffleframework.com/ganache/). After, run it and keep it running, this will deploy a private Ethereum network on your machine, port 7545. 138 | - npm: follow [this instructions](https://www.npmjs.com/get-npm) to install npm 139 | - [Metamask](https://metamask.io) Chrome extension installed and running 140 | 141 | **How to lunch the ethereum roulette on your machine** 142 | 143 | Run Ganache and keep it running. 144 | 145 | Clone the repo from github: 146 | 147 | git clone https://github.com/bordalix/ethereum-roulette.git 148 | cd ethereum-roulette 149 | npm install 150 | 151 | Deploy the contract to your private blockchain (provided by Ganache): 152 | 153 | truffle deploy --reset 154 | 155 | Run the webserver 156 | 157 | npm run dev 158 | 159 | You now have the ethereum roulette on [http://localhost:3000](http://localhost:3000). 160 | 161 | Have fun. 162 | -------------------------------------------------------------------------------- /src/js/app.js: -------------------------------------------------------------------------------- 1 | /* variables */ 2 | const BET_AMOUNT = 10000000000000000; /* 0,01 ether, around $6 */ 3 | const GAS = 700000; 4 | const GAS_PRICE = 2000000000; 5 | const bets = []; 6 | let contract; 7 | let lastPosition = 0; 8 | let wheelSpinCounter = 0; 9 | let firstBetAfterSpin = true; 10 | let web3Provider = null; 11 | let lastBlockEvent = 0; 12 | 13 | const betTypes = [ 14 | 'color', 'column', 'dozen', 15 | 'eighteen', 'modulus', 'number' 16 | ]; 17 | 18 | function showWarning(msg) { 19 | var p = document.getElementById('warning'); 20 | p.innerHTML = msg; 21 | p.style.display = 'block'; 22 | } 23 | 24 | function init() { 25 | return initWeb3(); 26 | } 27 | 28 | function initWeb3() { 29 | // Is there an injected web3 instance? 30 | if (typeof web3 !== 'undefined') { 31 | web3Provider = web3.currentProvider; 32 | } else { 33 | // If no injected web3 instance is detected, fall back to Ganache 34 | web3Provider = new Web3.providers.HttpProvider('http://localhost:7545'); 35 | } 36 | web3 = new Web3(web3Provider); 37 | if (web3.isConnected()) return initContract(); 38 | showWarning('You need Metamask installed and connected to the ropsten network'); 39 | } 40 | 41 | function initContract() { 42 | // get abi and deployed address 43 | $.getJSON('Roulette.json', (data) => { 44 | web3.version.getNetwork((err, netId) => { 45 | let address; 46 | switch (netId) { 47 | case "1": // main network 48 | showWarning("You're on the Ethereum main network. Please switch to Ropsten."); 49 | break 50 | case "2": // morden 51 | showWarning("You're on the Morden test network. Please switch to Ropsten."); 52 | break 53 | case "3": // ropsten 54 | address = '0xba3bb2eb6ec54fc62bef844f8bad8044724d801b'; 55 | break 56 | case "4": // rinkeby 57 | showWarning("You're on the Rinkeby test network. Please switch to Ropsten."); 58 | break 59 | case "42": // kovan 60 | showWarning("You're on the Kovan test network. Please switch to Ropsten."); 61 | break 62 | default: // unknown network, should be ganache 63 | console.log('This is an unknown network.'); 64 | address = data.networks[netId].address; 65 | } 66 | const abi = data.abi; 67 | contract = web3.eth.contract(abi).at(address); 68 | updateUI(); 69 | return initEventListeners(); 70 | }) 71 | }); 72 | } 73 | 74 | function initEventListeners() { 75 | /* listening for events from the smart contract */ 76 | const event = contract.RandomNumber({}, (err, res) => { 77 | if (res.blockNumber > lastBlockEvent) { /* prevent duplicated events */ 78 | /* 'random' number generated by the smart contract */ 79 | const oneRandomNumber = res.args.number.toNumber(); 80 | /* increment spin counter */ 81 | wheelSpinCounter += 1; 82 | /* get wheel element */ 83 | var wheel = document.getElementById("wheel"); 84 | /* reset wheel */ 85 | wheel.style.transform = "rotate(" + lastPosition + "deg)"; 86 | /* numbers in the wheel, ordered clockwise */ 87 | var numbers = [ 88 | 0, 32, 15, 19, 4, 21, 2, 25, 17, 34, 6, 27, 89 | 13, 36, 11, 30, 8, 23, 10, 5, 24, 16, 33, 1, 90 | 20, 14, 31, 9, 22, 18, 29, 7, 28, 12, 35, 3, 26 91 | ]; 92 | /* calculate how much do we need to rotate to have the random number chosen */ 93 | var numberDegree = numbers.indexOf(oneRandomNumber) * 360 / numbers.length; 94 | /* add some rounds before to look like it's spinning */ 95 | var numRoundsBefore = 3 * wheelSpinCounter; 96 | /* calculate total degrees we need to rotate */ 97 | var totalDegrees = (numRoundsBefore * 360) + numberDegree; 98 | /* rotate the wheel */ 99 | document.getElementById("wheel").style.transform = "rotate(-" + totalDegrees + "deg)"; 100 | /* save position to be able to reset the wheel next time */ 101 | lastPosition = numberDegree; 102 | /* show status on bets after wheel stops */ 103 | setTimeout(function() { 104 | showBetsStatus(oneRandomNumber); 105 | }, 2000); 106 | lastBlockEvent = res.blockNumber; 107 | } 108 | }); 109 | } 110 | 111 | function showError(msg, err) { 112 | console.log(err); 113 | const p = document.getElementById('errorPanel'); 114 | p.innerText = msg; 115 | setTimeout(function() { 116 | p.innerHTML = ' '; 117 | }, 4000); 118 | } 119 | 120 | function hideBets() { 121 | var div = document.getElementById('betsList'); 122 | while (div.firstChild) { 123 | div.removeChild(div.firstChild); 124 | } 125 | } 126 | 127 | function cleanBets() { 128 | bets.length = 0; 129 | hideBets(); 130 | } 131 | 132 | function placeBet() { 133 | let area = this.id; 134 | let bet = {}; 135 | if (/^c\_\d/.test(area)) bet = {type: 0, value: parseInt(area.substr(2))}; 136 | if (/^p\_\d/.test(area)) bet = {type: 1, value: parseInt(area.substr(2))}; 137 | if (/^d\_\d/.test(area)) bet = {type: 2, value: parseInt(area.substr(2))}; 138 | if (/^e\_\d/.test(area)) bet = {type: 3, value: parseInt(area.substr(2))}; 139 | if (/^m\_\d/.test(area)) bet = {type: 4, value: parseInt(area.substr(2))}; 140 | if (/^n\d\d/.test(area)) bet = {type: 5, value: parseInt(area.substr(1))}; 141 | if (bet.hasOwnProperty('type') && bet.hasOwnProperty('value')) { 142 | const options = {value:BET_AMOUNT, gas:GAS, gasPrice:GAS_PRICE}; 143 | contract.bet(bet.value, bet.type, options, (err, res) => { 144 | if (err) return void showError('not enough money in the bank', err); 145 | pushBet(bet); 146 | }); 147 | } 148 | } 149 | 150 | function pushBet(hash) { 151 | if (firstBetAfterSpin) cleanBets(); 152 | firstBetAfterSpin = false; 153 | bets.push(hash); 154 | printBet(hash); 155 | } 156 | 157 | function printBet(hash) { 158 | const labelForNum = { 159 | color: { 160 | 0: 'black', 161 | 1: 'red' 162 | }, 163 | column: { 164 | 0: 'left', 165 | 1: 'middle', 166 | 2: 'right' 167 | }, 168 | dozen: { 169 | 0: '1st', 170 | 1: '2nd', 171 | 2: '3rd' 172 | }, 173 | eighteen: { 174 | 0: '1-18', 175 | 1: '19-36' 176 | }, 177 | modulus: { 178 | 0: 'even', 179 | 1: 'odd' 180 | } 181 | } 182 | const type = betTypes[hash.type]; 183 | const value = type === 'number' ? hash.value : labelForNum[type][hash.value]; 184 | const div = document.getElementById('betsList'); 185 | const p = document.createElement('p'); 186 | p.innerText = type + ' ' + value + ' '; 187 | if (hash.hasOwnProperty('status')) { 188 | p.innerText += (hash.status ? 'WIN' : 'LOST'); 189 | } 190 | div.appendChild(p); 191 | } 192 | 193 | function showBetsStatus(num) { 194 | hideBets(); 195 | bets.map(function(bet) { 196 | if (num === 0) { 197 | bet.status = (bet.type === 5 && bet.value === 0); // bet on 0 198 | } else { 199 | if (bet.type === 5) { // bet on number 200 | bet.status = (bet.value === num); 201 | } 202 | if (bet.type === 4) { // bet on modulus 203 | if (bet.value === 0) bet.status = (num % 2 === 0); 204 | if (bet.value === 1) bet.status = (num % 2 === 1); 205 | } 206 | if (bet.type === 3) { // bet on eighteen 207 | if (bet.value === 0) bet.status = (num <= 18); 208 | if (bet.value === 1) bet.status = (num >= 19); 209 | } 210 | if (bet.type === 2) { // bet on dozen 211 | if (bet.value === 0) bet.status = (num <= 12); 212 | if (bet.value === 1) bet.status = (num >= 13 && num <= 24); 213 | if (bet.value === 2) bet.status = (num >= 25); 214 | } 215 | if (bet.type === 1) { // bet on column 216 | if (bet.value === 0) bet.status = (num % 3 === 1); 217 | if (bet.value === 1) bet.status = (num % 3 === 2); 218 | if (bet.value === 2) bet.status = (num % 3 === 0); 219 | } 220 | if (bet.type === 0) { // bet on color 221 | if (num <= 10 || (num >= 20 && num <= 28)) { 222 | if (bet.value === 0) bet.status = (num % 2 === 0) 223 | if (bet.value === 1) bet.status = (num % 2 === 1) 224 | } else { 225 | if (bet.value === 0) bet.status = (num % 2 === 1) 226 | if (bet.value === 1) bet.status = (num % 2 === 0) 227 | } 228 | } 229 | } 230 | printBet(bet); 231 | }) 232 | } 233 | 234 | function spinWheel() { 235 | contract.spinWheel({value:0, gas:GAS, gasPrice:GAS_PRICE}, (err, res) => { 236 | if (err) return void showError('to soon to play?', err); 237 | firstBetAfterSpin = true; 238 | }); 239 | } 240 | 241 | function cashOut() { 242 | contract.cashOut({value:0, gas:GAS, gasPrice:GAS_PRICE}, (err, res) => { 243 | if (err) return void showError('something went wrong with cashOut', err); 244 | }); 245 | } 246 | 247 | function toEther(bigNum) { 248 | return (bigNum / 1000000000000000000).toFixed(2) 249 | } 250 | 251 | function updateHTML(value, elId) { 252 | const span = document.getElementById(elId); 253 | span.innerText = value; 254 | } 255 | 256 | /* call smart contract to get status and update UI */ 257 | function getStatus() { 258 | contract.getStatus((err, res) => { 259 | if (err) return void showError('something went wrong with getStatus', err); 260 | let aux = res.map(x => x.toNumber()); 261 | updateHTML(aux[0],'betsCount'); // bets count 262 | aux[1] = toEther(aux[1]); // bets value 263 | updateHTML(aux[1],'betsValue'); 264 | const now = Math.round(new Date() / 1000); // time until next spin 265 | aux[2] = aux[2] < now ? 0 : (aux[2] - now); 266 | updateHTML(aux[2],'timeUntilNextSpin'); 267 | aux[3] = toEther(aux[3]); // roulette balance 268 | updateHTML(aux[3],'balance'); 269 | aux[4] = toEther(aux[4]); // winnings 270 | updateHTML(aux[4],'winnings'); 271 | web3.eth.getBalance(web3.eth.coinbase, (err, balance) => { // player balance 272 | balance = toEther(balance); 273 | updateHTML(balance, 'yourBalance'); 274 | }); 275 | }); 276 | } 277 | 278 | /* every second query smart contract for status */ 279 | function updateUI() { 280 | setInterval(function () { 281 | getStatus(); 282 | }, 1000); 283 | } 284 | 285 | document.addEventListener('DOMContentLoaded', function() { 286 | /* adds click event to roulette table */ 287 | var areas = document.getElementsByTagName('area'); 288 | for (i=0; i3)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){if(a(b.target).is(this))return b.handleObj.handler.apply(this,arguments)}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.7",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a("#"===f?[]:f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.7",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c).prop(c,!0)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c).prop(c,!1))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target).closest(".btn");b.call(d,"toggle"),a(c.target).is('input[type="radio"], input[type="checkbox"]')||(c.preventDefault(),d.is("input,button")?d.trigger("focus"):d.find("input:visible,button:visible").first().trigger("focus"))}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.7",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));if(!(a>this.$items.length-1||a<0))return this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){if(!this.sliding)return this.slide("next")},c.prototype.prev=function(){if(!this.sliding)return this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.7",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger(a.Event("hidden.bs.dropdown",f)))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.7",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger(a.Event("shown.bs.dropdown",h))}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&jdocument.documentElement.clientHeight;this.$element.css({paddingLeft:!this.bodyIsOverflowing&&a?this.scrollbarWidth:"",paddingRight:this.bodyIsOverflowing&&!a?this.scrollbarWidth:""})},c.prototype.resetAdjustments=function(){this.$element.css({paddingLeft:"",paddingRight:""})},c.prototype.checkScrollbar=function(){var a=window.innerWidth;if(!a){var b=document.documentElement.getBoundingClientRect();a=b.right-Math.abs(b.left)}this.bodyIsOverflowing=document.body.clientWidth
',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){if(this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(a.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusin"==b.type?"focus":"hover"]=!0),c.tip().hasClass("in")||"in"==c.hoverState?void(c.hoverState="in"):(clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show())},c.prototype.isInStateTrue=function(){for(var a in this.inState)if(this.inState[a])return!0;return!1},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);if(c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusout"==b.type?"focus":"hover"]=!1),!c.isInStateTrue())return clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide()},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var d=a.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c):c.leave(c)):c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){var a=this;clearTimeout(this.timeout),this.hide(function(){a.$element.off("."+a.type).removeData("bs."+a.type),a.$tip&&a.$tip.detach(),a.$tip=null,a.$arrow=null,a.$viewport=null,a.$element=null})};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;!e&&/destroy|hide/.test(b)||(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.3.7",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:''}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){this.$body=a(document.body),this.$scrollElement=a(a(c).is(document.body)?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.scrollHeight=0,this.$scrollElement.on("scroll.bs.scrollspy",a.proxy(this.process,this)),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.3.7",b.DEFAULTS={offset:10},b.prototype.getScrollHeight=function(){return this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)},b.prototype.refresh=function(){var b=this,c="offset",d=0;this.offsets=[],this.targets=[],this.scrollHeight=this.getScrollHeight(),a.isWindow(this.$scrollElement[0])||(c="position",d=this.$scrollElement.scrollTop()),this.$body.find(this.selector).map(function(){var b=a(this),e=b.data("target")||b.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[c]().top+d,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){b.offsets.push(this[0]),b.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.getScrollHeight(),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(this.scrollHeight!=c&&this.refresh(),b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b=e[a]&&(void 0===e[a+1]||b .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.7",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return e=a-d&&"bottom"},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); -------------------------------------------------------------------------------- /src/fonts/glyphicons-halflings-regular.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | --------------------------------------------------------------------------------