1
1
// SPDX-License-Identifier: MIT
2
2
pragma solidity ^ 0.8.0 ;
3
3
4
- contract EnglishAuction {
4
+ import "@openzeppelin/contracts/token/ERC721/ERC721.sol " ;
5
+ import "@openzeppelin/contracts/access/Ownable.sol " ;
6
+
7
+ contract EnglishAuction is ERC721 , Ownable {
5
8
address payable public auctioneer;
6
9
uint256 public stblock; // start time
7
10
uint256 public etblock; // end time
@@ -12,6 +15,7 @@ contract EnglishAuction {
12
15
Ended,
13
16
Cancelled
14
17
}
18
+
15
19
Auc_state public auctionState;
16
20
17
21
uint256 public highestBid;
@@ -24,34 +28,29 @@ contract EnglishAuction {
24
28
25
29
event bidPlaced (address bidder , uint bidAmount );
26
30
27
- constructor () {
31
+ constructor (address initialOwner ) ERC721 ( " EnglishAuction " , " EA " ) Ownable (initialOwner ) {
28
32
auctioneer = payable (msg .sender );
29
33
auctionState = Auc_state.Running;
30
34
stblock = block .number ;
31
35
etblock = stblock + 240 ;
32
36
bidInc = 1 ether ;
33
37
}
34
38
35
-
36
-
37
39
modifier NotOwner () {
38
40
require (auctioneer != msg .sender );
39
41
_;
40
42
}
41
- modifier Owner () {
42
- require (auctioneer == msg .sender );
43
- _;
44
- }
43
+
45
44
modifier Start () {
46
45
require (block .number > stblock, "Not yet Started " );
47
46
_;
48
47
}
49
48
50
- function cancelAuc () public Owner {
49
+ function cancelAuc () public onlyOwner {
51
50
auctionState= Auc_state.Cancelled;
52
51
}
53
52
54
- function endAuc () public Owner {
53
+ function endAuc () public onlyOwner {
55
54
auctionState= Auc_state.Ended;
56
55
}
57
56
@@ -79,7 +78,6 @@ contract EnglishAuction {
79
78
}
80
79
81
80
emit bidPlaced (msg .sender , currentBid);
82
-
83
81
}
84
82
85
83
function finalizeAuc () public {
@@ -103,9 +101,7 @@ contract EnglishAuction {
103
101
person.transfer (value);
104
102
}
105
103
106
-
107
-
108
- function withdraw ()public {
104
+ function withdraw () public {
109
105
require (auctionState== Auc_state.Cancelled || auctionState== Auc_state.Ended || block .number > etblock, "Auction still running " );
110
106
require (bids[msg .sender ]> 0 , "Only bidders can withdraw " );
111
107
@@ -122,7 +118,14 @@ contract EnglishAuction {
122
118
}
123
119
bids[msg .sender ]= 0 ;
124
120
person.transfer (value);
125
- }
121
+ }
126
122
123
+ function mint (address to , uint256 tokenId ) public onlyOwner {
124
+ _mint (to, tokenId);
127
125
}
128
126
127
+ function transferNFT (address from , address to , uint256 tokenId ) public onlyOwner {
128
+ require (ownerOf (tokenId) == from, "You don't own this token " );
129
+ safeTransferFrom (from, to, tokenId);
130
+ }
131
+ }
0 commit comments