1+ pragma solidity ^ 0.4.22 ;
2+ pragma solidity 0.4.22 ;
3+ pragma experimental something;
4+
5+ import "a.sol " ;
6+ import {a,b} from "a.sol " ;
7+ import "./abc.sol " as x;
8+ import * as y from "./abc.sol " ;
9+ import {a as b, c as d, f} from "./abc.sol " ;
10+
11+ contract SimpleAuction {
12+ // Parameters of the auction. Times are either
13+ // absolute unix timestamps (seconds since 1970-01-01)
14+ // or time periods in seconds.
15+ address public beneficiary;
16+ uint public auctionEnd;
17+
18+
19+ // Current state of the auction.
20+ address public highestBidder;
21+ uint public highestBid;
22+
23+ // Allowed withdrawals of previous bids
24+ mapping (address => uint ) pendingReturns;
25+
26+ // Set to true at the end, disallows any change
27+ bool ended;
28+
29+ struct MyStructName {
30+ address addr;
31+ uint256 count;
32+ }
33+
34+
35+ MyStructName haha;
36+
37+ enum SomeData {DEFAULT,ONE,TWO}
38+ SomeData someData;
39+
40+ // Events that will be fired on changes.
41+ event HighestBidIncreased (address bidder , uint amount );
42+ event AuctionEnded (address winner , uint amount );
43+
44+ // The following is a so-called natspec comment,
45+ // recognizable by the three slashes.
46+ // It will be shown when the user is asked to
47+ // confirm a transaction.
48+
49+ /// Create a simple auction with `_biddingTime`
50+ /// seconds bidding time on behalf of the
51+ /// beneficiary address `_beneficiary`.
52+ constructor (
53+ uint _biddingTime ,
54+ address _beneficiary
55+ ) public {
56+ beneficiary = _beneficiary;
57+ auctionEnd = now + _biddingTime;
58+ }
59+
60+ function (uint a , uint b ) public {}
61+
62+ /// Bid on the auction with the value sent
63+ /// together with this transaction.
64+ /// The value will only be refunded if the
65+ /// auction is not won.
66+ function bid () public payable {
67+ // No arguments are necessary, all
68+ // information is already part of
69+ // the transaction. The keyword payable
70+ // is required for the function to
71+ // be able to receive Ether.
72+
73+ // Revert the call if the bidding
74+ // period is over.
75+ require (
76+ now <= auctionEnd,
77+ "Auction already ended. "
78+ );
79+
80+ // If the bid is not higher, send the
81+ // money back.
82+ require (
83+ msg .value > highestBid,
84+ "There already is a higher bid. "
85+ );
86+
87+ if (highestBid != 0 ) {
88+ // Sending back the money by simply using
89+ // highestBidder.send(highestBid) is a security risk
90+ // because it could execute an untrusted contract.
91+ // It is always safer to let the recipients
92+ // withdraw their money themselves.
93+ pendingReturns[highestBidder] += highestBid;
94+ }
95+ highestBidder = msg .sender ;
96+ highestBid = msg .value ;
97+ emit HighestBidIncreased (msg .sender , msg .value );
98+ }
99+
100+ /// Withdraw a bid that was overbid.
101+ function withdraw () public returns (bool ) {
102+ uint amount = pendingReturns[msg .sender ];
103+ if (amount > 0 ) {
104+ // It is important to set this to zero because the recipient
105+ // can call this function again as part of the receiving call
106+ // before `send` returns.
107+ pendingReturns[msg .sender ] = 0 ;
108+
109+ if (! msg .sender .send (amount)) {
110+ // No need to call throw here, just reset the amount owing
111+ pendingReturns[msg .sender ] = amount;
112+ return false ;
113+ }
114+ }
115+ return true ;
116+ }
117+
118+ modifier loli () {
119+
120+ }
121+
122+ function lol () public {
123+ return pendingReturns[msg .sender ];
124+ }
125+
126+ /// End the auction and send the highest bid
127+ /// to the beneficiary.
128+ function auctionEnd () public {
129+ // It is a good guideline to structure functions that interact
130+ // with other contracts (i.e. they call functions or send Ether)
131+ // into three phases:
132+ // 1. checking conditions
133+ // 2. performing actions (potentially changing conditions)
134+ // 3. interacting with other contracts
135+ // If these phases are mixed up, the other contract could call
136+ // back into the current contract and modify the state or cause
137+ // effects (ether payout) to be performed multiple times.
138+ // If functions called internally include interaction with external
139+ // contracts, they also have to be considered interaction with
140+ // external contracts.
141+
142+ // 1. Conditions
143+ require (now >= auctionEnd, "Auction not yet ended. " );
144+ require (! ended, "auctionEnd has already been called. " );
145+
146+ // 2. Effects
147+ ended = true ;
148+ emit AuctionEnded (highestBidder, highestBid);
149+
150+ // 3. Interaction
151+ beneficiary.transfer (highestBid);
152+ }
153+ }
0 commit comments