-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEtherBank.sol
executable file
·71 lines (58 loc) · 2.07 KB
/
EtherBank.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
*Submitted for verification at Etherscan.io on 2021-05-21
*/
/*
Developed by Salman Haider
Date: 21 May 2021
*/
pragma solidity 0.4.26;
contract EtherBank {
address public owner;
address public user;
address[] public depositers;
mapping(address => uint) public depositedBalance;
mapping(address => bool) public hasDeposited;
event etherDeposited(address depositer, uint ethAmount);
event etherReturned(address depositer, uint ethAmount);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
/*
1. Anyone can depositEther to the EtherBank
2. DepositEther() function will deposit the Ether from user address
3. DepositEther() will save the balance and address of the depositers
*/
function depositEther() public payable {
user = msg.sender;
uint amount = msg.value;
depositers.push(user);
// Eth is deposited to the contract
depositedBalance[user] += amount;
hasDeposited[user] = true;
emit etherDeposited(user, amount);
}
/*
1. OnlyOwner can call returnEth() in order to return ethers to all the addresses
2. returnEth() should be automated and can only be called from inside the contract
3. If the etherBank Contract is deployed on rinkeby at Block : 0
Then
after 10 blocks are mined ( 0 + 10 ) on the rinkeby testnet
=> An automated scheduler should call the returnEth() function
from inside the deployed EtherBank smartContract
=> To return ethers deposited by the depositers
*/
function returnEth() public {
for (uint i=0; i<depositers.length; i++) {
user = depositers[i];
uint refundedAmount = depositedBalance[user];
user.transfer(refundedAmount);
depositedBalance[user] = 0;
hasDeposited[user] = false;
emit etherReturned(user, refundedAmount);
}
}
}