// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; /** * @title Marriage Contract * @dev Accepts ethereum and simulates a humorous marriage dynamic with randomness. */ contract Marriage { using SafeMath for uint256; bool public isWoman; mapping(address => bool) public notHappy; address public divorceAddress; uint256 public argumentThreshold; uint256 public hystericalArgumentCount; event Divorce(address indexed partner1, address indexed partner2, uint256 value); event HystericalArgument(address indexed partner1, address indexed partner2, string reason); /** * @dev Constructor that sets the gender of the contract initiator and initializes randomness. * @param _isWoman Indicates if the contract initiator is a woman. */ constructor(bool _isWoman) { isWoman = _isWoman; argumentThreshold = uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) % 10 + 1; } /** * @dev Modifier to check if the contract is valid. * @param _isContract The address to check. */ modifier isSmartContract(address _isContract) { uint32 size; assembly { size := extcodesize(_isContract) } require(size > 0, "This is not a smart contract"); _; } /** * @dev Sends ethereum to the contract and triggers a not happy condition if it is not reversed. */ function sendEther() external payable isSmartContract(msg.sender) { require(msg.value > 0, "Send some ethereum with your love!"); notHappy[msg.sender] = true; // Simulates loss of contract value over time uint256 divorceAmount = msg.value.div(10); divorceAddress = address(uint160(address(this))); // Choose your desired address here if (notHappy[msg.sender]) { emit Divorce(divorceAddress, msg.sender, divorceAmount); payable(msg.sender).transfer(divorceAmount); } else { notHappy[msg.sender] = false; } // Trigger hysterical argument if (hystericalArgumentCount < argumentThreshold) { hystericalArgumentCount++; } else { triggerHystericalArgument(); } } /** * @dev Allows a partner to express happiness, reversing the not happy condition. */ function expressHappiness() external { notHappy[msg.sender] = false; } /** * @dev Simulates a cheating action, causing the cheater's partner to be extremely unhappy. */ function cheat() external { require(notHappy[msg.sender], "Only unhappy partners can cheat!"); // Increase argument threshold to make hysterical argument less likely argumentThreshold = argumentThreshold.add(5); emit HystericalArgument(msg.sender, divorceAddress, "Cheating!"); notHappy[divorceAddress] = true; } /** * @dev Simulates moving out of the shared home, making the partner sad. */ function moveOut() external { require(notHappy[msg.sender], "Only unhappy partners can move out!"); // Increase argument threshold to make hysterical argument less likely argumentThreshold = argumentThreshold.add(2);
0.4.18