Proper Format Smart Contract

This commit is contained in:
2024-08-05 22:15:23 +08:00
parent ee8912613c
commit fb89cb6e1e
+52 -32
View File
@@ -4,14 +4,27 @@
Withdraw funds
Set a minimum funding value in USD
*/
/***** 1. Pragma *****/
pragma solidity ^0.8.0;
/***** 2. Import *****/
import "./PriceConverter.sol";
// Save Gas by using constant, immutable for variables
error NotOwner();
/***** 3. Error Codes *****/
error FundMe__NotOwner();
// 816914
/***** 4. Interfaces *****/
/***** 5. Libraries *****/
/***** 6. Contracts *****/
/**
* @title A contract for crowd funding
* @author hoelee
* @notice This contract is to demo a sample funding contract
* @dev This implements price feed as our library
*/
contract FundMe {
/*
Transaction Fields
@@ -24,27 +37,56 @@ contract FundMe {
v, r, s - components of TX signature
*/
/***** 6.1 Type Declarations *****/
using PriceConverter for uint256;
uint256 public constant MINIMUM_USD = 50 * 1e18;
address[] public funders;
address public immutable i_owner; // immutable only can declare 1 time at contructor
AggregatorV3Interface public priceFeed;
/***** 6.2 State Variable *****/
mapping(address => uint256) public addressToAmountFunded;
// immutable only can declare 1 time at contructor
address public immutable i_owner;
/***** 6.3 Modifier *****/
modifier onlyOwner() {
// require(msg.sender == i_owner, "Sender is not owner!");
if (msg.sender != i_owner) {
revert FundMe__NotOwner();
}
_; // doing the rest of the code
}
AggregatorV3Interface public priceFeed;
/***** Function Orders:
* Constructor
* Receive
* Fallback
* External
* Public Internal
* Private
* View / Pure
* *****/
constructor(address priceFeedAddress) {
i_owner = msg.sender;
priceFeed = AggregatorV3Interface(priceFeedAddress);
}
// What happens if someone send this contract ETH without calling the fund function
receive() external payable {
// people send money / empty money into this contract
fund();
}
fallback() external payable {
// cannot identify which function to run
fund();
}
/**
* @notice Minimum sending USD50, Check Conversion In Real Time
* @dev This implements price feed as our library
*/
function fund() public payable {
/*
Want to be able to set a minimum fund amount in USD
1. How do we send ETH to this contract
*/
//require (msg.value >= 1e18, "Didn't send enough"); // 1e18 = 1 * 10 * 18 = 1000000000000000000
require(
msg.value.getConversionRate(priceFeed) >= MINIMUM_USD,
@@ -85,26 +127,4 @@ contract FundMe {
}("");
require(callSuccess, "Call failed");
}
modifier onlyOwner() {
// require(msg.sender == i_owner, "Sender is not owner!");
if (msg.sender != i_owner) {
revert NotOwner();
}
_; // doing the rest of the code
}
// What happens if someone send this contract ETH without calling the fund fucntion
/*
receive - people send money / empty money into this contract
fallback - cannot identify which function to run
*/
receive() external payable {
fund();
}
fallback() external payable {
fund();
}
}