Cheaper Gas v2
This commit is contained in:
+24
-5
@@ -41,12 +41,12 @@ contract FundMe {
|
||||
/***** 6.1 Type Declarations *****/
|
||||
using PriceConverter for uint256;
|
||||
uint256 public constant MINIMUM_USD = 50 * 1e18;
|
||||
address[] public s_funders;
|
||||
address public immutable i_owner; // immutable only can declare 1 time at contructor
|
||||
AggregatorV3Interface public s_priceFeed;
|
||||
address[] private s_funders;
|
||||
address private immutable i_owner; // immutable only can declare 1 time at contructor
|
||||
AggregatorV3Interface private s_priceFeed;
|
||||
|
||||
/***** 6.2 State Variable *****/
|
||||
mapping(address => uint256) public s_addressToAmountFunded;
|
||||
mapping(address => uint256) private s_addressToAmountFunded;
|
||||
|
||||
/***** 6.3 Modifier *****/
|
||||
modifier onlyOwner() {
|
||||
@@ -94,7 +94,7 @@ contract FundMe {
|
||||
require(
|
||||
msg.value.getConversionRate(s_priceFeed) >= MINIMUM_USD,
|
||||
"Didn't send enough"
|
||||
);
|
||||
); // Use error code is gas cheaper
|
||||
s_funders.push(msg.sender);
|
||||
s_addressToAmountFunded[msg.sender] = msg.value;
|
||||
}
|
||||
@@ -147,4 +147,23 @@ contract FundMe {
|
||||
(bool callSuccess, ) = i_owner.call{value: address(this).balance}("");
|
||||
require(callSuccess, "Call failed");
|
||||
}
|
||||
|
||||
// private variable is gas cheaper
|
||||
function getOwner() public view returns (address) {
|
||||
return i_owner;
|
||||
}
|
||||
|
||||
function getFunders(uint256 index) public view returns (address) {
|
||||
return s_funders[index];
|
||||
}
|
||||
|
||||
function getAddressToAmountFunded(
|
||||
address funder
|
||||
) public view returns (uint256) {
|
||||
return s_addressToAmountFunded[funder];
|
||||
}
|
||||
|
||||
function getPriceFeed() public view returns (AggregatorV3Interface) {
|
||||
return s_priceFeed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user