“Examples”的版本间的差异
跳到导航
跳到搜索
| 第5行: | 第5行: | ||
|| Loan contract, refers to a contract where a lender delivers a certain amount of funds to a borrower, and the latter returns the same amount of funds within a certain period of time and pays interests to the lender. There are 6 terms in the contract that consists of two aspects: <br> 1) the borrower shall submit a loan application stating the amount he/she wants to borrow, and <br> 2) the lender may deposit funds into the contract account until the target of loan is reached. Before borrowing, the contract requires that the borrower must confirm the loan information and check the historical loan records, and then calculate the corresponding interests. Meanwhile, the contract asserts that the borrower pays off the loan amount before the loan date comes. | || Loan contract, refers to a contract where a lender delivers a certain amount of funds to a borrower, and the latter returns the same amount of funds within a certain period of time and pays interests to the lender. There are 6 terms in the contract that consists of two aspects: <br> 1) the borrower shall submit a loan application stating the amount he/she wants to borrow, and <br> 2) the lender may deposit funds into the contract account until the target of loan is reached. Before borrowing, the contract requires that the borrower must confirm the loan information and check the historical loan records, and then calculate the corresponding interests. Meanwhile, the contract asserts that the borrower pays off the loan amount before the loan date comes. | ||
|} | |} | ||
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
// Lend Spesc.scs | // Lend Spesc.scs | ||
contract Lend{ | contract Lend{ | ||
| 第62行: | 第62行: | ||
} | } | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* FunderT.sol */ | /* FunderT.sol */ | ||
pragma solidity >=0.4.0 <0.6.0; | pragma solidity >=0.4.0 <0.6.0; | ||
| 第113行: | 第113行: | ||
} | } | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* Lend.sol */ | /* Lend.sol */ | ||
pragma solidity >=0.4.0 <0.6.0; | pragma solidity >=0.4.0 <0.6.0; | ||
| 第238行: | 第238行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* UserT.sol */ | /* UserT.sol */ | ||
pragma solidity >=0.4.0 <0.6.0; | pragma solidity >=0.4.0 <0.6.0; | ||
| 第309行: | 第309行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
=== <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> (2)Auction contract </div> === | === <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> (2)Auction contract </div> === | ||
| 第315行: | 第315行: | ||
|| Auction contract involves two parties: auctioneer who is an enterprise legal person engaged in auction activities, and bidders who are some citizens, legal persons or organizations to participate in bidding for auction targets. The highest bidding process is described as the following steps. The auctioneer starts the auction system after setting a reserve price and an auction end time, and waits for the auction to end; The bidders can bid anytime during the system. If the bid is greater than the current highest price, the system records it as new highest price, puts the bid into the fund pool, and returns the bid paid by the previous highest bidder; otherwise, the bidder fails and the bid is returned; After the auction time is over, the auctioneer can collect the highest bid from the fund pool. | || Auction contract involves two parties: auctioneer who is an enterprise legal person engaged in auction activities, and bidders who are some citizens, legal persons or organizations to participate in bidding for auction targets. The highest bidding process is described as the following steps. The auctioneer starts the auction system after setting a reserve price and an auction end time, and waits for the auction to end; The bidders can bid anytime during the system. If the bid is greater than the current highest price, the system records it as new highest price, puts the bid into the fund pool, and returns the bid paid by the previous highest bidder; otherwise, the bidder fails and the bid is returned; After the auction time is over, the auctioneer can collect the highest bid from the fund pool. | ||
|} | |} | ||
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
// Simple Auction.scs | // Simple Auction.scs | ||
contract SimpleAuction{ | contract SimpleAuction{ | ||
| 第358行: | 第358行: | ||
while withdraw $highestPrice. | while withdraw $highestPrice. | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* auctioneerT.sol */ | /* auctioneerT.sol */ | ||
pragma solidity >=0.4.0 <0.6.0; | pragma solidity >=0.4.0 <0.6.0; | ||
| 第414行: | 第414行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* biddersT.sol */ | /* biddersT.sol */ | ||
pragma solidity ^0.4.22; | pragma solidity ^0.4.22; | ||
| 第555行: | 第555行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* goodsOwnerT.sol */ | /* goodsOwnerT.sol */ | ||
pragma solidity ^0.4.22; | pragma solidity ^0.4.22; | ||
| 第615行: | 第615行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* SimpleAuction.sol */ | /* SimpleAuction.sol */ | ||
pragma solidity ^0.4.22; | pragma solidity ^0.4.22; | ||
| 第675行: | 第675行: | ||
} | } | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
=== <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> (3)House-leasing contract </div> === | === <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> (3)House-leasing contract </div> === | ||
| 第681行: | 第681行: | ||
|| House-leasing contract, takes assets as the transaction subject between lessor and lessee. There are 7 terms in the contract, including two aspects:<br> 1) the lessor can register the house after depositing the rental deposit, and <br> 2) the lessee can keep the right to use the house during the leasing period after depositing the rent. After confirming the leased house, the contract requires that the lessee shall pay the rent, and the lessor must transfer the right to the lessee within one week. Meanwhile, the contract stipulates the pre-condition for the lessor to charge the rent paid by the lessee, and the postcondition for both parties to get their deposits back after the house inspection. | || House-leasing contract, takes assets as the transaction subject between lessor and lessee. There are 7 terms in the contract, including two aspects:<br> 1) the lessor can register the house after depositing the rental deposit, and <br> 2) the lessee can keep the right to use the house during the leasing period after depositing the rent. After confirming the leased house, the contract requires that the lessee shall pay the rent, and the lessor must transfer the right to the lessee within one week. Meanwhile, the contract stipulates the pre-condition for the lessor to charge the rent paid by the lessee, and the postcondition for both parties to get their deposits back after the house inspection. | ||
|} | |} | ||
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
// HouseLease.scs | // HouseLease.scs | ||
contract Houselease{ | contract Houselease{ | ||
| 第766行: | 第766行: | ||
} | } | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* Houselease.sol */ | /* Houselease.sol */ | ||
pragma solidity ^0.4.0; | pragma solidity ^0.4.0; | ||
| 第903行: | 第903行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* RenterT.sol */ | /* RenterT.sol */ | ||
pragma solidity ^0.4.22; | pragma solidity ^0.4.22; | ||
| 第1,019行: | 第1,019行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* TenantT.sol */ | /* TenantT.sol */ | ||
pragma solidity ^0.4.22; | pragma solidity ^0.4.22; | ||
| 第1,119行: | 第1,119行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
=== <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> (4)Purchase contract </div> === | === <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> (4)Purchase contract </div> === | ||
{| 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. | ||
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
// purchase.scs | // purchase.scs | ||
contract Purchase{ | contract Purchase{ | ||
| 第1,210行: | 第1,210行: | ||
} | } | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* buyerT.sol */ | /* buyerT.sol */ | ||
pragma solidity ^0.4.22; | pragma solidity ^0.4.22; | ||
| 第1,326行: | 第1,326行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* logisticsT.sol */ | /* logisticsT.sol */ | ||
pragma solidity ^0.4.22; | pragma solidity ^0.4.22; | ||
| 第1,377行: | 第1,377行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* Purchase.sol */ | /* Purchase.sol */ | ||
pragma solidity ^0.4.0; | pragma solidity ^0.4.0; | ||
| 第1,540行: | 第1,540行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
| − | <syntaxhighlight lang="spec" line="1"> | + | '''<syntaxhighlight lang="spec" line="1"> |
/* sellerT.sol */ | /* sellerT.sol */ | ||
pragma solidity ^0.4.22; | pragma solidity ^0.4.22; | ||
| 第1,641行: | 第1,641行: | ||
} | } | ||
| − | </syntaxhighlight> | + | </syntaxhighlight>''' |
2021年2月28日 (日) 03:05的版本
EXAMPLE
(1)Loan contract
| Loan contract, refers to a contract where a lender delivers a certain amount of funds to a borrower, and the latter returns the same amount of funds within a certain period of time and pays interests to the lender. There are 6 terms in the contract that consists of two aspects: 1) the borrower shall submit a loan application stating the amount he/she wants to borrow, and 2) the lender may deposit funds into the contract account until the target of loan is reached. Before borrowing, the contract requires that the borrower must confirm the loan information and check the historical loan records, and then calculate the corresponding interests. Meanwhile, the contract asserts that the borrower pays off the loan amount before the loan date comes. |
1 // Lend Spesc.scs
2 contract Lend{
3 party User{
4 loan : Loan
5 SubmitLoanApplication(l : Loan)
6 confirm()
7 getHisLoan()
8 payback()
9 }
10
11 party Funder{
12 moneyFunded : Money
13 moneyWillGet : Money
14 Contribute(uid : User)
15 refund(uid : User)
16 }
17
18 term term1 : User can SubmitLoanApplication.
19
20 term term2 : Funder can Contribute
21 when before uid::loan::timelimit
22 while deposit $ value <= uid::loan::fundingGoal.
23
24 term term3 : Funder can refund
25 when after uid::loan::timelimit and uid::loan::amount < uid::loan::fundingGoal
26 while withdraw $ his::moneyFunded.
27
28 term term4 : User must confirm
29 when within 3 day after his::loan::timelimit and his::loan::amount = his::loan::fundingGoal.
30
31 term term5 : User can getHisLoan
32 when after User did confirm
33 while withdraw $ his::loan::amount.
34
35 term term6 : User must payback
36 when after User did confirm and before his::loan::tenorM
37 while
38 deposit $ his::loan::balance + his::loan::installment
39 transfer $ his::loan::funders::moneyWillGet to his::loan::funders.
40
41 type Loan
42 {
43 operationName : Name//use of money
44 beneficiary : User//Borrower
45 timelimit : Date//time limit of collecting money
46 fundingGoal : integer//the amount borrower want to borrow
47 amount : integer//the money collected now
48 balance : integer//the Capital have to pay back
49 numFunders : integer
50 interestRateM : integer// monthly
51 gracePeriod : integer//the period you don't have to pay the interest
52 tenorM : integer//monthly//you have to pay back tenorM month later
53 installment : integer//monthly//the interest have to pay back
54 funders : set Funder
55 }
56 }
1 /* FunderT.sol */
2 pragma solidity >=0.4.0 <0.6.0;
3
4 contract FunderT{
5
6 uint moneyFunded;
7 uint moneyWillGet;
8
9 address _FunderAddress;
10 uint _max;
11
12 function funderT() public{
13 _max = now*1000;
14 }
15 function regist(address a) public {
16 _FunderAddress = a;
17 }
18
19 function getAddress() public returns (address a){
20 return _FunderAddress;
21 }
22
23 function getmoneyFunded() public returns(uint _result){
24 return moneyFunded;
25 }
26
27 function setmoneyFunded ( uint a) public{
28 moneyFunded = a;
29 }
30
31 /* function getmoneyWillGet() public returns(uint _result){
32 return moneyWillGet;
33 }
34
35 function setmoneyWillGet(uint a) public {
36 moneyWillGet = a;
37 }*/
38
39
40
41 function setmoneyWillGet(uint256 newValue) public {
42 moneyWillGet = newValue;
43 }
44
45
46 function getmoneyWillGet() public view returns (uint256) {
47 return moneyWillGet;
48 }
49 }
1 /* Lend.sol */
2 pragma solidity >=0.4.0 <0.6.0;
3 pragma experimental ABIEncoderV2;
4
5 import "./UserT.sol";
6 import "./FunderT.sol";
7
8 contract Lend {
9
10 UserT User;
11 FunderT Funder;
12 uint start;
13
14
15 mapping (string => Loan) loan;
16
17 struct Loan{
18 bytes32 operationName;
19 address beneficiary;
20 uint timelimit;
21 uint fundingGoal;
22 uint amount;
23 uint balance;
24 uint numFunders;
25 uint interestRateM;
26 uint gracePeriod;
27 uint tenorM;
28 uint installment;
29 address funders;
30 }
31
32
33
34 constructor() public{
35 start = now;
36 User = new UserT();
37 Funder = new FunderT();
38 }
39
40 /* constructor() public{
41 start = now;
42 User = new UserT();
43 Funder = new FunderT();
44 }*/
45
46 modifier onlyUser{
47 require(User.getAddress()==msg.sender);
48 _;
49 }
50
51 modifier onlyFunder{
52 require(Funder.getAddress()==msg.sender);
53 _;
54 }
55
56 modifier term2Modifier(UserT uid){
57 // require(now < uid.loan.timelimit);
58 // require(msg.value <= uid.loan.fundingGoal);
59 _;
60 }
61
62 modifier term3Modifier(UserT uid){
63 // require(now > (uid.loan.timelimit && uid.loan.amount < uid.loan.fundingGoal));
64 _;
65 }
66
67 modifier term4Modifier{
68 // require((now > (User.getloan.timelimit(msg.sender) && User.getloan.amount(msg.sender) == User.getloan.fundingGoal(msg.sender))) &&(now < (User.getloan.timelimit(msg.sender) && User.getloan.amount(msg.sender) == User.getloan.fundingGoal(msg.sender))+259200));
69 _;
70 }
71
72 modifier term5Modifier{
73 require(now > User.confirmTime());
74 _;
75 }
76
77 modifier term6Modifier{
78 // require(now > (User.confirmTime() && now < User.getloan.tenorM(msg.sender)));
79 // require(User.getloan.balance(msg.sender) + User.getloan.installment(msg.sender));
80 _;
81 }
82
83 function SubmitLoanApplication( Loan memory l) onlyUser() public {
84 //USER CODE HERE
85 //CHECK
86
87 }
88
89 function Contribute(UserT uid) onlyFunder() term2Modifier(uid) public payable {
90 //USER CODE HERE
91 //CHECK
92
93 }
94
95 function refund(UserT uid) onlyFunder() term3Modifier(uid) public payable {
96 //USER CODE HERE
97 msg.sender.transfer(Funder.getmoneyFunded());
98 //CHECK
99
100 }
101
102 function confirm() onlyUser() term4Modifier() public {
103 //USER CODE HERE
104 //CHECK
105
106 }
107
108 function getHisLoan() onlyUser() term5Modifier() public payable {
109 //USER CODE HERE
110 msg.sender.transfer(User.getloan().amount);
111 //CHECK
112
113 }
114
115 function payback() onlyUser() term6Modifier() public payable {
116 //USER CODE HERE
117 //User.getloan().funders.transfer(msg.sender);
118 msg.sender.transfer(User.getloan().amount);
119 //CHECK
120
121 }
122
123 }
1 /* UserT.sol */
2 pragma solidity >=0.4.0 <0.6.0;
3 pragma experimental ABIEncoderV2;
4
5
6 import "./Lend.sol";
7
8 contract UserT{
9
10 struct Loan{
11 bytes32 operationName;
12 address beneficiary;
13 uint timelimit;
14 uint fundingGoal;
15 uint amount;
16 uint balance;
17 uint numFunders;
18 uint interestRateM;
19 uint gracePeriod;
20 uint tenorM;
21 uint installment;
22 address funders;
23 }
24
25
26
27
28 Loan loan;
29 //attributes of actionconfirm
30 bool _isconfirmDone;
31 uint _confirmTime;
32
33 address _UserAddress;
34 uint _max;
35
36 constructor ()public{
37 _max = now*1000;
38 }
39
40 function regist(address a) public {
41 _UserAddress = a;
42 }
43
44 function getAddress() public returns (address a){
45 return _UserAddress;
46 }
47
48 function getloan() public returns(Loan memory _result) {
49 return loan;
50 }
51
52 function setloan(Loan memory a) public{
53 loan = a;
54 }
55
56 function confirmDone() public{
57 _confirmTime = now;
58 _isconfirmDone = true;
59 }
60
61 function confirmTime() public returns (uint result){
62 if(_isconfirmDone){
63 return _confirmTime;
64 }
65 return _max;
66 }
67
68 }
(2)Auction contract
| Auction contract involves two parties: auctioneer who is an enterprise legal person engaged in auction activities, and bidders who are some citizens, legal persons or organizations to participate in bidding for auction targets. The highest bidding process is described as the following steps. The auctioneer starts the auction system after setting a reserve price and an auction end time, and waits for the auction to end; The bidders can bid anytime during the system. If the bid is greater than the current highest price, the system records it as new highest price, puts the bid into the fund pool, and returns the bid paid by the previous highest bidder; otherwise, the bidder fails and the bid is returned; After the auction time is over, the auctioneer can collect the highest bid from the fund pool. |
1 // Simple Auction.scs
2 contract SimpleAuction{
3 party group bidders{
4 amount : Money
5 Bid()
6 withdrawOverbidMoney()
7 }
8
9 party auctioneer{
10 StartBidding(reservePrice : Money, biddingTime : Date)
11 StopBidding()
12 }
13
14 highestPrice : Money
15 highestBidder : biddersBiddingStop
16 Time : Date
17
18 term no1 : auctioneer can StartBidding,
19 when before auctioneer did StartBidding
20 where highestPrice = reservePrice and BiddingStopTime = biddingTime + now.
21
22 term no2 : bidders can Bid,
23 when after auctioneer did StartBidding and before BiddingStopTime
24 while deposit $ value > highestPrice
25 where highestPrice = value and highestBidder = this bidder and
26 this bidder : : amount = this bidder: :0ri amount + value .
27
28 term no3_1 : bidders can withdrawOverbidMoney,
29 when this bidder isn't highestBidder and this bidder: :amount > 0
30 while withdraw $this bidder : :amount
31 where this bidder : : amount = 0.
32
33
34 term no3_2 : bidders can withdrawOverbidMoney,
35 when this bidder is highestBidder and this bidder : : amount > highestPrice
36 while withdraw $this bidder : : amount - highestPrice
37 where this bidder : : amount = highestPrice.
38
39 term no4 : auctioneer can StopBidding,
40 when after BiddingStopTime and before auctioneer did StopBidding
41 while withdraw $highestPrice.
42 }
1 /* auctioneerT.sol */
2 pragma solidity >=0.4.0 <0.6.0;
3
4 contract auctioneerT{
5
6
7 //attributes of actionStartBidding
8 bool _isStartBiddingDone;
9 uint _StartBiddingTime;
10
11 //attributes of actionCollectPayment
12 bool _isCollectPaymentDone;
13 uint _CollectPaymentTime;
14
15 address _auctioneerAddress;
16 uint _max;
17
18 constructor() public{
19 _max = now*1000;
20 }
21
22 function regist(address a) public {
23 _auctioneerAddress = a;
24 }
25
26 function getAddress() public returns (address a){
27 return _auctioneerAddress;
28 }
29
30 function StartBiddingDone() public{
31 _StartBiddingTime = now;
32 _isStartBiddingDone = true;
33 }
34
35 function StartBiddingTime() public returns (uint result){
36 if(_isStartBiddingDone){
37 return _StartBiddingTime;
38 }
39 return _max;
40 }
41
42 function CollectPaymentDone() public{
43 _CollectPaymentTime = now;
44 _isCollectPaymentDone = true;
45 }
46
47 function CollectPaymentTime() public returns (uint result){
48 if(_isCollectPaymentDone){
49 return _CollectPaymentTime;
50 }
51 return _max;
52 }
53
54 }
1 /* biddersT.sol */
2 pragma solidity ^0.4.22;
3
4 contract biddersT{
5
6 struct bidderstype{
7 uint amount;
8
9 //attributes of actionBid
10 bool _isBidDone;
11 uint _BidTime;
12
13 //attributes of actionWithdrawOverbidMoney
14 bool _isWithdrawOverbidMoneyDone;
15 uint _WithdrawOverbidMoneyTime;
16
17 }
18
19 uint _max;//time max
20 uint _sum;//total member of this party
21 uint _BidDoneNum;
22 uint[] _BidTime;
23
24 uint _WithdrawOverbidMoneyDoneNum;
25 uint[] _WithdrawOverbidMoneyTime;
26
27 bidderstype _Empty;//used to initialize
28 bidderstype[] _biddersEntity;
29 address[] _biddersAddress;
30 mapping(address=>uint) _userlist;
31
32 function biddersT(){
33 _BidDoneNum = 0;
34
35 _WithdrawOverbidMoneyDoneNum = 0;
36
37 _biddersEntity.push(_Empty);
38 _max = now*1000;
39 }
40
41 function getSum() public returns(uint c){
42 return _sum;
43 }
44
45 function add(address a) public {
46 _biddersEntity.push(_Empty);
47 _biddersAddress.push(a);
48 // _userlist[address] = _sum;
49
50 _sum ++;
51 }
52
53 function remove(address a) public {
54 uint num = _userlist[a];
55 _biddersEntity[num] = _biddersEntity[_sum-1];
56 delete(_biddersEntity[num]);
57 delete(_userlist[a]);
58 _sum --;
59 }
60
61 function getList() public returns (address[] a){
62 return _biddersAddress;
63 }
64
65 function contains(address a) public returns (bool b){
66 return _userlist[a] != 0;
67 }
68
69 function getamount(address a) returns(uint _result){
70 uint num = _userlist[a];
71 return _biddersEntity[num].amount;
72 }
73
74 function setamount(address a, uint b){
75 uint num = _userlist[a];
76 _biddersEntity[num].amount = b;
77 }
78
79 function BidDone(address a){
80 uint num = _userlist[a];
81 _biddersEntity[num]._BidTime = now;
82 _biddersEntity[num]._isBidDone = true;
83 _BidTime.push(_biddersEntity[num]._BidTime);
84 _BidDoneNum ++;
85 }
86
87 function BidTime(address a) returns (uint result){
88 uint num = _userlist[a];
89 if(_biddersEntity[num]._isBidDone){
90 return _biddersEntity[num]._BidTime;
91 }
92 return _max;
93 }
94
95 function BidAllTime() returns (uint result){
96 if(_BidDoneNum == _max-1){
97 return _BidTime[_BidDoneNum-1];
98 }
99 return _max;
100 }
101
102 function BidSomeTime() returns (uint result){
103 if(_BidDoneNum >= 1){
104 return _BidTime[0];
105 }
106 return _max;
107 }
108
109 function WithdrawOverbidMoneyDone(address a){
110 uint num = _userlist[a];
111 _biddersEntity[num]._WithdrawOverbidMoneyTime = now;
112 _biddersEntity[num]._isWithdrawOverbidMoneyDone = true;
113 _WithdrawOverbidMoneyTime.push(_biddersEntity[num]._WithdrawOverbidMoneyTime);
114 _WithdrawOverbidMoneyDoneNum ++;
115 }
116
117 function WithdrawOverbidMoneyTime(address a) returns (uint result){
118 uint num = _userlist[a];
119 if(_biddersEntity[num]._isWithdrawOverbidMoneyDone){
120 return _biddersEntity[num]._WithdrawOverbidMoneyTime;
121 }
122 return _max;
123 }
124
125 function WithdrawOverbidMoneyAllTime() returns (uint result){
126 if(_WithdrawOverbidMoneyDoneNum == _max-1){
127 return _WithdrawOverbidMoneyTime[_WithdrawOverbidMoneyDoneNum-1];
128 }
129 return _max;
130 }
131
132 function WithdrawOverbidMoneySomeTime() returns (uint result){
133 if(_WithdrawOverbidMoneyDoneNum >= 1){
134 return _WithdrawOverbidMoneyTime[0];
135 }
136 return _max;
137 }
138
139 }
1 /* goodsOwnerT.sol */
2 pragma solidity ^0.4.22;
3
4 contract goodsOwnerT{
5
6
7 //attributes of actionStartBidding
8 bool _isStartBiddingDone;
9 uint _StartBiddingTime;
10 bool _isgoodsOwnerDone;
11
12 uint _max;
13
14 //attributes of actionStopBidding
15 bool _isStopBiddingDone;
16 uint _StopBiddingTime;
17
18 address[] _goodsOwnerAddress;
19
20 constructor() public{
21 _max = now*1000;
22 }
23
24 function regist (address[] a){
25 _goodsOwnerAddress = a;
26 }
27
28 function getAddress() public returns (address[] a){
29 return _goodsOwnerAddress;
30 }
31
32 function StartBiddingDone(address[] a){
33 // StartBiddingTime = now;
34 _isgoodsOwnerDone = true;
35 //_isStartBiddingDone = true;
36 }
37
38 function StartBiddingTime() returns (uint result){
39 if(_isStartBiddingDone){
40 return _StartBiddingTime;
41 }
42 return _max;
43 }
44
45 function StopBiddingDone(address[] a){
46 // StopBiddingTime = now;
47 _isgoodsOwnerDone = true;
48 // _StopBiddingTime = true;
49 }
50
51 function StopBiddingTime() returns (uint result){
52 if(_isStopBiddingDone){
53 return _StopBiddingTime;
54 }
55 return _max;
56 }
57
58 }
1 /* SimpleAuction.sol */
2 pragma solidity ^0.4.22;
3
4 contract SimpleAuction {
5
6 address public beneficiary;
7 uint public auctionEnd;
8 address public highestBidder;
9 uint public highestBid;
10 mapping(address => uint) pendingReturns;
11 bool ended;
12
13 event HighestBidIncreased(address bidder, uint amount);
14 event AuctionEnded(address winner, uint amount);
15
16 constructor(uint _biddingTime, address _beneficiary) public {
17 beneficiary = _beneficiary;
18 auctionEnd = now + _biddingTime;
19 }
20
21 function bid() public payable {
22
23 require(now <= auctionEnd, "Auction already ended.");
24 require(msg.value > highestBid, "There already is a higher bid.");
25
26 if (highestBid != 0) {
27 pendingReturns[highestBidder] += highestBid;
28 }
29 highestBidder = msg.sender;
30 highestBid = msg.value;
31 HighestBidIncreased(msg.sender, msg.value);
32 }
33
34 function withdraw() public returns (bool) {
35 uint amount = pendingReturns[msg.sender];
36 if (amount > 0) {
37 pendingReturns[msg.sender] = 0;
38
39 if (!msg.sender.send(amount)) {
40 // No need to call throw here, just reset the amount owing
41 pendingReturns[msg.sender] = amount;
42 return false;
43 }
44 }
45 return true;
46 }
47
48 function auctionEnd() public {
49
50 require(now >= auctionEnd, "Auction not yet ended.");
51 require(!ended, "auctionEnd has already been called.");
52
53 ended = true;
54 AuctionEnded(highestBidder, highestBid);
55
56 beneficiary.transfer(highestBid);
57 }
58 }
(3)House-leasing contract
| House-leasing contract, takes assets as the transaction subject between lessor and lessee. There are 7 terms in the contract, including two aspects: 1) the lessor can register the house after depositing the rental deposit, and 2) the lessee can keep the right to use the house during the leasing period after depositing the rent. After confirming the leased house, the contract requires that the lessee shall pay the rent, and the lessor must transfer the right to the lessee within one week. Meanwhile, the contract stipulates the pre-condition for the lessor to charge the rent paid by the lessee, and the postcondition for both parties to get their deposits back after the house inspection. |
1 // HouseLease.scs
2 contract Houselease{
3 party Renter{
4 registerHouse()
5 collectRent()
6 collectBail()
7 transferHouse()
8 checkHouse()
9 }
10
11 party Tenant{
12 confirmLease(endLeasingDuration:Date,
13 payDuration:Date)
14 payRent()
15 returnHouse()
16 collectBail()
17 }
18
19 house : House
20 infos : contractInfo
21
22 term term1 : Renter can registerHouse
23 while deposit $infos::renterBail.
24
25 term term2 : Tenant can confirmLease
26 when after Renter did registerHouse
27 while deposit $infos::tenantBail
28 where infos::startLeasingTime = now and
29 infos::endLeasingTime = endLeasingDuration + now
30 and infos::payDate = payDuration + now
31 and infos::payDuration = payDuration.
32
33 term term3 : Renter must transferHouse
34 when within 7 day after Tenant did confirmLease
35 while deposit $ house::useRight.
36
37 term term4 : Tenant must payRent
38 when before Tenant did confirmLease
39 while deposit $infos::rental
40 withdraw $house::useRight
41 where infos::payDate = infos::payDate + infos::payDuration
42 and infos::totalRental = infos::totalRental + infos::rental.
43
44 term term5 : Renter can collectRent
45 while withdraw $infos::totalRental
46 where infos::totalRental = 0.
47
48 term term6 : Tenant must returnHouse
49 when within 7 day after Renter did checkHouse
50 while deposit $house::useRight
51 transfer $house::useRight to Renter.
52
53 term term7_1 : Renter can collectBail
54 when within 15 day after Renter did checkHouse
55 while withdraw $infos::renterBail.
56
57 term term7_2 : Tenant can collectBail
58 when within 15 day after Renter did checkHouse
59 while withdraw $infos::tenantBail.
60
61 type contractInfo {
62 renterBail : Money
63 tenantBail : Money
64 rental : Money
65 totalRental : Money
66 penalty : Money
67 startLeasingTime : Date
68 endLeasingTime : Date
69 payDate : Date
70 payDuration : Date
71 }
72
73 type House {
74 ownershipNumber : integer
75 location : String
76 area : integer
77 usage : String
78 price : Money
79 useRight : String
80 usufruct : String
81 dispositionRight : String
82 possessionRight : String
83 }
84 }
1 /* Houselease.sol */
2 pragma solidity ^0.4.0;
3
4 import "./RenterT.sol";
5 import "./TenantT.sol";
6
7 contract Houselease {
8
9 RenterT Renter;
10 TenantT Tenant;
11
12 House house;
13 contractInfo infos;
14
15 uint start;
16 struct contractInfo{
17 uint renterBail;
18 uint tenantBail;
19 uint rental;
20 uint totalRental;
21 uint penalty;
22 uint startLeasingTime;
23 uint endLeasingTime;
24 uint payDate;
25 uint payDuration;
26 }
27 struct House{
28 uint ownershipNumber;
29 bytes32 location;
30 uint area;
31 bytes32 usage;
32 uint price;
33 uint useRight;
34 uint usufruct;
35 uint dispositionRight;
36 uint possessionRight;
37 }
38
39 function Houselease(){
40 start = now;
41 Renter = new RenterT();
42 Tenant = new TenantT();
43 }
44
45 modifier onlyRenter{
46 require(Renter.contains(msg.sender));
47 _;
48 }
49
50 modifier onlyTenant{
51 require(Tenant.contains(msg.sender));
52 _;
53 }
54
55 modifier term2Modifier{
56 require(now > Renter.registerHouseTime());
57 require(infos.tenantBail > 0);
58 _;
59 }
60
61 modifier term3Modifier{
62 require((now > Tenant.confirmLeaseTime()) &&(now < Tenant.confirmLeaseTime()+604800));
63 require(house.useRight > 0);
64 _;
65 }
66
67 modifier term4Modifier{
68 require(now < Tenant.confirmLeaseTime());
69 require(infos.rental > 0);
70 _;
71 }
72
73 modifier term6Modifier{
74 require((now > Renter.checkHouseTime()) &&(now < Renter.checkHouseTime()+604800));
75 require(house.useRight > 0);
76 _;
77 }
78
79 modifier term7_1Modifier{
80 require((now > Renter.checkHouseTime()) &&(now < Renter.checkHouseTime()+1296000));
81 _;
82 }
83
84 modifier term7_2Modifier{
85 require((now > Renter.checkHouseTime()) &&(now < Renter.checkHouseTime()+1296000));
86 _;
87 }
88
89 function registerHouse() onlyRenter() public payable {
90 //USER CODE HERE
91 //CHECK
92
93 }
94
95 function confirmLease(uint endLeasingDuration, uint payDuration) onlyTenant() term2Modifier() public payable {
96 //USER CODE HERE
97 infos.startLeasingTime = now;
98 infos.endLeasingTime = endLeasingDuration + now;
99 infos.payDate = payDuration + now;
100 infos.payDuration = payDuration;
101 //CHECK
102 assert(infos.startLeasingTime == now && (infos.endLeasingTime == endLeasingDuration + now && (infos.payDate == payDuration + now && infos.payDuration == payDuration)));
103 }
104
105 function transferHouse() onlyRenter() term3Modifier() public payable {
106 //USER CODE HERE
107 //CHECK
108
109 }
110
111 function payRent() onlyTenant() term4Modifier() public payable {
112 //USER CODE HERE
113 infos.payDate = infos.payDate + infos.payDuration;
114 infos.totalRental = infos.totalRental + infos.rental;
115 msg.sender.transfer(house.useRight);
116 //CHECK
117 assert(infos.payDate == infos.payDate + infos.payDuration && infos.totalRental == infos.totalRental + infos.rental);
118 }
119
120 function collectRent() onlyRenter() term7_1Modifier() public payable {
121 //USER CODE HERE
122 infos.totalRental = 0;
123 msg.sender.transfer(infos.totalRental);
124 //CHECK
125 assert(infos.totalRental == 0);
126 }
127
128 function returnHouse() onlyTenant() term6Modifier() public payable {
129 //USER CODE HERE
130 address(Renter).transfer(house.useRight);
131 //CHECK
132
133 }
134
135 }
1 /* RenterT.sol */
2 pragma solidity ^0.4.22;
3
4 contract RenterT{
5
6
7 //attributes of actionregisterHouse
8 bool _isregisterHouseDone;
9 uint _registerHouseTime;
10
11 //attributes of actioncollectRent
12 bool _iscollectRentDone;
13 uint _collectRentTime;
14
15 //attributes of actioncollectBail
16 bool _iscollectBailDone;
17 uint _collectBailTime;
18
19 //attributes of actiontransferHouse
20 bool _istransferHouseDone;
21 uint _transferHouseTime;
22
23 //attributes of actioncheckHouse
24 bool _ischeckHouseDone;
25 uint _checkHouseTime;
26
27 uint _max;
28 bool _isRenterDone;
29 uint _i;
30
31 address[] _RenterAddress;
32 function RenterT(){
33 _max = now*1000;
34 }
35
36 function regist(address a) public {
37 _RenterAddress[_i] = a;
38 _i++;
39 }
40
41 function getAddress(uint _i) public returns (address a){
42 return _RenterAddress[_i];
43 }
44
45 function registerHouseDone(address a){
46 _registerHouseTime = now;
47 _isRenterDone = true;
48 }
49
50 function registerHouseTime() returns (uint result){
51 if(_isregisterHouseDone){
52 return _registerHouseTime;
53 }
54 return _max;
55 }
56
57 function collectRentDone(address a){
58 _collectRentTime = now;
59 _isRenterDone = true;
60 }
61
62 function collectRentTime() returns (uint result){
63 if(_iscollectRentDone){
64 return _collectRentTime;
65 }
66 return _max;
67 }
68
69 function collectBailDone(address a){
70 _collectBailTime = now;
71 _isRenterDone = true;
72 }
73
74 function collectBailTime() returns (uint result){
75 if(_iscollectBailDone){
76 return _collectBailTime;
77 }
78 return _max;
79 }
80
81 function transferHouseDone(address a){
82 _transferHouseTime = now;
83 _isRenterDone = true;
84 }
85
86 function transferHouseTime() returns (uint result){
87 if(_istransferHouseDone){
88 return _transferHouseTime;
89 }
90 return _max;
91 }
92
93 function checkHouseDone(address a){
94 _checkHouseTime = now;
95 _isRenterDone = true;
96 }
97
98 function checkHouseTime() returns (uint result){
99 if(_ischeckHouseDone){
100 return _checkHouseTime;
101 }
102 return _max;
103 }
104
105 function contains(address a) returns (bool result) {
106 for (uint _j = 0; _j < _RenterAddress.length; _j++ ) { //for loop example
107 if (a == _RenterAddress[_j]){
108 return true;
109 }
110 }
111 return false;
112 }
113
114 }
1 /* TenantT.sol */
2 pragma solidity ^0.4.22;
3
4 contract TenantT{
5
6
7 //attributes of actionconfirmLease
8 bool _isconfirmLeaseDone;
9 uint _confirmLeaseTime;
10
11 //attributes of actionpayRent
12 bool _ispayRentDone;
13 uint _payRentTime;
14
15 //attributes of actionreturnHouse
16 bool _isreturnHouseDone;
17 uint _returnHouseTime;
18
19 //attributes of actioncollectBail
20 bool _iscollectBailDone;
21 uint _collectBailTime;
22
23 uint _max;
24 bool _isTenantDone;
25 uint _i;
26
27 address[] _TenantAddress;
28 function TenantT(){
29 _max = now*1000;
30 }
31
32 function regist(address a) public {
33 _TenantAddress[_i] = a;
34 _i++;
35 }
36
37 function getAddress(uint _i) public returns (address a){
38 return _TenantAddress[_i];
39 }
40
41 function confirmLeaseDone(address a){
42 _confirmLeaseTime = now;
43 _isTenantDone = true;
44 }
45
46 function confirmLeaseTime() returns (uint result){
47 if(_isconfirmLeaseDone){
48 return _confirmLeaseTime;
49 }
50 return _max;
51 }
52
53 function payRentDone(address a){
54 _payRentTime = now;
55 _isTenantDone = true;
56 }
57
58 function payRentTime() returns (uint result){
59 if(_ispayRentDone){
60 return _payRentTime;
61 }
62 return _max;
63 }
64
65 function returnHouseDone(address a){
66 _returnHouseTime = now;
67 _isTenantDone = true;
68 }
69
70 function returnHouseTime() returns (uint result){
71 if(_isreturnHouseDone){
72 return _returnHouseTime;
73 }
74 return _max;
75 }
76
77 function collectBailDone(address a){
78 _collectBailTime = now;
79 _isTenantDone = true;
80 }
81
82 function collectBailTime() returns (uint result){
83 if(_iscollectBailDone){
84 return _collectBailTime;
85 }
86 return _max;
87 }
88
89 function contains(address a) returns (bool result) {
90 for (uint _j = 0; _j < _TenantAddress.length; _j++ ) { //for loop example
91 if (a == _TenantAddress[_j]){
92 return true;
93 }
94 }
95 return false;
96 }
97
98 }
(4)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. 1 // purchase.scs
2 contract Purchase{
3 party seller{
4 //定义seller角色,有四个动作
5 create()
6 abort()
7 confirmClaim()
8 autoConfirm()
9 }
10
11 party buyer{
12 confirmPurchase()//
13 confirmReceived()
14 overtimeClaim()
15 claim()
16 revokeClaim()
17 }
18
19 party logistics{
20 //第三方角色,物流公司
21 arrive()
22 }
23
24 balance : integer
25
26 xxxDescription : goods//定义一个商品描述,good是下面定义的商品结构体
27
28 term no1 : seller can create
29 while deposit $ xxxDescription::price*2.
30 //卖家可以创建合约,同时要存入物品两倍价格作为保证金
31
32 term no2 : buyer can confirmPurchase
33 when after seller did create
34 while deposit $ xxxDescription::price*2.
35 //买家创建合约后买家可以确认购买,同时要存入物品两倍价格作为保证金和货款
36
37 term no3 : seller can abort
38 when before buyer did confirmPurchase
39 while withdraw $ xxxDescription::price*2.
40 //卖家在买家确认购买之前,可以撤回合约,并取走两倍的保证金
41
42 term no4 : logistics must arrive
43 when within 10 day after buyer did confirmPurchase.
44 //买家付款后10天内必须到货
45
46 term no5 : buyer must confirmReceived
47 when within 7 day after logistics did arrive
48 while
49 withdraw $ xxxDescription::price
50 transfer $ balance to seller.
51 //买家在到货后7天内必须确认到货,同时双方取走保证金,卖家取走货款
52
53 term no6 : buyer can claim
54 when within 7 day after logistics did arrive.
55 //买家可以在到货7天内申请赔款
56
57 term no7 : buyer can overtimeClaim
58 when after start + 10 day or after logistics did arrive.
59 //如果货物在付款后10天内没到,买家可以申请赔款
60
61 term no8 : seller can confirmClaim
62 when after buyer did claim or after buyer did overtimeClaim
63 while transfer $ balance to buyer.
64 //卖家可以同意退款,并把所有保证金及货款转给买家
65
66 term no9 : buyer can revokeClaim
67 when after buyer did claim or after buyer did overtimeClaim
68 while
69 withdraw $ xxxDescription::price
70 transfer $ balance to seller.
71 //买家可以撤回退款申请
72
73 term no10 : seller can autoConfirm
74 when before buyer did claim and 7 day after logistics did arrive
75 while
76 withdraw $ xxxDescription::price
77 transfer $ balance to seller.
78 //如果到货七天内买家没有确认或申请退款,卖家可以自动确认到货。
79
80 type goods {
81 name : Name//物品名称
82 quantity : integer//物品数量
83 price : Money//价格
84 package : String//运送包装
85 }
86 }
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 }
|