-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlockchainSolution1114.sol
151 lines (114 loc) · 4.58 KB
/
BlockchainSolution1114.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
pragma solidity ^0.4.23;
contract SaleContract{
address applicant = msg.sender;
string Buyer;
string Seller;
string Bank;
address addr_Buyer;
address addr_Seller;
uint Price;
uint TotalValue;
uint timeOfShipment;
string PortOfLanding;
string PortOfDest;
string PayDetail;
address addr_Bank;
uint public sequence = 1;
bool public BoolDeposit;
bool public lock_all;
bool public AlreadyPay;
bool public AlreadyShip;
uint PayBeforeShipment;
uint PayAfterShipment;
uint EditTimes;
mapping (address => uint) userSeq;
mapping (uint => string) status;
constructor (address _importer, address _exporter, address _bank ) // 建構子 發布合約時要同時設定這三個address
{
addr_Buyer = _importer;
addr_Seller = _exporter;
addr_Bank = _bank;
userSeq[addr_Buyer]= 1; userSeq[addr_Seller]= 2; userSeq[addr_Bank]= 3;
}
function dispute() //買賣有爭議時才按下,銀行接管智能合約上的貨款
{
require (msg.sender==addr_Seller||msg.sender==addr_Buyer);
sequence = 0;
}
modifier IsOwner //判別開狀人身分用
{
require (applicant == msg.sender);
_;
}
modifier seq //用來控制順序
{
require (userSeq[msg.sender]!=0 && userSeq[msg.sender]==sequence );
_;
}
modifier lockAll //用來保證大家都確認完後信用狀無法被任何人修改
{
require(lock_all == false);
_;
}
modifier IsUser //判別開狀人身分用
{
require (msg.sender==addr_Seller || msg.sender==addr_Buyer || msg.sender==addr_Bank );
_;
}
function getBallence() constant returns(uint){ //取得此合約內餘額資訊
return address(this).balance;
}
function setInform ( string _Buyer , string _Seller , uint _Price , uint _timeOfShipment
, string _PortOfLanding , string _PortOfDest , string _PayDetail ,uint _PayBeforeShipment , uint _PayAfterShipment ) lockAll IsUser returns (address)
{ require(_PayAfterShipment + _PayBeforeShipment == _Price);
EditTimes++;
sequence = 1;
Buyer = _Buyer ; Seller = _Seller ; Price = _Price;
timeOfShipment = _timeOfShipment ; PortOfLanding = _PortOfLanding ; PortOfDest = _PortOfDest ; PayDetail = _PayDetail ;
PayBeforeShipment = _PayBeforeShipment ; PayAfterShipment = _PayAfterShipment ;
return msg.sender;
}
function output() returns (string , string , uint , uint , string , string , string ,uint , uint)
{
return (Buyer , Seller , Price , timeOfShipment , PortOfLanding , PortOfDest , PayDetail , PayBeforeShipment , PayAfterShipment);
}
function pay() payable //用來付款的函式
{
require(lock_all == true);
if (Price <= address(this).balance)
{
AlreadyPay = true;
}
if (address(this).balance >= PayBeforeShipment)
{
BoolDeposit = true;
}
}
function LcApproval() lockAll seq{ //照順序驗證合約的函式
sequence++;
if (sequence == 4){
lock_all=true;
}
}
function finish() //收貨完成後按下,智能合約把貨款支付給出口出口商
{ require(sequence == 4);
require(msg.sender == addr_Buyer);
require(AlreadyPay == true);
addr_Seller.send(Price);
}
function arbitrate(address addrSend , uint amount) //銀行仲裁時使用的函式
{
require(sequence == 0);
require(msg.sender == addr_Bank);
require(addrSend == addr_Seller || addrSend == addr_Buyer);
require(amount <= address(this).balance);
addrSend.transfer(amount);
}
function shipment() //出口商要出貨時按下,會檢查合約是否審核完成,以及訂金是否已經支付
{
AlreadyShip = true;
require (msg.sender == addr_Seller);
require (lock_all == true);
require (address(this).balance >= PayBeforeShipment);
}
}