implement block-timestamp-based (automatic) deadlines, replacing opening/closing feature

main
SI 2023-08-20 01:16:40 +00:00
parent bb84619a9a
commit a9e5739f9f
1 changed files with 8 additions and 5 deletions

View File

@ -23,7 +23,7 @@ contract CryptoCTF10 {
}
modifier onlyOpen(uint contestID) {
require(contests[contestID].submissionsOpen, "Submissions are not open for this contest at this time");
require(block.timestamp < contests[contestID].deadline, "Submissions are not open for this contest at this time");
_;
}
@ -44,7 +44,7 @@ contract CryptoCTF10 {
address admin;
mapping (uint => Challenge) challenges;
mapping (address => Player) players;
bool submissionsOpen;
uint256 deadline;
mapping (address => mapping (uint => bool)) solves; // address -> challengeID -> solved/not
mapping (uint => bool) anySolves; // challengeID -> solved/not
string password;
@ -58,7 +58,6 @@ contract CryptoCTF10 {
function createContest(uint contestID, string memory password) external {
require(contests[contestID].admin == address(0), "This contest ID has already been registered");
contests[contestID].admin = msg.sender;
contests[contestID].submissionsOpen = false;
contests[contestID].password = password;
}
@ -67,8 +66,8 @@ contract CryptoCTF10 {
contests[contestID].admin = newAdmin;
}
function setSubmissionsStatus(uint contestID, bool open) external onlyExistingContest(contestID) onlyAdmin(contestID) {
contests[contestID].submissionsOpen = open;
function setContestDeadline(uint contestID, uint256 deadline) external onlyExistingContest(contestID) onlyAdmin(contestID) {
contests[contestID].deadline = deadline;
}
function addOrUpdateChallenge(uint contestID, uint challengeID, address obscuredFlag, uint worth, uint256 descriptionFingerprint, bool onlyFirstSolver, string memory skill) external onlyExistingContest(contestID) onlyAdmin(contestID) {
@ -119,6 +118,10 @@ contract CryptoCTF10 {
}
}
function getContestDeadline(uint contestID) external view onlyExistingContest(contestID) returns (uint256) {
return contests[contestID].deadline;
}
function getPlayerStatus(uint contestID, address player) external view onlyExistingContest(contestID) returns (PlayerStatus) {
return contests[contestID].players[player].status;
}