Created
February 17, 2021 21:34
-
-
Save godoppl/3490aac9b30a963595b1dddcca6e460b 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.7.4+commit.3f05b770.js&optimize=false&runs=200&gist=
This file contains 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
// this line is added to create a gist. Empty file is not allowed. |
This file contains 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.7.0 <0.8.0; | |
contract BounceBack { | |
address payable internal owner; | |
constructor() { | |
owner = msg.sender; | |
} | |
modifier onlyOwner() { | |
require(msg.sender == owner, "Owner called this"); | |
_; | |
} | |
function payout() external onlyOwner { | |
// Withdraw balance | |
owner.transfer(address(this).balance); | |
} | |
receive() external payable { | |
// Deposit money | |
} | |
} |
This file contains 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.7.0 <0.8.0; | |
contract YouGet5 { | |
address payable internal owner; | |
modifier onlyOwner() { | |
require(msg.sender == owner, "Owner called this"); | |
_; | |
} | |
constructor() { | |
owner = msg.sender; | |
} | |
function payout() external onlyOwner { | |
owner.transfer(address(this).balance); | |
} | |
function destroy() external onlyOwner { | |
selfdestruct(owner); | |
} | |
function getSenderBalance() internal view returns (uint256) { | |
return msg.sender.balance; | |
} | |
function getContractBalance() internal view returns (uint256) { | |
return address(this).balance; | |
} | |
function calculateDeposit() internal view returns (uint256) { | |
return (5000000000000000000 - getSenderBalance()); | |
} | |
receive() external payable { | |
uint256 balance = getSenderBalance(); | |
if (balance < 5000000000000000000) { | |
uint256 deposit = calculateDeposit(); | |
if (deposit < getContractBalance()) { | |
msg.sender.transfer(deposit); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment