-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartcontract_challenge_4.sol
43 lines (31 loc) · 1.09 KB
/
smartcontract_challenge_4.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
41
42
43
pragma solidity ^0.6.0;
contract SmartBank {
uint8 public clientCount;
mapping (address => uint) public balances;
address public owner;
event LogDepositMade(address indexed accountAddress, uint amount);
constructor() public payable {
require(msg.value == 10 ether, "10 ether initial funding required");
owner = msg.sender;
clientCount = 0;
}
function enroll() public returns (uint) {
if (clientCount < 3) {
clientCount++;
balances[msg.sender] = 10 ether;
}
return balances[msg.sender];
}
function deposit() public payable returns (uint) {
balances[msg.sender] += msg.value;
emit LogDepositMade(msg.sender, msg.value);
return balances[msg.sender];
}
function withdraw(uint withdrawAmount) public returns (uint remainingBal) {
if (withdrawAmount <= balances[msg.sender]) {
balances[msg.sender] -= withdrawAmount;
msg.sender.transfer(withdrawAmount);
}
return balances[msg.sender];
}
}