Created
February 14, 2023 17:31
-
-
Save mushketyk/22b4967be77d8388525f65a16bc52130 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.17+commit.8df45f5f.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; | |
// TODO: Add "onlyOwner" function modifier | |
constructor(string memory itemName_) { | |
owner = msg.sender; | |
itemName = itemName_; | |
} | |
// TODO: Replace "require" with a function modifier | |
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