-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFundMe.sol
57 lines (39 loc) · 1.26 KB
/
FundMe.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
//SPDX-License-Identifier:MIT
pragma solidity ^0.8.8;
// import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./PriceConverter.sol";
contract FundMe{
using PriceConverter for uint256;
uint256 public minimumUsd = 50;
address[] public funders;
mapping (address => uint256) public addressToAmountList;
address public owner;
error NotOwner();
constructor(){
owner = msg.sender;
}
function fund() public payable{
require(msg.value.getConversionRate() > minimumUsd, "Didn't send enoungh!");
funders.push(msg.sender);
addressToAmountList[msg.sender] = msg.value;
}
function withdraw() public {
for(uint256 funderIndex = 0; funderIndex < funders.length; funderIndex++){
address funder = funders[funderIndex];
addressToAmountList[funder] = 0;
}
funders = new address[](0);
(bool callSuccess, ) = payable(msg.sender).call{value:address(this).balance}("");
require(callSuccess, "call failed!");
}
modifier onlyOwner{
if (msg.sender != owner) {revert NotOwner();}
_;
}
receive() external payable {
fund();
}
fallback() external payable {
fund();
}
}