-
Notifications
You must be signed in to change notification settings - Fork 2
/
contract.sol
82 lines (62 loc) · 2.19 KB
/
contract.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
pragma solidity ^0.5.1;
import "./ownable.sol";
contract Contrat is Ownable {
enum Disponibility{Available, Canceled, Wait_for_deliverer, Wait_for_delivering, On_delivering, Wait_for_rating, Delivered}
enum Type{atom,poly,master}
Disponibility internal dispo;
Type internal typee;
event dispoChanged();
event contratUpdate();
bytes32 internal hash_desc;
uint internal dell_price;
/**
* create a smart contract, initialize his value and put his disponibility to Available
*/
constructor(string memory _title,string memory _localisation, string memory _description, uint _dell_price) public Ownable(){
hash_desc = sha256(abi.encode(_title,_description,_localisation));
dispo = Disponibility.Available;
dell_price = _dell_price *(1 ether);
}
/**
* a modifier which allow modification only if the contract is cancel
*/
modifier onlyDispo(){
require(dispo == Disponibility.Canceled);
_;
}
/**
* change the disponibility from available to cancel, or from cancel to available
* an event is send
*/
function avalaibleToCancel() external onlyOwner{
require(dispo==Disponibility.Available || dispo==Disponibility.Canceled);
if(dispo == Disponibility.Available){
dispo = Disponibility.Canceled;
}else{
dispo = Disponibility.Available;
}
emit dispoChanged();
}
function getHash_desc()external view returns(bytes32){
return hash_desc;
}
function getDispo() external view returns(Disponibility){
return dispo;
}
function getTypee() external view returns(Type){
return typee;
}
/**
* various intermediate functions used in listContracts
* if the condition are not met, an error occurred
* they are define in order to avoid the use of function costing infinite gas
*/
function isAvailible(address _someone) external view returns(bool){
require((dispo == Disponibility.Available) && (owner!=_someone));
return(true);
}
function isMaster()external view returns(bool){
require(typee==Type.master);
return true;
}
}