Created
February 8, 2023 19:25
-
-
Save pom421/179a262975d1cd6510d5673c9087f13d to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.8.2 <0.9.0; | |
/** | |
* Compte épargne | |
* | |
* Cf. aussi Ownable de OpenZeppelin | |
*/ | |
contract Epargne { | |
uint256 id; | |
address owner; | |
uint256 contractTime; | |
mapping(uint => uint) history; | |
constructor() { | |
owner = msg.sender; | |
contractTime = block.timestamp; | |
} | |
modifier onlyOwner() { | |
require(msg.sender == owner, unicode"Vous n'êtes pas autorisé."); | |
_; | |
} | |
function deposit() public payable onlyOwner { | |
history[id] = msg.value; | |
id++; | |
} | |
function distribute() external { | |
require( | |
block.timestamp > contractTime + 12 seconds, | |
unicode"Vous ne pouvez pas récupérer votre argent encore." | |
); | |
// Pas nécessaire de mettre payable autour de msg.sender car msg.sender est déjà payable. | |
(bool sent, ) = payable(msg.sender).call{value: address(this).balance}( | |
"" | |
); | |
require(sent, unicode"Transfert non effectué."); | |
// history[id] = -1 * int(address(this).balance); | |
// id++; | |
} | |
receive() external payable { | |
deposit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment