查看“ExampleofAuctionContract”的源代码
←
ExampleofAuctionContract
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
{{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 "> Auction contract </div> === {| class="wikitable" || 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. |} ---- ''' <font color=green>// Simple Auction.scs</font><br> <font color=blue>contract</font> SimpleAuction{<br> :<font color=blue>party</font> group bidders{<br> ::amount : Money<br> ::Bid()<br> ::withdrawOverbidMoney()<br> :} <br> :<font color=blue>party</font> auctioneer{<br> ::StartBidding(reservePrice : Money, biddingTime : Date)<br> ::StopBidding()<br> :} <br> :highestPrice : Money<br> :highestBidder : biddersBiddingStop<br> :Time : Date <br> :<font color=blue>term</font> no1 : auctioneer <font color=blue>can</font> StartBidding,<br> ::<font color=blue>when</font> <font color=blue>before</font> auctioneer <font color=blue>did</font> StartBidding<br> ::where highestPrice = reservePrice <font color=blue>and</font> BiddingStopTime = biddingTime + now. <br> :<font color=blue>term</font> no2 : bidders <font color=blue>can</font> Bid,<br> ::<font color=blue>when</font> <font color=blue>after</font> auctioneer <font color=blue>did</font> StartBidding <font color=blue>and</font> <font color=blue>before</font> BiddingStopTime<br> ::<font color=blue>while</font> deposit $ value > highestPrice<br> ::where highestPrice = value <font color=blue>and</font> highestBidder = <font color=blue>this</font> bidder <font color=blue>and</font><br> :::<font color=blue>this</font> bidder : : amount = <font color=blue>this</font> bidder: :0ri amount + value . <br> :<font color=blue>term</font> no3_1 : bidders <font color=blue>can</font> <font color=blue>withdraw</font>OverbidMoney,<br> ::<font color=blue>when</font> <font color=blue>this</font> bidder isn't highestBidder <font color=blue>and</font> <font color=blue>this</font> bidder: :amount > 0<br> ::<font color=blue>while</font> <font color=blue>withdraw</font> $<font color=blue>this</font> bidder : :amount<br> ::where <font color=blue>this</font> bidder : : amount = 0. <br> :<font color=blue>term</font> no3_2 : bidders <font color=blue>can</font> <font color=blue>withdraw</font>OverbidMoney,<br> ::<font color=blue>when</font> <font color=blue>this</font> bidder is highestBidder <font color=blue>and</font> <font color=blue>this</font> bidder : : amount > highestPrice<br> ::<font color=blue>while</font> <font color=blue>withdraw</font> $<font color=blue>this</font> bidder : : amount - highestPrice<br> ::where <font color=blue>this</font> bidder : : amount = highestPrice.<br> <br> :<font color=blue>term</font> no4 : auctioneer <font color=blue>can</font> StopBidding,<br> ::<font color=blue>when</font> <font color=blue>after</font> BiddingStopTime <font color=blue>and</font> <font color=blue>before</font> auctioneer <font color=blue>did</font> StopBidding<br> ::<font color=blue>while</font> <font color=blue>withdraw</font> $highestPrice.<br> } ''' '''<syntaxhighlight lang="spec" line="1"> /* auctioneerT.sol */ pragma solidity >=0.4.0 <0.6.0; contract auctioneerT{ //attributes of actionStartBidding bool _isStartBiddingDone; uint _StartBiddingTime; //attributes of actionCollectPayment bool _isCollectPaymentDone; uint _CollectPaymentTime; address _auctioneerAddress; uint _max; constructor() public{ _max = now*1000; } function regist(address a) public { _auctioneerAddress = a; } function getAddress() public returns (address a){ return _auctioneerAddress; } function StartBiddingDone() public{ _StartBiddingTime = now; _isStartBiddingDone = true; } function StartBiddingTime() public returns (uint result){ if(_isStartBiddingDone){ return _StartBiddingTime; } return _max; } function CollectPaymentDone() public{ _CollectPaymentTime = now; _isCollectPaymentDone = true; } function CollectPaymentTime() public returns (uint result){ if(_isCollectPaymentDone){ return _CollectPaymentTime; } return _max; } } </syntaxhighlight>''' '''<syntaxhighlight lang="spec" line="1"> /* biddersT.sol */ pragma solidity ^0.4.22; contract biddersT{ struct bidderstype{ uint amount; //attributes of actionBid bool _isBidDone; uint _BidTime; //attributes of actionWithdrawOverbidMoney bool _isWithdrawOverbidMoneyDone; uint _WithdrawOverbidMoneyTime; } uint _max;//time max uint _sum;//total member of this party uint _BidDoneNum; uint[] _BidTime; uint _WithdrawOverbidMoneyDoneNum; uint[] _WithdrawOverbidMoneyTime; bidderstype _Empty;//used to initialize bidderstype[] _biddersEntity; address[] _biddersAddress; mapping(address=>uint) _userlist; function biddersT(){ _BidDoneNum = 0; _WithdrawOverbidMoneyDoneNum = 0; _biddersEntity.push(_Empty); _max = now*1000; } function getSum() public returns(uint c){ return _sum; } function add(address a) public { _biddersEntity.push(_Empty); _biddersAddress.push(a); // _userlist[address] = _sum; _sum ++; } function remove(address a) public { uint num = _userlist[a]; _biddersEntity[num] = _biddersEntity[_sum-1]; delete(_biddersEntity[num]); delete(_userlist[a]); _sum --; } function getList() public returns (address[] a){ return _biddersAddress; } function contains(address a) public returns (bool b){ return _userlist[a] != 0; } function getamount(address a) returns(uint _result){ uint num = _userlist[a]; return _biddersEntity[num].amount; } function setamount(address a, uint b){ uint num = _userlist[a]; _biddersEntity[num].amount = b; } function BidDone(address a){ uint num = _userlist[a]; _biddersEntity[num]._BidTime = now; _biddersEntity[num]._isBidDone = true; _BidTime.push(_biddersEntity[num]._BidTime); _BidDoneNum ++; } function BidTime(address a) returns (uint result){ uint num = _userlist[a]; if(_biddersEntity[num]._isBidDone){ return _biddersEntity[num]._BidTime; } return _max; } function BidAllTime() returns (uint result){ if(_BidDoneNum == _max-1){ return _BidTime[_BidDoneNum-1]; } return _max; } function BidSomeTime() returns (uint result){ if(_BidDoneNum >= 1){ return _BidTime[0]; } return _max; } function WithdrawOverbidMoneyDone(address a){ uint num = _userlist[a]; _biddersEntity[num]._WithdrawOverbidMoneyTime = now; _biddersEntity[num]._isWithdrawOverbidMoneyDone = true; _WithdrawOverbidMoneyTime.push(_biddersEntity[num]._WithdrawOverbidMoneyTime); _WithdrawOverbidMoneyDoneNum ++; } function WithdrawOverbidMoneyTime(address a) returns (uint result){ uint num = _userlist[a]; if(_biddersEntity[num]._isWithdrawOverbidMoneyDone){ return _biddersEntity[num]._WithdrawOverbidMoneyTime; } return _max; } function WithdrawOverbidMoneyAllTime() returns (uint result){ if(_WithdrawOverbidMoneyDoneNum == _max-1){ return _WithdrawOverbidMoneyTime[_WithdrawOverbidMoneyDoneNum-1]; } return _max; } function WithdrawOverbidMoneySomeTime() returns (uint result){ if(_WithdrawOverbidMoneyDoneNum >= 1){ return _WithdrawOverbidMoneyTime[0]; } return _max; } } </syntaxhighlight>''' '''<syntaxhighlight lang="spec" line="1"> /* goodsOwnerT.sol */ pragma solidity ^0.4.22; contract goodsOwnerT{ //attributes of actionStartBidding bool _isStartBiddingDone; uint _StartBiddingTime; bool _isgoodsOwnerDone; uint _max; //attributes of actionStopBidding bool _isStopBiddingDone; uint _StopBiddingTime; address[] _goodsOwnerAddress; constructor() public{ _max = now*1000; } function regist (address[] a){ _goodsOwnerAddress = a; } function getAddress() public returns (address[] a){ return _goodsOwnerAddress; } function StartBiddingDone(address[] a){ // StartBiddingTime = now; _isgoodsOwnerDone = true; //_isStartBiddingDone = true; } function StartBiddingTime() returns (uint result){ if(_isStartBiddingDone){ return _StartBiddingTime; } return _max; } function StopBiddingDone(address[] a){ // StopBiddingTime = now; _isgoodsOwnerDone = true; // _StopBiddingTime = true; } function StopBiddingTime() returns (uint result){ if(_isStopBiddingDone){ return _StopBiddingTime; } return _max; } } </syntaxhighlight>''' '''<syntaxhighlight lang="spec" line="1"> /* SimpleAuction.sol */ pragma solidity ^0.4.22; contract SimpleAuction { address public beneficiary; uint public auctionEnd; address public highestBidder; uint public highestBid; mapping(address => uint) pendingReturns; bool ended; event HighestBidIncreased(address bidder, uint amount); event AuctionEnded(address winner, uint amount); constructor(uint _biddingTime, address _beneficiary) public { beneficiary = _beneficiary; auctionEnd = now + _biddingTime; } function bid() public payable { require(now <= auctionEnd, "Auction already ended."); require(msg.value > highestBid, "There already is a higher bid."); if (highestBid != 0) { pendingReturns[highestBidder] += highestBid; } highestBidder = msg.sender; highestBid = msg.value; HighestBidIncreased(msg.sender, msg.value); } function withdraw() public returns (bool) { uint amount = pendingReturns[msg.sender]; if (amount > 0) { pendingReturns[msg.sender] = 0; if (!msg.sender.send(amount)) { // No need to call throw here, just reset the amount owing pendingReturns[msg.sender] = amount; return false; } } return true; } function auctionEnd() public { require(now >= auctionEnd, "Auction not yet ended."); require(!ended, "auctionEnd has already been called."); ended = true; AuctionEnded(highestBidder, highestBid); beneficiary.transfer(highestBid); } } </syntaxhighlight>'''
返回至
ExampleofAuctionContract
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
crypto202
导航
智能合约
最近更改
SPESC
MediaWiki帮助
语言
智能法律合约
Smart Legal Contract
应用
公益遗嘱链
样例
智能法律合约样例
工具
链入页面
相关更改
特殊页面
页面信息