Lottery házi 001
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OP_Homework_1/OP hazi.sol

55 lines
1.8 KiB

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.11;
contract winfreemoney {
address public admin;
address payable[] public participants;
event info(
uint256 date
);
constructor(){
admin = msg.sender;
}
function freeBalance() public view returns (uint256){ // összes pénz
return address(this).balance;
}
function getparticipants() public view returns (address payable[] memory){
return participants;
}
function participate() external payable{ //neve és address-e a belépőnek
require(msg.value > .1 ether); //0.1 ether belépési dij
participants.push(payable(msg.sender));
emit info(block.timestamp); // aktualis idöpont
}
function randomnumber() private view returns (uint256){ // random szám generátor
return uint256(keccak256(abi.encodePacked(admin, block.timestamp)));
}
function yourwinner () public {
require(msg.sender == admin); // csak az admin használhatja
uint256 index = randomnumber() % participants.length; // nyertes választása
participants[index].transfer(address(this).balance); // transfer money
participants = new address payable[](0); //reset the contract
}
function ertek () public pure returns (uint256){ // csak megadunk egy random értéket
return 42;
}
}