-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalisma3_escrow2.sol
105 lines (87 loc) · 3.92 KB
/
calisma3_escrow2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
/*
Bu çalışma calisma3_escrow2.sol olarak geçmektedir. Bir önceki çalışma olan calisma3_escrow.sol adlı çalışma ile aynı işlevselliği taşımaktadır.
Fakat bazı küçük farklılıklar vardır. Bu çalışmada önceki çalışmadan farklı olarak bazı fonksiyonların farklı kullanımı veya değişik kullanımları söz konusudur.
calisma3_escrow çalışmasında olan bazı satırlar burada yoktur. Bunun nedeni farklı şekilde kullanıldığını veya kullanılmadığında nasıl bir değişiklik olduğunu gösterebilmektir.
*/
contract escrow2 {
mapping (uint => address) transaction_receivers_list;
mapping (uint => address) transaction_owners_list;
mapping (uint => uint) transaction_payment_list;
mapping (uint => bool) transaction_status_list;
uint transaction_count = 0;
address admin;
uint commission_percent = 1;
uint collected_commission = 0;
constructor(uint _commission_percent) {
admin = msg.sender;
commission_percent = _commission_percent;
}
modifier onlyAdmin() {
require(msg.sender == admin);
_;
}
modifier onlyTransactionOwner(uint _transaction_id) {
require(transaction_payment_list[_transaction_id] != 0);
_;
}
modifier CheckIfTransactionNotZero(uint _transaction_id) {
require(transaction_payment_list[_transaction_id] != 0);
_;
}
modifier CheckIfTransactionActive(uint _transaction_id) {
require(!transaction_status_list[_transaction_id]);
_;
}
function createTransaction(address _transaction_receiver) external payable {
require(msg.value >= 1 ether);
require(_transaction_receiver != address(0));
transaction_receivers_list[transaction_count] = _transaction_receiver;
transaction_payment_list[transaction_count] += msg.value;
transaction_owners_list[transaction_count] = msg.sender;
transaction_status_list[transaction_count] = false;
transaction_count += 1;
}
function addEtherToTransaction(uint _transaction_id) external payable
onlyTransactionOwner(_transaction_id)
CheckIfTransactionNotZero(_transaction_id)
CheckIfTransactionActive(_transaction_id)
{
transaction_payment_list[_transaction_id] += msg.value;
}
function cancelTransaction(uint _transaction_id) external
onlyTransactionOwner(_transaction_id)
CheckIfTransactionNotZero(_transaction_id)
CheckIfTransactionActive(_transaction_id)
{
TransferPayment(transaction_owners_list[_transaction_id], transaction_payment_list[_transaction_id]);
transaction_payment_list[_transaction_id] = 0;
transaction_owners_list[_transaction_id] = address(0);
transaction_receivers_list[_transaction_id] = address(0);
}
function confirmTransaction(uint _transaction_id) external
onlyTransactionOwner(_transaction_id)
CheckIfTransactionNotZero(_transaction_id)
CheckIfTransactionActive(_transaction_id)
{
transaction_status_list[_transaction_id] = true;
}
function withDrawtransaction(uint _transaction_id) external payable {
require(transaction_receivers_list[_transaction_id] == msg.sender);
require(transaction_status_list[_transaction_id]);
collected_commission += transaction_payment_list[_transaction_id] / 100 * commission_percent;
TransferPayment(msg.sender, transaction_payment_list[_transaction_id] - transaction_payment_list[_transaction_id] / 100 * commission_percent);
transaction_payment_list[_transaction_id] = 0;
}
function TransferPayment(address _receiver, uint _amount) internal {
payable(_receiver).transfer(_amount);
}
function setAdmin(address _newAdmin) external onlyAdmin {
require(_newAdmin != address(0));
admin = _newAdmin;
}
}
/*
Author Muhammed Akıncı
*/