“ExampleofPurchaseContract”的版本间的差异
跳到导航
跳到搜索
(建立内容为“{{DISPLAYTITLE:<span style="position: absolute; clip: rect(1px 1px 1px 1px); clip: rect(1px, 1px, 1px, 1px);">{{FULLPAGENAME}}</span>}} === <div style=" backgroun…”的新页面) |
|||
| 第3行: | 第3行: | ||
{| class="wikitable" | {| class="wikitable" | ||
|| Purchase contract, transfers the ownership of goods from a seller to a buyer through logistics company. There are 10 terms in the contract, including three parts: <br> 1) once the goods are confirmed, the seller will sign a contract and take twice the contracting price as the delivery price,<br> 2) the goods are sent to the buyer through logistics when the buyer purchases the goods, and 3) only when the logistics successfully delivers the goods to the buyer can the seller get back the payment. According to relevant laws, the contract requires the buyer can apply for compensation if goods do not arrive within 10 days after payment, or the seller can automatically confirm the arrival if the buyer does not confirm or apply for refund within 7 days after arrival. | || Purchase contract, transfers the ownership of goods from a seller to a buyer through logistics company. There are 10 terms in the contract, including three parts: <br> 1) once the goods are confirmed, the seller will sign a contract and take twice the contracting price as the delivery price,<br> 2) the goods are sent to the buyer through logistics when the buyer purchases the goods, and 3) only when the logistics successfully delivers the goods to the buyer can the seller get back the payment. According to relevant laws, the contract requires the buyer can apply for compensation if goods do not arrive within 10 days after payment, or the seller can automatically confirm the arrival if the buyer does not confirm or apply for refund within 7 days after arrival. | ||
| − | '''< | + | ---- |
| − | // purchase.scs | + | ''' |
| − | contract Purchase{ | + | <font color=green>// purchase.scs</font><br> |
| − | + | <font color=blue>contract</font> Purchase{<br> | |
| − | + | :<font color=green>// 定义seller角色,有四个动作</font><br> | |
| − | + | :<font color=blue>party</font> seller{<br> | |
| − | + | :::create()<br> | |
| − | + | :::abort()<br> | |
| − | + | :::confirmClaim()<br> | |
| − | + | :::autoConfirm()<br> | |
| − | + | :}<br><br> | |
| − | + | :<font color=green>// 定义buyer角色,有五个动作</font><br> | |
| − | + | :<font color=blue>party</font> buyer{<br> | |
| − | + | :::confirmPurchase()<br> | |
| − | + | :::confirmReceived()<br> | |
| − | + | :::overtimeClaim()<br> | |
| − | + | :::claim()<br> | |
| − | + | :::revokeClaim()<br> | |
| − | + | :}<br><br> | |
| − | + | :<font color=green>// 第三方角色,物流公司</font><br> | |
| − | + | :<font color=blue>party</font> logistics{<br> | |
| − | + | :::arrive()<br> | |
| − | + | :} | |
| − | + | <br> | |
| − | + | :balance : integer | |
| − | + | <br> | |
| − | + | :<font color=green>// 定义一个商品描述,good是下面定义的商品结构体</font><br> | |
| − | + | :xxxDescription : goods | |
| − | + | <br> | |
| − | + | :<font color=green>// 卖家可以创建合约,同时要存入物品两倍价格作为保证金</font><br> | |
| − | + | :<font color=blue>term</font> no1 : seller <font color=blue>can</font> create<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>deposit</font> $ xxxDescription::price*2. | |
| − | + | <br> | |
| − | + | :<font color=green>// 买家创建合约后买家可以确认购买,同时要存入物品两倍价格作为保证金和货款</font><br> | |
| − | + | :<font color=blue>term</font> no2 : buyer <font color=blue>can</font> confirmPurchase<br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>after</font> seller <font color=blue>did</font> create<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>deposit</font> $ xxxDescription::price*2. | |
| − | + | <br> | |
| − | + | :<font color=green>// 卖家在买家确认购买之前,可以撤回合约,并取走两倍的保证金</font><br> | |
| − | + | :<font color=blue>term</font> no3 : seller <font color=blue>can</font> abort <br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>before</font> buyer <font color=blue>did</font> confirmPurchase <br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>withdraw</font> $ xxxDescription::price*2. | |
| − | + | <br> | |
| − | + | :<font color=green>// 买家付款后10天内必须到货</font><br> | |
| − | + | :<font color=blue>term</font> no4 : logistics <font color=blue>must</font> arrive <br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>within</font> 10 <font color=blue>day</font> <font color=blue>after</font> buyer <font color=blue>did</font> confirmPurchase. | |
| − | + | <br> | |
| − | + | :<font color=green>// 买家在到货后7天内必须确认到货,同时双方取走保证金,卖家取走货款</font><br> | |
| − | + | :<font color=blue>term</font> no5 : buyer <font color=blue>must</font> confirmReceived <br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>within</font> 7 <font color=blue>day</font> <font color=blue>after</font> logistics <font color=blue>did</font> arrive<br> | |
| − | + | ::<font color=blue>while</font><br> | |
| − | + | :::<font color=blue>withdraw</font> $ xxxDescription::price<br> | |
| − | + | :::<font color=blue>transfer</font> $ balance <font color=blue>to</font> seller. | |
| − | + | <br> | |
| − | + | :<font color=green>// 买家可以在到货7天内申请赔款</font><br> | |
| − | + | :<font color=blue>term</font> no6 : buyer <font color=blue>can</font> claim <br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>within</font> 7 <font color=blue>day</font> <font color=blue>after</font> logistics <font color=blue>did</font> arrive. | |
| − | + | <br> | |
| − | + | :<font color=green>// 如果货物在付款后10天内没到,买家可以申请赔款</font><br> | |
| − | + | :<font color=blue>term</font> no7 : buyer <font color=blue>can</font> overtimeClaim <br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>after</font> start + 10 <font color=blue>day</font> or <font color=blue>after</font> logistics <font color=blue>did</font> arrive. | |
| − | + | <br> | |
| − | + | :<font color=green>// 卖家可以同意退款,并把所有保证金及货款转给买家</font><br> | |
| − | + | :<font color=blue>term</font> no8 : seller <font color=blue>can</font> confirmClaim <br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>after</font> buyer <font color=blue>did</font> claim or <font color=blue>after</font> buyer <font color=blue>did</font> overtimeClaim<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>transfer</font> $ balance <font color=blue>to</font> buyer. | |
| − | + | <br> | |
| − | + | :<font color=green>// 买家可以撤回退款申请</font><br> | |
| − | + | :<font color=blue>term</font> no9 : buyer <font color=blue>can</font> revokeClaim <br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>after</font> buyer <font color=blue>did</font> claim <font color=blue>or</font> <font color=blue>after</font> buyer <font color=blue>did</font> overtimeClaim<br> | |
| − | + | ::<font color=blue>while</font><br> | |
| − | + | :::<font color=blue>withdraw</font> $ xxxDescription::price<br> | |
| − | + | :::<font color=blue>transfer</font> $ balance <font color=blue>to</font> seller. | |
| − | + | <br> | |
| − | + | :<font color=green>// 如果到货七天内买家没有确认或申请退款,卖家可以自动确认到货</font><br> | |
| − | + | :<font color=blue>term</font> no10 : seller <font color=blue>can</font> autoConfirm <br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>before</font> buyer <font color=blue>did</font> claim <font color=blue>and</font> 7 <font color=blue>day</font> <font color=blue>after</font> logistics <font color=blue>did</font> arrive<br> | |
| − | + | ::<font color=blue>while</font><br> | |
| − | + | :::<font color=blue>withdraw</font> $ xxxDescription::price<br> | |
| − | + | :::<font color=blue>transfer</font> $ balance <font color=blue>to</font> seller. | |
| − | + | <br> | |
| − | + | :<font color=blue>type</font> goods {<br> | |
| − | + | ::name : Name <font color=green>// 物品名称</font><br> | |
| − | + | ::quantity : integer <font color=green>// 物品数量</font><br> | |
| − | + | ::price : Money <font color=green>// 价格</font><br> | |
| − | + | ::package : String <font color=green>// 运送包装</font><br> | |
| − | } | + | :}<br> |
| − | < | + | }<br> |
| + | ''' | ||
'''<syntaxhighlight lang="spec" line="1"> | '''<syntaxhighlight lang="spec" line="1"> | ||
/* buyerT.sol */ | /* buyerT.sol */ | ||
2021年9月12日 (日) 08:16的最新版本
Purchase contract
| Purchase contract, transfers the ownership of goods from a seller to a buyer through logistics company. There are 10 terms in the contract, including three parts: 1) once the goods are confirmed, the seller will sign a contract and take twice the contracting price as the delivery price, 2) the goods are sent to the buyer through logistics when the buyer purchases the goods, and 3) only when the logistics successfully delivers the goods to the buyer can the seller get back the payment. According to relevant laws, the contract requires the buyer can apply for compensation if goods do not arrive within 10 days after payment, or the seller can automatically confirm the arrival if the buyer does not confirm or apply for refund within 7 days after arrival.
// purchase.scs
} 1 /* buyerT.sol */
2 pragma solidity ^0.4.22;
3
4 contract buyerT{
5
6
7 //attributes of actionconfirmPurchase
8 bool _isconfirmPurchaseDone;
9 uint _confirmPurchaseTime;
10
11 //attributes of actionconfirmReceived
12 bool _isconfirmReceivedDone;
13 uint _confirmReceivedTime;
14
15 //attributes of actionovertimeClaim
16 bool _isovertimeClaimDone;
17 uint _overtimeClaimTime;
18
19 //attributes of actionclaim
20 bool _isclaimDone;
21 uint _claimTime;
22
23 //attributes of actionrevokeClaim
24 bool _isrevokeClaimDone;
25 uint _revokeClaimTime;
26
27 uint _max;
28 bool _isbuyerDone;
29 uint _i = 0;
30
31 address[] _buyerAddress;
32 function buyerT(){
33 _max = now*1000;
34 }
35
36 function regist(address a) public {
37 _buyerAddress[_i] = a;
38 _i++;
39 }
40
41 function getAddress() public returns (address a){
42 return _buyerAddress[_i];
43 }
44
45 function confirmPurchaseDone(address a){
46 _confirmPurchaseTime = now;
47 _isbuyerDone = true;
48 }
49
50 function confirmPurchaseTime() returns (uint result){
51 if(_isconfirmPurchaseDone){
52 return _confirmPurchaseTime;
53 }
54 return _max;
55 }
56
57 function confirmReceivedDone(address a){
58 _confirmReceivedTime = now;
59 _isbuyerDone = true;
60 }
61
62 function confirmReceivedTime() returns (uint result){
63 if(_isconfirmReceivedDone){
64 return _confirmReceivedTime;
65 }
66 return _max;
67 }
68
69 function overtimeClaimDone(address a){
70 _overtimeClaimTime = now;
71 _isbuyerDone = true;
72 }
73
74 function overtimeClaimTime() returns (uint result){
75 if(_isovertimeClaimDone){
76 return _overtimeClaimTime;
77 }
78 return _max;
79 }
80
81 function claimDone(address a){
82 _claimTime = now;
83 _isbuyerDone = true;
84 }
85
86 function claimTime() returns (uint result){
87 if(_isclaimDone){
88 return _claimTime;
89 }
90 return _max;
91 }
92
93 function revokeClaimDone(address a){
94 _revokeClaimTime = now;
95 _isbuyerDone = true;
96 }
97
98 function revokeClaimTime() returns (uint result){
99 if(_isrevokeClaimDone){
100 return _revokeClaimTime;
101 }
102 return _max;
103 }
104
105 function contains(address a) returns (bool result) {
106 for (uint _j = 0; _j < _buyerAddress.length; _j++ ) { //for loop example
107 if (a == _buyerAddress[_j]){
108 return true;
109 }
110 }
111 return false;
112 }
113
114 }
1 /* logisticsT.sol */
2 pragma solidity ^0.4.22;
3
4 contract logisticsT{
5
6
7 //attributes of actionarrive
8 bool _isarriveDone;
9 uint _arriveTime;
10
11 uint _max;
12 bool _islogisticsDone;
13 uint _i = 0;
14
15 address[] _logisticsAddress;
16 function logisticsT(){
17 _max = now*1000;
18 }
19
20 function regist(address a) public {
21 _logisticsAddress[_i] = a;
22 }
23
24 function getAddress() public returns (address a){
25 return _logisticsAddress[_i];
26 }
27
28 function arriveDone(address a){
29 _arriveTime = now;
30 _islogisticsDone = true;
31 }
32
33 function arriveTime() returns (uint result){
34 if(_isarriveDone){
35 return _arriveTime;
36 }
37 return _max;
38 }
39
40 function contains(address a) returns (bool result) {
41 for (uint _j = 0; _j < _logisticsAddress.length; _j++ ) { //for loop example
42 if (a == _logisticsAddress[_j]){
43 return true;
44 }
45 }
46 return false;
47 }
48
49 }
1 /* Purchase.sol */
2 pragma solidity ^0.4.0;
3
4 import "./sellerT.sol";
5 import "./buyerT.sol";
6 import "./logisticsT.sol";
7
8 contract Purchase {
9
10 sellerT seller;
11 buyerT buyer;
12 logisticsT logistics;
13
14 uint balance;
15 goods xxxDescription;
16
17 uint start;
18 struct goods{
19 bytes32 name;
20 uint quantity;
21 uint price;
22 bytes32 package;
23 }
24
25 function Purchase(){
26 start = now;
27 seller = new sellerT();
28 buyer = new buyerT();
29 logistics = new logisticsT();
30 }
31
32 modifier onlyseller{
33 require(seller.contains(msg.sender));
34 _;
35 }
36
37 modifier onlybuyer{
38 require(buyer.contains(msg.sender));
39 _;
40 }
41
42 modifier onlylogistics{
43 require(logistics.contains(msg.sender));
44 _;
45 }
46
47 modifier no2Modifier{
48 require(now > seller.createTime());
49 require(xxxDescription.price * 2 > 0);
50 _;
51 }
52
53 modifier no3Modifier{
54 require(now < buyer.confirmPurchaseTime());
55 _;
56 }
57
58 modifier no4Modifier{
59 require((now > buyer.confirmPurchaseTime()) &&(now < buyer.confirmPurchaseTime()+864000));
60 _;
61 }
62
63 modifier no5Modifier{
64 require((now > logistics.arriveTime()) &&(now < logistics.arriveTime()+604800));
65 _;
66 }
67
68 modifier no6Modifier{
69 require((now > logistics.arriveTime()) &&(now < logistics.arriveTime()+604800));
70 _;
71 }
72
73 modifier no7Modifier{
74 require(now > start + 864000 || now > logistics.arriveTime());
75 _;
76 }
77
78 modifier no8Modifier{
79 require(now > buyer.claimTime() || now > buyer.overtimeClaimTime());
80 _;
81 }
82
83 modifier no9Modifier{
84 require(now > buyer.claimTime() || now > buyer.overtimeClaimTime());
85 _;
86 }
87
88 modifier no10Modifier{
89 require(now < buyer.claimTime() && now > logistics.arriveTime()+604800);
90 _;
91 }
92
93 function create() onlyseller() public payable {
94 //USER CODE HERE
95 //CHECK
96
97 }
98
99 function confirmPurchase() onlybuyer() no2Modifier() public payable {
100 //USER CODE HERE
101 //CHECK
102
103 }
104
105 function abort() onlyseller() no3Modifier() public payable {
106 //USER CODE HERE
107 msg.sender.transfer(xxxDescription.price * 2);
108 //CHECK
109
110 }
111
112 function arrive() onlylogistics() no4Modifier() public {
113 //USER CODE HERE
114 //CHECK
115
116 }
117
118 function confirmReceived() onlybuyer() no5Modifier() public payable {
119 //USER CODE HERE
120 msg.sender.transfer(xxxDescription.price);
121 address(seller).transfer(balance);
122 //CHECK
123
124 }
125
126 function claim() onlybuyer() no6Modifier() public {
127 //USER CODE HERE
128 //CHECK
129
130 }
131
132 function overtimeClaim() onlybuyer() no7Modifier() public {
133 //USER CODE HERE
134 //CHECK
135
136 }
137
138 function confirmClaim() onlyseller() no8Modifier() public payable {
139 //USER CODE HERE
140 address(buyer).transfer(balance);
141 //CHECK
142
143 }
144
145 function revokeClaim() onlybuyer() no9Modifier() public payable {
146 //USER CODE HERE
147 msg.sender.transfer(xxxDescription.price);
148 address(seller).transfer(balance);
149 //CHECK
150
151 }
152
153 function autoConfirm() onlyseller() no10Modifier() public payable {
154 //USER CODE HERE
155 msg.sender.transfer(xxxDescription.price);
156 address(seller).transfer(balance);
157 //CHECK
158
159 }
160
161 }
1 /* sellerT.sol */
2 pragma solidity ^0.4.22;
3
4 contract sellerT{
5
6
7 //attributes of actioncreate
8 bool _iscreateDone;
9 uint _createTime;
10
11 //attributes of actionabort
12 bool _isabortDone;
13 uint _abortTime;
14
15 //attributes of actionconfirmClaim
16 bool _isconfirmClaimDone;
17 uint _confirmClaimTime;
18
19 //attributes of actionautoConfirm
20 bool _isautoConfirmDone;
21 uint _autoConfirmTime;
22
23 uint _max;
24 bool _issellerDone;
25 uint _i = 0;
26
27 address[] _sellerAddress;
28 function sellerT(){
29 _max = now*1000;
30 }
31
32 function regist(address a) public {
33 _sellerAddress[_i] = a;
34 _i++;
35 }
36
37 function getAddress() public returns (address a){
38 return _sellerAddress[_i];
39 }
40
41 function createDone(address a){
42 _createTime = now;
43 _issellerDone = true;
44 }
45
46 function createTime() returns (uint result){
47 if(_iscreateDone){
48 return _createTime;
49 }
50 return _max;
51 }
52
53 function abortDone(address a){
54 _abortTime = now;
55 _issellerDone = true;
56 }
57
58 function abortTime() returns (uint result){
59 if(_isabortDone){
60 return _abortTime;
61 }
62 return _max;
63 }
64
65 function confirmClaimDone(address a){
66 _confirmClaimTime = now;
67 _issellerDone = true;
68 }
69
70 function confirmClaimTime() returns (uint result){
71 if(_isconfirmClaimDone){
72 return _confirmClaimTime;
73 }
74 return _max;
75 }
76
77 function autoConfirmDone(address a){
78 _autoConfirmTime = now;
79 _issellerDone = true;
80 }
81
82 function autoConfirmTime() returns (uint result){
83 if(_isautoConfirmDone){
84 return _autoConfirmTime;
85 }
86 return _max;
87 }
88
89 function contains(address a) returns (bool result) {
90 for (uint _j = 0; _j < _sellerAddress.length; _j++ ) { //for loop example
91 if (a == _sellerAddress[_j]){
92 return true;
93 }
94 }
95 return false;
96 }
97
98 }
|