-
Notifications
You must be signed in to change notification settings - Fork 0
/
idiotbetting.sol
40 lines (31 loc) · 1.43 KB
/
idiotbetting.sol
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
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;
contract IdiotBettingGame {
/*
This exercise assumes you know how block.timestamp works.
- Whoever deposits the most ether into a contract wins all the ether if no-one
else deposits after an hour.
1. `bet` function allows users to deposit ether into the contract.
If the deposit is higher than the previous highest deposit, the endTime is
updated by current time + 1 hour, the highest deposit and winner are updated.
2. `claimPrize` function can only be called by the winner after the betting
period has ended. It transfers the entire balance of the contract to the winner.
*/
uint256 highestDeposit;
address winner;
uint256 endTime;
function bet() public payable {
//code here
require (msg.value > highestDeposit, "deposit must be higher than the previous deposit!!");
highestDeposit = msg.value;
winner = msg.sender;
endTime = block.timestamp + 1 hours;
}
function claimPrize() public {
// your code here
require (msg.sender == winner, "this is the winnner");
require (block.timestamp > endTime, "it is still open");
// Transfer the entire balance of the contract to the winner
payable(winner).transfer(address(this).balance);
}
}