查看“ExampleofLoanContract”的源代码
←
ExampleofLoanContract
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:<span style="position: absolute; clip: rect(1px 1px 1px 1px); clip: rect(1px, 1px, 1px, 1px);">{{FULLPAGENAME}}</span>}} === <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> Loan contract </div> === {| class="wikitable" || 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. |} ---- ''' <font color=green>// Lend Spesc.scs</font><br> <font color=blue>contract</font> Lend{<br> :<font color=blue>party</font> User{<br> ::loan : Loan<br> ::SubmitLoanApplication(l : Loan)<br> ::confirm()<br> ::getHisLoan()<br> ::payback()<br> :} <br> :<font color=blue>party</font> Funder{<br> ::moneyFunded : Money<br> ::moneyWillGet : Money<br> ::Contribute(uid : User)<br> ::refund(uid : User)<br> :} <br> :<font color=blue>term</font> <font color=blue>term</font>1 : User <font color=blue>can</font> SubmitLoanApplication.<br> <br> :<font color=blue>term</font> <font color=blue>term</font>2 : Funder <font color=blue>can</font> Contribute <br> ::<font color=blue>when</font> <font color=blue>before</font> uid::loan::timelimit<br> ::<font color=blue>while</font> <font color=blue>deposit</font> $ value <= uid::loan::fundingGoal. <br> :<font color=blue>term</font> <font color=blue>term</font>3 : Funder <font color=blue>can</font> refund <br> ::<font color=blue>when</font> <font color=blue>after</font> uid::loan::timelimit <font color=blue>and</font> uid::loan::amount < uid::loan::fundingGoal<br> ::<font color=blue>while</font> <font color=blue>withdraw</font> $ his::moneyFunded. <br> :<font color=blue>term</font> <font color=blue>term</font>4 : User must confirm <br> ::<font color=blue>when</font> <font color=blue>within</font> 3 <font color=blue>day</font> <font color=blue>after</font> his::loan::timelimit <font color=blue>and</font> his::loan::amount = his::loan::fundingGoal. <br> :<font color=blue>term</font> <font color=blue>term</font>5 : User <font color=blue>can</font> getHisLoan <br> ::<font color=blue>when</font> <font color=blue>after</font> User <font color=blue>did</font> confirm <br> ::<font color=blue>while</font> <font color=blue>withdraw</font> $ his::loan::amount. <br> :<font color=blue>term</font> <font color=blue>term</font>6 : User must payback <br> ::<font color=blue>when</font> <font color=blue>after</font> User <font color=blue>did</font> confirm <font color=blue>and</font> <font color=blue>before</font> his::loan::tenorM<br> ::<font color=blue>while</font> <br> :::<font color=blue>deposit</font> $ his::loan::balance + his::loan::installment<br> :::<font color=blue>transfer</font> $ his::loan::funders::moneyWillGet <font color=blue>to</font> his::loan::funders. <br> :<font color=blue>type</font> Loan<br> :{<br> ::operationName : Name <font color=green>// use of money</font><br> ::beneficiary : User <font color=green>// Borrower</font><br> ::timelimit : Date <font color=green>// time limit of collecting money</font><br> ::fundingGoal : integer <font color=green>// the amount borrower want to borrow</font><br> ::amount : integer <font color=green>// the money collected now</font><br> ::balance : integer <font color=green>// the Capital have to pay back</font><br> ::numFunders : integer<br> ::interestRateM : integer <font color=green>// monthly</font><br> ::gracePeriod : integer <font color=green>// the period you don't have to pay the interest</font><br> ::tenorM : integer <font color=green>// you have to pay back tenorM month later</font><br> ::installment : integer <font color=green>// the interest have to pay back</font><br> ::funders : set Funder<br> :}<br> }''' '''<syntaxhighlight lang="spec" line="1"> /* FunderT.sol */ pragma solidity >=0.4.0 <0.6.0; contract FunderT{ uint moneyFunded; uint moneyWillGet; address _FunderAddress; uint _max; function funderT() public{ _max = now*1000; } function regist(address a) public { _FunderAddress = a; } function getAddress() public returns (address a){ return _FunderAddress; } function getmoneyFunded() public returns(uint _result){ return moneyFunded; } function setmoneyFunded ( uint a) public{ moneyFunded = a; } /* function getmoneyWillGet() public returns(uint _result){ return moneyWillGet; } function setmoneyWillGet(uint a) public { moneyWillGet = a; }*/ function setmoneyWillGet(uint256 newValue) public { moneyWillGet = newValue; } function getmoneyWillGet() public view returns (uint256) { return moneyWillGet; } } </syntaxhighlight>''' '''<syntaxhighlight lang="spec" line="1"> /* Lend.sol */ pragma solidity >=0.4.0 <0.6.0; pragma experimental ABIEncoderV2; import "./UserT.sol"; import "./FunderT.sol"; contract Lend { UserT User; FunderT Funder; uint start; mapping (string => Loan) loan; struct Loan{ bytes32 operationName; address beneficiary; uint timelimit; uint fundingGoal; uint amount; uint balance; uint numFunders; uint interestRateM; uint gracePeriod; uint tenorM; uint installment; address funders; } constructor() public{ start = now; User = new UserT(); Funder = new FunderT(); } /* constructor() public{ start = now; User = new UserT(); Funder = new FunderT(); }*/ modifier onlyUser{ require(User.getAddress()==msg.sender); _; } modifier onlyFunder{ require(Funder.getAddress()==msg.sender); _; } modifier term2Modifier(UserT uid){ // require(now < uid.loan.timelimit); // require(msg.value <= uid.loan.fundingGoal); _; } modifier term3Modifier(UserT uid){ // require(now > (uid.loan.timelimit && uid.loan.amount < uid.loan.fundingGoal)); _; } modifier term4Modifier{ // 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)); _; } modifier term5Modifier{ require(now > User.confirmTime()); _; } modifier term6Modifier{ // require(now > (User.confirmTime() && now < User.getloan.tenorM(msg.sender))); // require(User.getloan.balance(msg.sender) + User.getloan.installment(msg.sender)); _; } function SubmitLoanApplication( Loan memory l) onlyUser() public { //USER CODE HERE //CHECK } function Contribute(UserT uid) onlyFunder() term2Modifier(uid) public payable { //USER CODE HERE //CHECK } function refund(UserT uid) onlyFunder() term3Modifier(uid) public payable { //USER CODE HERE msg.sender.transfer(Funder.getmoneyFunded()); //CHECK } function confirm() onlyUser() term4Modifier() public { //USER CODE HERE //CHECK } function getHisLoan() onlyUser() term5Modifier() public payable { //USER CODE HERE msg.sender.transfer(User.getloan().amount); //CHECK } function payback() onlyUser() term6Modifier() public payable { //USER CODE HERE //User.getloan().funders.transfer(msg.sender); msg.sender.transfer(User.getloan().amount); //CHECK } } </syntaxhighlight>''' '''<syntaxhighlight lang="spec" line="1"> /* UserT.sol */ pragma solidity >=0.4.0 <0.6.0; pragma experimental ABIEncoderV2; import "./Lend.sol"; contract UserT{ struct Loan{ bytes32 operationName; address beneficiary; uint timelimit; uint fundingGoal; uint amount; uint balance; uint numFunders; uint interestRateM; uint gracePeriod; uint tenorM; uint installment; address funders; } Loan loan; //attributes of actionconfirm bool _isconfirmDone; uint _confirmTime; address _UserAddress; uint _max; constructor ()public{ _max = now*1000; } function regist(address a) public { _UserAddress = a; } function getAddress() public returns (address a){ return _UserAddress; } function getloan() public returns(Loan memory _result) { return loan; } function setloan(Loan memory a) public{ loan = a; } function confirmDone() public{ _confirmTime = now; _isconfirmDone = true; } function confirmTime() public returns (uint result){ if(_isconfirmDone){ return _confirmTime; } return _max; } } </syntaxhighlight>'''
返回至
ExampleofLoanContract
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
crypto202
导航
智能合约
最近更改
SPESC
MediaWiki帮助
语言
智能法律合约
Smart Legal Contract
应用
公益遗嘱链
样例
智能法律合约样例
工具
链入页面
相关更改
特殊页面
页面信息