forked from magonicolas/Ethereum-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarriage.sol
More file actions
68 lines (52 loc) · 1.67 KB
/
Marriage.sol
File metadata and controls
68 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
pragma solidity ^0.4.23;
/**
* This contract is a love contract, we will offer marriage
and accept it or rejected on the ethereum blockchain.
*@autor: magonicolas
*/
contract MarriageContract {
struct Marriage {
uint id;
string agreements;
uint256 proposalDate;
uint256 answeredDate;
uint256 endedDate;
address proposer;
address proposed;
bool accepted;
bool ended;
}
event MarriageStatus(string _msg, address _proposer, address _proposed, bool _accepted, uint256 _date, bool _ended);
mapping (uint => Marriage) public marriages;
function MarriageContract () {
}
function proposeMarriage(uint _id, string _agreements, address _proposed) {
require (marriages[_id].proposalDate == 0);
Marriage memory _marriage = Marriage({
id: _id,
agreements: _agreements,
proposalDate: block.timestamp,
answeredDate: 0,
endedDate: 0,
proposer: msg.sender,
proposed: _proposed,
accepted: false,
ended: false
});
marriages[_id] = _marriage;
}
function answerMarriage(uint _id, bool _accept) {
Marriage storage _marriage = marriages[_id];
require (_marriage.proposed == msg.sender);
_marriage.accepted = _accept;
_marriage.answeredDate = block.timestamp;
MarriageStatus('User has answered to Marriage proposal', _marriage.proposer, msg.sender, _accept, block.timestamp, false);
}
function endMarriage(uint _id) {
Marriage storage _marriage = marriages[_id];
require (_marriage.proposed == msg.sender || _marriage.proposer == msg.sender);
_marriage.ended = true;
_marriage.endedDate = block.timestamp;
MarriageStatus('Marriage Ended', _marriage.proposer, _marriage.proposed, _marriage.accepted, block.timestamp, true);
}
}