-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path4_FundProjectForOwner.sol
43 lines (31 loc) · 1.03 KB
/
4_FundProjectForOwner.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
// SPDX-License-Identifier: MIT
/*
This contract recevives funding from different accounts. Only the contract owner can withdraw these funds.
*/
pragma solidity ^0.8.0;
contract FundProjectForOwner {
address public owner;
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "You are not the owner of this contract!");
_;
}
function fund() public payable {
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
}
function withdraw() public payable onlyOwner {
// Resets map
for (uint256 funderIndex = 0;funderIndex < funders.length;funderIndex++) {
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
// Resets funders array
funders = new address[](0);
payable(msg.sender).transfer(address(this).balance);
}
}