forked from shentufoundation/testnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minibank.sol
53 lines (40 loc) · 1.52 KB
/
minibank.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
44
45
46
47
48
49
50
51
52
53
pragma solidity ^0.5.12;
contract MiniBank {
// the contract owner
address public owner;
// the bank accounts mapper
mapping (address => uint) private accounts;
// event for deposit log
event LogDeposit(address indexed accountAddress, uint amount);
// event for withdraw log
event LogWithdraw(address indexed withdrawAddress, uint amount);
constructor() public {
// 1. set the owner to your current account
// add the code here
}
/// Deposit amount into MiniBank
/// @return User balance after the deposit is made
function deposit() public payable returns (uint) {
require((accounts[msg.sender] + msg.value) >= accounts[msg.sender]);
// 2. add msg.value to the user account
// add the code here
emit LogDeposit(msg.sender, msg.value);
return accounts[msg.sender];
}
/// Withdraw amount from MiniBank
/// @param withdrawAmount amount for withdrawing
/// @return The ramaining balance
function withdraw(uint withdrawAmount) public returns (uint) {
require(withdrawAmount <= accounts[msg.sender]);
// 3. decrease user balance
// add the code here
msg.sender.transfer(withdrawAmount);
// 4. emit LogWithdraw event
// add the code here
return accounts[msg.sender];
}
/// @return The user balance
function balance() view public returns (uint) {
return accounts[msg.sender];
}
}