Skip to content

Instantly share code, notes, and snippets.

@wellyington
Created December 26, 2023 11:42
Show Gist options
  • Save wellyington/547e64fb97952bee9452d8b46d5c76d1 to your computer and use it in GitHub Desktop.
Save wellyington/547e64fb97952bee9452d8b46d5c76d1 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MarriageContract {
address public spouse1;
address public spouse2;
address public witness1;
address public witness2;
uint256 public weddingDate;
bool public isMarried;
event Married(address indexed spouse1, address indexed spouse2, uint256 weddingDate);
modifier onlySpouses() {
require(msg.sender == spouse1 || msg.sender == spouse2, "Only spouses can call this function");
_;
}
modifier onlyWitnesses() {
require(msg.sender == witness1 || msg.sender == witness2, "Only witnesses can call this function");
_;
}
constructor(
address _spouse1,
address _spouse2,
address _witness1,
address _witness2,
uint256 _weddingDate
) {
spouse1 = _spouse1;
spouse2 = _spouse2;
witness1 = _witness1;
witness2 = _witness2;
weddingDate = _weddingDate;
isMarried = true;
emit Married(_spouse1, _spouse2, _weddingDate);
}
function updateWeddingDate(uint256 newWeddingDate) external onlySpouses {
require(newWeddingDate > block.timestamp, "Invalid date");
weddingDate = newWeddingDate;
}
function divorce() external onlySpouses {
// Additional conditions for divorce can be added here
isMarried = false;
}
function updateWitness(address newWitness, uint256 witnessNumber) external onlySpouses {
require(witnessNumber == 1 || witnessNumber == 2, "Invalid witness number");
if (witnessNumber == 1) {
witness1 = newWitness;
} else {
witness2 = newWitness;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment