pragma solidity ^0.4.25; contract SportBetting { //Variables address public manager; address [] public bettors; address public winner; //constructor of the contract - the msg.sender is the address of the contract creator - in this function the creater will be the manager constructor() public { manager = msg.sender; } //modifier require only the mmanager have the right to call this function modifier onlyManager() { require(msg.sender == manager); _; } //function requires the bettors sending money to the winning pool - in this function the msg.sender is the bettor address function enter() public payable { require(msg.value == 1 ether);fa bettors.push(msg.sender); } //Function to get the winner name function random() private view returns (uint) { return uint(keccak256(abi.encodePacked(block.difficulty, now, bettors))); } //Function return the address of winner - This function only called only by manager function pickWinner() onlyManager returns (address) { uint index = random() % bettors.length; winner = bettors[index]; winner.transfer(address(this).balance); bettors = new address[](0); return winner; } }
0.4.25