-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.sol
59 lines (45 loc) · 1.51 KB
/
protocol.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Transaction {
address payable public sender;
address payable public receiver;
bool public senderConfirmed;
bool public receiverConfirmed;
constructor(address payable _receiver) payable {
sender = payable(msg.sender);
receiver = _receiver;
}
function confirmSender() public onlySender {
senderConfirmed = true;
if (receiverConfirmed == true) startTransaction();
}
function refuseSender() public onlySender {
senderConfirmed = false;
goToFirstSupportLevel();
}
function confirmReceiver() public onlyReciver {
receiverConfirmed = true;
if (senderConfirmed == true) startTransaction();
}
function refuseReceiver() public payable onlyReciver {
sender.transfer(getBalance());
}
function getBalance() public view returns(uint256) {
return address(this).balance;
}
function startTransaction() private {
require(senderConfirmed == true && receiverConfirmed == true, "Both sender and receiver must confirm the transaction");
receiver.transfer(getBalance());
}
modifier onlySender() {
require(msg.sender == sender, "Only sender can confirm this");
_;
}
modifier onlyReciver() {
require(msg.sender == receiver, "Only reciver can confirm this");
_;
}
function goToFirstSupportLevel()private {
// here will be the go to AI method
}
}