implement block-timestamp-based (automatic) deadlines, replacing opening/closing feature
parent
bb84619a9a
commit
a9e5739f9f
|
@ -23,7 +23,7 @@ contract CryptoCTF10 {
|
||||||
}
|
}
|
||||||
|
|
||||||
modifier onlyOpen(uint contestID) {
|
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;
|
address admin;
|
||||||
mapping (uint => Challenge) challenges;
|
mapping (uint => Challenge) challenges;
|
||||||
mapping (address => Player) players;
|
mapping (address => Player) players;
|
||||||
bool submissionsOpen;
|
uint256 deadline;
|
||||||
mapping (address => mapping (uint => bool)) solves; // address -> challengeID -> solved/not
|
mapping (address => mapping (uint => bool)) solves; // address -> challengeID -> solved/not
|
||||||
mapping (uint => bool) anySolves; // challengeID -> solved/not
|
mapping (uint => bool) anySolves; // challengeID -> solved/not
|
||||||
string password;
|
string password;
|
||||||
|
@ -58,7 +58,6 @@ contract CryptoCTF10 {
|
||||||
function createContest(uint contestID, string memory password) external {
|
function createContest(uint contestID, string memory password) external {
|
||||||
require(contests[contestID].admin == address(0), "This contest ID has already been registered");
|
require(contests[contestID].admin == address(0), "This contest ID has already been registered");
|
||||||
contests[contestID].admin = msg.sender;
|
contests[contestID].admin = msg.sender;
|
||||||
contests[contestID].submissionsOpen = false;
|
|
||||||
contests[contestID].password = password;
|
contests[contestID].password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +66,8 @@ contract CryptoCTF10 {
|
||||||
contests[contestID].admin = newAdmin;
|
contests[contestID].admin = newAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSubmissionsStatus(uint contestID, bool open) external onlyExistingContest(contestID) onlyAdmin(contestID) {
|
function setContestDeadline(uint contestID, uint256 deadline) external onlyExistingContest(contestID) onlyAdmin(contestID) {
|
||||||
contests[contestID].submissionsOpen = open;
|
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) {
|
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) {
|
function getPlayerStatus(uint contestID, address player) external view onlyExistingContest(contestID) returns (PlayerStatus) {
|
||||||
return contests[contestID].players[player].status;
|
return contests[contestID].players[player].status;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue