forked from francbianc/blockchain_GoodGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwin.sol
More file actions
41 lines (31 loc) · 1.68 KB
/
win.sol
File metadata and controls
41 lines (31 loc) · 1.68 KB
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
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol";
import "https://github.com/francbianc/blockchain/blob/main/bet.sol";
contract Win is Betting {
// NB: inheritance therefore same balance
// Set the commission fee of GoodGame (3%)
uint commission_cost = 3;
// Only GG can transfer ETH from loser to winner and charge the commission fee
function payOutChallenger(uint _idBet, bool _winnC, address payable _C, address payable _A) public onlyOwner returns(bool success,
string memory name_winner) {
require(all_bets[_idBet].challenger == _C && all_bets[_idBet].accepter == _A);
require(all_bets[_idBet].challenger_pay == true && all_bets[_idBet].accepter_pay == true);
uint256 prize = all_bets[_idBet].price_challenger.add(all_bets[_idBet].price_accepter);
uint256 commission = prize.mul(commission_cost)/100;
uint256 netPrize = prize.sub(commission);
msg.sender.transfer(commission);
if (_winnC == true) {
_C.transfer(netPrize);
return (true, 'Challenger');} else {
_A.transfer(netPrize);
return (true, 'Accepter');}
}
// Double check to be sure the Inheritance has worked correctly
function getBalanceBet2() public view onlyOwner returns (uint) {
return address(this).balance;}
// GG may access its own balance
function getGoodGameBalance() public view onlyOwner returns (uint256) {
return msg.sender.balance;
}
}