-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path01.withdrawalPattern.sol
More file actions
37 lines (24 loc) · 889 Bytes
/
01.withdrawalPattern.sol
File metadata and controls
37 lines (24 loc) · 889 Bytes
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
contract DividendContract is Ownable {
address[] public investors;
function registerInvestor(address _investor) public onlyOwner {
require(_investor != address(0));
investors.push(_investor);
}
function distributeDividend() public onlyOwner {
for (uint256 i = 0; i < investors.length; i++) {
uint256 amount = calculateDividend(investors[i]);
investors[i].transfer(amount); //Push ether to user
}
}
function calculateDividend(address _investor) internal returns (uint256) {
//Dividend calculation here
}
function claimDividend() public {
uint256 amount = balances[msg.sender];
require(amount > 0);
//Ensure to update balance before transfer
//to avoid reentrancy attack
balances[msg.sender] = 0;
msg.sender.transfer(amount);
}
}