Created
March 26, 2023 21:31
-
-
Save mushketyk/3fa4dd9affa55de29fb5b1c55e368c57 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
import "Ownable.sol"; | |
contract Auction { | |
enum AuctionState { | |
INITIALIZED, | |
ONGOING, | |
FINISHED | |
} | |
address public beneficiary; | |
uint public deadline; | |
Ownable public ownable; | |
AuctionState public state = AuctionState.INITIALIZED; | |
modifier onlyState(AuctionState expectedState) { | |
require(state == expectedState, "Invalid state"); | |
_; | |
} | |
constructor(address ownableAddress) { | |
beneficiary = msg.sender; | |
ownable = Ownable(ownableAddress); | |
require(ownable.owner() == address(beneficiary), "Should be owned by the caller"); | |
} | |
function startAuction(uint duration) public onlyState(AuctionState.INITIALIZED) { | |
require(ownable.isOwner(), "Auction should be the owner"); | |
deadline = block.timestamp + duration; | |
state = AuctionState.ONGOING; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
contract Ownable { | |
address public owner; | |
string public itemName; | |
constructor(string memory itemName_) { | |
owner = msg.sender; | |
itemName = itemName_; | |
} | |
function transferOwnership(address newOwner) public { | |
require(isOwner(), "Not an owner"); | |
require(newOwner != address(0x0), "Invalid owner address"); | |
owner = newOwner; | |
} | |
function isOwner() public view returns(bool) { | |
return owner == msg.sender; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment