OP_Homework_1/OP hazi.txt

55 lines
1.8 KiB
Plaintext
Raw Normal View History

2022-02-13 16:00:53 +00:00
// 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;
}
}