“ExampleofHouseLeasingContract”的版本间的差异
跳到导航
跳到搜索
| 第4行: | 第4行: | ||
|| 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. | ||
|} | |} | ||
| − | '''< | + | ---- |
| − | // HouseLease.scs | + | ''' |
| − | contract Houselease{ | + | <font color=green>// HouseLease.scs</font><br> |
| − | + | <font color=blue>contract</font> Houselease{<br> | |
| − | + | :<font color=blue>party</font> Renter{<br> | |
| − | + | ::registerHouse()<br> | |
| − | + | ::collectRent()<br> | |
| − | + | ::collectBail()<br> | |
| − | + | ::transferHouse()<br> | |
| − | + | ::checkHouse()<br> | |
| − | + | :} | |
| − | + | <br> | |
| − | + | :<font color=blue>party</font> Tenant{<br> | |
| − | + | ::confirmLease(endLeasingDuration:Date,<br> | |
| − | + | :::payDuration:Date)<br> | |
| − | + | ::payRent()<br> | |
| − | + | ::returnHouse()<br> | |
| − | + | ::collectBail()<br> | |
| − | + | :} | |
| − | + | <br> | |
| − | + | :house : House<br> | |
| − | + | :infos : contractInfo | |
| − | + | <br> | |
| − | + | :<font color=blue>term</font> <font color=blue>term</font>1 : Renter <font color=blue>can</font> registerHouse<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>deposit</font> $infos::renterBail. | |
| − | + | <br> | |
| − | + | :<font color=blue>term</font> <font color=blue>term</font>2 : Tenant <font color=blue>can</font> confirmLease<br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>after</font> Renter <font color=blue>did</font> registerHouse<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>deposit</font> $infos::tenantBail<br> | |
| − | + | ::<font color=blue>where</font> infos::startLeasingTime = now <font color=blue>and</font><br> | |
| − | + | :::infos::endLeasingTime = endLeasingDuration + now<br> | |
| − | + | :::<font color=blue>and</font> infos::payDate = payDuration + now<br> | |
| − | + | :::<font color=blue>and</font> infos::payDuration = payDuration. | |
| − | + | <br> | |
| − | + | :<font color=blue>term</font> <font color=blue>term</font>3 : Renter <font color=blue>must</font> transferHouse<br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>within</font> 7 <font color=blue>day</font> <font color=blue>after</font> Tenant <font color=blue>did</font> confirmLease<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>deposit</font> $ house::useRight. | |
| − | + | <br> | |
| − | + | :<font color=blue>term</font> <font color=blue>term</font>4 : Tenant <font color=blue>must</font> payRent<br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>before</font> Tenant <font color=blue>did</font> confirmLease<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>deposit</font> $infos::rental<br> | |
| − | + | :::<font color=blue>withdraw</font> $house::useRight<br> | |
| − | + | ::<font color=blue>where</font> infos::payDate = infos::payDate + infos::payDuration<br> | |
| − | + | :::<font color=blue>and</font> infos::totalRental = infos::totalRental + infos::rental. | |
| − | + | <br> | |
| − | + | :<font color=blue>term</font> <font color=blue>term</font>5 : Renter <font color=blue>can</font> collectRent<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>withdraw</font> $infos::totalRental<br> | |
| − | + | ::<font color=blue>where</font> infos::totalRental = 0. | |
| − | + | <br> | |
| − | + | :<font color=blue>term</font> <font color=blue>term</font>6 : Tenant <font color=blue>must</font> returnHouse<br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>within</font> 7 <font color=blue>day</font> <font color=blue>after</font> Renter <font color=blue>did</font> checkHouse<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>deposit</font> $house::useRight<br> | |
| − | + | :::transfer $house::useRight to Renter. | |
| − | + | <br> | |
| − | + | :<font color=blue>term</font> <font color=blue>term</font>7_1 : Renter <font color=blue>can</font> collectBail<br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>within</font> 15 <font color=blue>day</font> <font color=blue>after</font> Renter <font color=blue>did</font> checkHouse<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>withdraw</font> $infos::renterBail. | |
| − | + | <br> | |
| − | + | :<font color=blue>term</font> <font color=blue>term</font>7_2 : Tenant <font color=blue>can</font> collectBail<br> | |
| − | + | ::<font color=blue>when</font> <font color=blue>within</font> 15 <font color=blue>day</font> <font color=blue>after</font> Renter <font color=blue>did</font> checkHouse<br> | |
| − | + | ::<font color=blue>while</font> <font color=blue>withdraw</font> $infos::tenantBail. | |
| − | + | <br> | |
| − | + | :<font color=blue>type</font> contractInfo {<br> | |
| − | + | ::renterBail : Money<br> | |
| − | + | ::tenantBail : Money<br> | |
| − | + | ::rental : Money<br> | |
| − | + | ::totalRental : Money<br> | |
| − | + | ::penalty : Money<br> | |
| − | + | ::startLeasingTime : Date<br> | |
| − | + | ::endLeasingTime : Date<br> | |
| − | + | ::payDate : Date<br> | |
| − | + | ::payDuration : Date<br> | |
| − | + | :} | |
| − | + | <br> | |
| − | + | :<font color=blue>type</font> House {<br> | |
| − | + | ::ownershipNumber : integer<br> | |
| − | + | ::location : String<br> | |
| − | + | ::area : integer<br> | |
| − | + | ::usage : String<br> | |
| − | + | ::price : Money<br> | |
| − | + | ::useRight : String<br> | |
| − | + | ::usufruct : String<br> | |
| − | + | ::dispositionRight : String<br> | |
| − | + | ::possessionRight : String<br> | |
| + | :}<br> | ||
} | } | ||
| − | + | ''' | |
'''<syntaxhighlight lang="spec" line="1"> | '''<syntaxhighlight lang="spec" line="1"> | ||
/* Houselease.sol */ | /* Houselease.sol */ | ||
2021年9月12日 (日) 09:05的最新版本
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. |
// HouseLease.scs
contract Houselease{
- party Renter{
- registerHouse()
- collectRent()
- collectBail()
- transferHouse()
- checkHouse()
- registerHouse()
- }
- party Tenant{
- confirmLease(endLeasingDuration:Date,
- payDuration:Date)
- payDuration:Date)
- payRent()
- returnHouse()
- collectBail()
- confirmLease(endLeasingDuration:Date,
- }
- house : House
- infos : contractInfo
- term term1 : Renter can registerHouse
- while deposit $infos::renterBail.
- term term2 : Tenant can confirmLease
- when after Renter did registerHouse
- while deposit $infos::tenantBail
- where infos::startLeasingTime = now and
- infos::endLeasingTime = endLeasingDuration + now
- and infos::payDate = payDuration + now
- and infos::payDuration = payDuration.
- infos::endLeasingTime = endLeasingDuration + now
- when after Renter did registerHouse
- term term3 : Renter must transferHouse
- when within 7 day after Tenant did confirmLease
- while deposit $ house::useRight.
- when within 7 day after Tenant did confirmLease
- term term4 : Tenant must payRent
- when before Tenant did confirmLease
- while deposit $infos::rental
- withdraw $house::useRight
- withdraw $house::useRight
- where infos::payDate = infos::payDate + infos::payDuration
- and infos::totalRental = infos::totalRental + infos::rental.
- when before Tenant did confirmLease
- term term5 : Renter can collectRent
- while withdraw $infos::totalRental
- where infos::totalRental = 0.
- while withdraw $infos::totalRental
- term term6 : Tenant must returnHouse
- when within 7 day after Renter did checkHouse
- while deposit $house::useRight
- transfer $house::useRight to Renter.
- when within 7 day after Renter did checkHouse
- term term7_1 : Renter can collectBail
- when within 15 day after Renter did checkHouse
- while withdraw $infos::renterBail.
- when within 15 day after Renter did checkHouse
- term term7_2 : Tenant can collectBail
- when within 15 day after Renter did checkHouse
- while withdraw $infos::tenantBail.
- when within 15 day after Renter did checkHouse
- type contractInfo {
- renterBail : Money
- tenantBail : Money
- rental : Money
- totalRental : Money
- penalty : Money
- startLeasingTime : Date
- endLeasingTime : Date
- payDate : Date
- payDuration : Date
- renterBail : Money
- }
- type House {
- ownershipNumber : integer
- location : String
- area : integer
- usage : String
- price : Money
- useRight : String
- usufruct : String
- dispositionRight : String
- possessionRight : String
- ownershipNumber : integer
- }
}
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 }