HW commit

master
OP 2022-02-13 17:00:53 +01:00
parent 932d87c445
commit 8411a54328
1 changed files with 55 additions and 0 deletions

55
OP hazi.txt 100644
View File

@ -0,0 +1,55 @@
// 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;
}
}