Add some more logic and fix previous issues

This commit is contained in:
David E. Perez Negron R. 2023-12-27 20:04:52 -06:00
parent 10b497dfbd
commit 2e561f6f3c
1 changed files with 40 additions and 22 deletions

View File

@ -9,7 +9,7 @@ contract AA is Ownable {
string[] nfts; string[] nfts;
mapping (address => bool) public airdropped; mapping (address => bool) public airdropped;
address[] public allowed; mapping (address => bool) public eligible;
constructor(string memory name, constructor(string memory name,
string memory symbol, string memory symbol,
@ -28,36 +28,47 @@ contract AA is Ownable {
// Mint Function // Mint Function
// Simplify // Simplify
function _mint(address to, string memory uri) public onlyOwner { function mintNFT(address to, uint index) external onlyOwner {
dco2sc.safeMint(to, uri); require(!airdropped[to], "account already airdropped");
dco2sc.safeMint(to, nfts[index]);
removeNFTAt(index);
airdropped[to] = true;
} }
// @notice Random giveaway function // @Notice Check if eligible
function airdrop() public { function checkIfEligible() public view returns (bool winner) {
//require(eligible(msg.sender)); if (airdropped[msg.sender] == true) {
require(!airdropped[msg.sender], "address already airdropped"); winner = false;
// top 20 is for Auction } else if (eligible[msg.sender] == true) {
uint256 randomURI = getRandomNumber() % nfts.length - 20; winner = true;
dco2sc.safeMint(msg.sender, nfts[randomURI]); } else {
// Require remove the URI so that is not mintable again winner = false;
airdropped[msg.sender] = true;
} }
// @eligible
function eligible(address to) public view returns (bool winner) {
// require( callable until specific date) // require( callable until specific date)
// Activity // Activity
// Longest Holders // Longest Holders
// Top Holders // Top Holders
// or Allowed Wallets() // or Allowed Wallets()
return winner;
} }
// @notice allowed addresses that supports DECA // @notice Random giveaway function
function allow(address supporter) public onlyOwner { function airdrop() external {
//require(eligible(supporter)); require(!airdropped[msg.sender], "account already airdropped");
require(!airdropped[supporter], "address already airdropped"); require(checkIfEligible(), "account not eligible");
allowed.push(supporter); // top 20 is for Auction
uint256 randomURI = getRandomNumber() % nfts.length - 20;
dco2sc.safeMint(msg.sender, nfts[randomURI]);
removeNFTAt(randomURI);
// Require remove the URI so that is not mintable again
airdropped[msg.sender] = true;
}
// @notice adds addresses to the eligible list
// thanks for supporting DECA
function inviteEligible(address supporter) public onlyOwner {
require(!airdropped[msg.sender], "account already airdropped");
eligible[supporter] = true;
} }
@ -67,6 +78,13 @@ contract AA is Ownable {
randomNumber = block.prevrandao; randomNumber = block.prevrandao;
} }
// @notice removes NFT URI from index
function removeNFTAt(uint index) public {
require(index < nfts.length, "nft index out of bounds");
nfts[index] = nfts[nfts.length - 1];
nfts.pop();
}
} }