pragma solidity ^0.4.25; contract BettingFactory { address public manager; address[] public bets; //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 function createbetting() public returns (address) { Betting bet = new Betting(); bets.push(bet); return bet; } } contract Betting { //Variables address public manager; address public bettorA; address public bettorB; address public winner; uint private balanceA; uint private balanceB; //modifier require only the bettor have the right to call this function modifier onlyBettor() { require(msg.sender == bettorA || msg.sender == bettorB); _; } //modifier require only the manager have the right to call this function modifier onlyManager() { require(msg.sender == manager); _; } //Bettor join to A side and sending money to winning pool function playerA() public payable { bettorA = msg.sender; uint balanceA = msg.value; } //Bettor join to B side and sending money to winning pool function playerB() public payable { bettorB = msg.sender; uint balanceB = msg.value; } function pickWinner(string _winner) public onlyManager { if (keccak256(_winner) == keccak256("A")) { winner = bettorA; } else winner = bettorB; } //Function return the address of winner - This function only called only by manager function payWinner() onlyManager returns (address) { winner.transfer(address(this).balance); return winner; } function winningPool() public returns(uint) { return this.balance; } }
0.4.18