-
Notifications
You must be signed in to change notification settings - Fork 2
/
atomContract.sol
113 lines (95 loc) · 3.66 KB
/
atomContract.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
106
107
108
109
110
111
112
113
pragma solidity ^0.5.1;
import "./contract.sol";
contract atomContract is Contrat {
uint internal price;
address payable internal buyer;
address payable internal deliverer;
uint8 internal ratingCD = 255;
uint8 internal ratingFD = 255;
uint8 internal ratingCF = 255;
uint8 internal ratingDF = 255;
uint8 internal ratingDC = 255;
bytes32 internal hash_localisation_buyer;
constructor(uint _price, string memory _title, string memory _localisation, string memory _description, uint _dell_price) public Contrat(_title,_localisation, _description, _dell_price){
require(_price!=0 );
price = _price * (1 ether);
typee = Type.atom;
}
/**
* a user buy the contract. the money is put on the balance, the buyer is set, the disponibility is set to delivering
* an event is send
*/
function buy(string calldata _localisation_buyer) external payable {
require(msg.value == price + dell_price);
require(dispo == Disponibility.Available);
buyer = msg.sender;
dispo = Disponibility.Wait_for_deliverer;
hash_localisation_buyer = sha256(abi.encode(_localisation_buyer));
emit dispoChanged();
}
function select_delivery() external {
require(dispo == Disponibility.Wait_for_deliverer);
deliverer = msg.sender;
dispo = Disponibility.Wait_for_delivering;
emit dispoChanged();
}
function receive_from_seller(uint8 _ratingDF ) external{
require(msg.sender == deliverer);
require(dispo == Disponibility.Wait_for_delivering);
require(_ratingDF <= 10);
dispo = Disponibility.On_delivering;
ratingDF = _ratingDF;
emit dispoChanged();
}
/**
* the buyer receive the object of the contract, the seller receives the money, and the disponibility is set to validated
* an event is send
*/
function reception() external{
require(msg.sender == buyer);
require(dispo == Disponibility.On_delivering);
owner.transfer(price);
deliverer.transfer(dell_price);
dispo = Disponibility.Wait_for_rating;
emit dispoChanged();
}
function finish_contract() internal{
require(msg.sender == owner || msg.sender == deliverer || msg.sender == buyer);
if(dispo == Disponibility.Wait_for_rating && ratingFD != 255 && ratingDF != 255 && ratingDC != 255 && ratingCF !=255 && ratingCD != 255){
dispo = Disponibility.Delivered;
emit dispoChanged();
}
}
function rate_seller(uint8 _ratingFD) external{
require(msg.sender == owner);
require(dispo == Disponibility.On_delivering || dispo == Disponibility.Wait_for_rating);
require(_ratingFD <= 10);
ratingFD = _ratingFD;
finish_contract();
}
function rate_deliverer(uint8 _ratingDC) external {
require(msg.sender == deliverer);
require(dispo == Disponibility.Wait_for_rating);
require(_ratingDC <= 10);
ratingDC = _ratingDC;
finish_contract();
}
function rate_buyer(uint8 _ratingCD, uint8 _ratingCF) external {
require(msg.sender == buyer);
require(dispo == Disponibility.Wait_for_rating);
require(_ratingCD <= 10);
require(_ratingCF <= 10);
ratingCD = _ratingCD;
ratingCF = _ratingCF;
finish_contract();
}
function getPrice() external view returns(uint){
return price;
}
function getBuyer() external view returns(address){
return buyer;
}
function getDeliverer() external view returns(address){
return deliverer;
}
}