查看“ExampleofPurchaseContract”的源代码
←
ExampleofPurchaseContract
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
{{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 "> Purchase contract </div> === {| 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. ---- ''' <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"> /* buyerT.sol */ pragma solidity ^0.4.22; contract buyerT{ //attributes of actionconfirmPurchase bool _isconfirmPurchaseDone; uint _confirmPurchaseTime; //attributes of actionconfirmReceived bool _isconfirmReceivedDone; uint _confirmReceivedTime; //attributes of actionovertimeClaim bool _isovertimeClaimDone; uint _overtimeClaimTime; //attributes of actionclaim bool _isclaimDone; uint _claimTime; //attributes of actionrevokeClaim bool _isrevokeClaimDone; uint _revokeClaimTime; uint _max; bool _isbuyerDone; uint _i = 0; address[] _buyerAddress; function buyerT(){ _max = now*1000; } function regist(address a) public { _buyerAddress[_i] = a; _i++; } function getAddress() public returns (address a){ return _buyerAddress[_i]; } function confirmPurchaseDone(address a){ _confirmPurchaseTime = now; _isbuyerDone = true; } function confirmPurchaseTime() returns (uint result){ if(_isconfirmPurchaseDone){ return _confirmPurchaseTime; } return _max; } function confirmReceivedDone(address a){ _confirmReceivedTime = now; _isbuyerDone = true; } function confirmReceivedTime() returns (uint result){ if(_isconfirmReceivedDone){ return _confirmReceivedTime; } return _max; } function overtimeClaimDone(address a){ _overtimeClaimTime = now; _isbuyerDone = true; } function overtimeClaimTime() returns (uint result){ if(_isovertimeClaimDone){ return _overtimeClaimTime; } return _max; } function claimDone(address a){ _claimTime = now; _isbuyerDone = true; } function claimTime() returns (uint result){ if(_isclaimDone){ return _claimTime; } return _max; } function revokeClaimDone(address a){ _revokeClaimTime = now; _isbuyerDone = true; } function revokeClaimTime() returns (uint result){ if(_isrevokeClaimDone){ return _revokeClaimTime; } return _max; } function contains(address a) returns (bool result) { for (uint _j = 0; _j < _buyerAddress.length; _j++ ) { //for loop example if (a == _buyerAddress[_j]){ return true; } } return false; } } </syntaxhighlight>''' '''<syntaxhighlight lang="spec" line="1"> /* logisticsT.sol */ pragma solidity ^0.4.22; contract logisticsT{ //attributes of actionarrive bool _isarriveDone; uint _arriveTime; uint _max; bool _islogisticsDone; uint _i = 0; address[] _logisticsAddress; function logisticsT(){ _max = now*1000; } function regist(address a) public { _logisticsAddress[_i] = a; } function getAddress() public returns (address a){ return _logisticsAddress[_i]; } function arriveDone(address a){ _arriveTime = now; _islogisticsDone = true; } function arriveTime() returns (uint result){ if(_isarriveDone){ return _arriveTime; } return _max; } function contains(address a) returns (bool result) { for (uint _j = 0; _j < _logisticsAddress.length; _j++ ) { //for loop example if (a == _logisticsAddress[_j]){ return true; } } return false; } } </syntaxhighlight>''' '''<syntaxhighlight lang="spec" line="1"> /* Purchase.sol */ pragma solidity ^0.4.0; import "./sellerT.sol"; import "./buyerT.sol"; import "./logisticsT.sol"; contract Purchase { sellerT seller; buyerT buyer; logisticsT logistics; uint balance; goods xxxDescription; uint start; struct goods{ bytes32 name; uint quantity; uint price; bytes32 package; } function Purchase(){ start = now; seller = new sellerT(); buyer = new buyerT(); logistics = new logisticsT(); } modifier onlyseller{ require(seller.contains(msg.sender)); _; } modifier onlybuyer{ require(buyer.contains(msg.sender)); _; } modifier onlylogistics{ require(logistics.contains(msg.sender)); _; } modifier no2Modifier{ require(now > seller.createTime()); require(xxxDescription.price * 2 > 0); _; } modifier no3Modifier{ require(now < buyer.confirmPurchaseTime()); _; } modifier no4Modifier{ require((now > buyer.confirmPurchaseTime()) &&(now < buyer.confirmPurchaseTime()+864000)); _; } modifier no5Modifier{ require((now > logistics.arriveTime()) &&(now < logistics.arriveTime()+604800)); _; } modifier no6Modifier{ require((now > logistics.arriveTime()) &&(now < logistics.arriveTime()+604800)); _; } modifier no7Modifier{ require(now > start + 864000 || now > logistics.arriveTime()); _; } modifier no8Modifier{ require(now > buyer.claimTime() || now > buyer.overtimeClaimTime()); _; } modifier no9Modifier{ require(now > buyer.claimTime() || now > buyer.overtimeClaimTime()); _; } modifier no10Modifier{ require(now < buyer.claimTime() && now > logistics.arriveTime()+604800); _; } function create() onlyseller() public payable { //USER CODE HERE //CHECK } function confirmPurchase() onlybuyer() no2Modifier() public payable { //USER CODE HERE //CHECK } function abort() onlyseller() no3Modifier() public payable { //USER CODE HERE msg.sender.transfer(xxxDescription.price * 2); //CHECK } function arrive() onlylogistics() no4Modifier() public { //USER CODE HERE //CHECK } function confirmReceived() onlybuyer() no5Modifier() public payable { //USER CODE HERE msg.sender.transfer(xxxDescription.price); address(seller).transfer(balance); //CHECK } function claim() onlybuyer() no6Modifier() public { //USER CODE HERE //CHECK } function overtimeClaim() onlybuyer() no7Modifier() public { //USER CODE HERE //CHECK } function confirmClaim() onlyseller() no8Modifier() public payable { //USER CODE HERE address(buyer).transfer(balance); //CHECK } function revokeClaim() onlybuyer() no9Modifier() public payable { //USER CODE HERE msg.sender.transfer(xxxDescription.price); address(seller).transfer(balance); //CHECK } function autoConfirm() onlyseller() no10Modifier() public payable { //USER CODE HERE msg.sender.transfer(xxxDescription.price); address(seller).transfer(balance); //CHECK } } </syntaxhighlight>''' '''<syntaxhighlight lang="spec" line="1"> /* sellerT.sol */ pragma solidity ^0.4.22; contract sellerT{ //attributes of actioncreate bool _iscreateDone; uint _createTime; //attributes of actionabort bool _isabortDone; uint _abortTime; //attributes of actionconfirmClaim bool _isconfirmClaimDone; uint _confirmClaimTime; //attributes of actionautoConfirm bool _isautoConfirmDone; uint _autoConfirmTime; uint _max; bool _issellerDone; uint _i = 0; address[] _sellerAddress; function sellerT(){ _max = now*1000; } function regist(address a) public { _sellerAddress[_i] = a; _i++; } function getAddress() public returns (address a){ return _sellerAddress[_i]; } function createDone(address a){ _createTime = now; _issellerDone = true; } function createTime() returns (uint result){ if(_iscreateDone){ return _createTime; } return _max; } function abortDone(address a){ _abortTime = now; _issellerDone = true; } function abortTime() returns (uint result){ if(_isabortDone){ return _abortTime; } return _max; } function confirmClaimDone(address a){ _confirmClaimTime = now; _issellerDone = true; } function confirmClaimTime() returns (uint result){ if(_isconfirmClaimDone){ return _confirmClaimTime; } return _max; } function autoConfirmDone(address a){ _autoConfirmTime = now; _issellerDone = true; } function autoConfirmTime() returns (uint result){ if(_isautoConfirmDone){ return _autoConfirmTime; } return _max; } function contains(address a) returns (bool result) { for (uint _j = 0; _j < _sellerAddress.length; _j++ ) { //for loop example if (a == _sellerAddress[_j]){ return true; } } return false; } } </syntaxhighlight>'''
返回至
ExampleofPurchaseContract
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
crypto202
导航
智能合约
最近更改
SPESC
MediaWiki帮助
语言
智能法律合约
Smart Legal Contract
应用
公益遗嘱链
样例
智能法律合约样例
工具
链入页面
相关更改
特殊页面
页面信息