-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetc.sol
94 lines (80 loc) · 2.77 KB
/
etc.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
pragma solidity ^0.4.24;
contract ETC{
// create etc order
event onCreateETCOrder
(
uint256 logisticOrderId,//logistic order id
address customerAddr,//customer address
uint256 eth //insurance money
);
// excute etc once
event onExcuteETCOnce
(
uint256 logisticOrderId,//logistic order id
address etcAddr,//etc address
uint256 eth //etc money once
);
// excute etc confirm
event onConfirm
(
uint256 logisticOrderId,//logistic order id
address customerAddr,//customer address
uint256 eth //leave money
);
/** contract total money */
uint256 public pool = 0;
address private etcAddr = 0xd0a50a025a06f8231c715432dd690d7d26ca0a84;
address private admin = msg.sender;
address public comfirmAddr;
//****************
// ETC Order
//****************
mapping (uint256 => EtcOrder) public EtcOrders; // (customerIdCard => etcOrder) etcOrders
modifier onlyAdmin(address _adminAddr){
require(admin == _adminAddr,"must be admin address");
_;
}
modifier onlyConfirmAddr(address _confirmAddr){
require(comfirmAddr == _confirmAddr,"must be confirm address");
_;
}
modifier onlyETCAddr(address _etcAddr){
require(etcAddr == _etcAddr,"must be etc address");
_;
}
function core(uint256 logisticOrderId,address customerAddr)
onlyConfirmAddr(msg.sender)
public payable{
pool = pool + msg.value;
EtcOrders[logisticOrderId] = EtcOrder(customerAddr,msg.value);
emit onCreateETCOrder(logisticOrderId,customerAddr,msg.value);
}
function setConfirmAddr(address _confirmAddr)
onlyAdmin(msg.sender)
public {
comfirmAddr = _confirmAddr;
}
function reduce(uint256 logisticOrderId)
onlyETCAddr(msg.sender)
public payable{
require(EtcOrders[logisticOrderId].eth > 0,"order id must be exists");
EtcOrders[logisticOrderId].eth = EtcOrders[logisticOrderId].eth - 10 ** 17;
etcAddr.transfer(10 ** 17);
pool = pool - 10 ** 17;
emit onExcuteETCOnce(logisticOrderId,EtcOrders[logisticOrderId].customerAddr,10 ** 17);
}
function confirm(uint256 logisticOrderId)
onlyConfirmAddr(msg.sender)
public{
if (EtcOrders[logisticOrderId].eth > 0) {
pool = pool - EtcOrders[logisticOrderId].eth;
address customerAddr = EtcOrders[logisticOrderId].customerAddr;
customerAddr.transfer(EtcOrders[logisticOrderId].eth);
emit onConfirm(logisticOrderId,customerAddr,EtcOrders[logisticOrderId].eth);
}
}
struct EtcOrder{
address customerAddr; //customer address
uint256 eth; // eth custumer pay total
}
}