Skip to content

Instantly share code, notes, and snippets.

@RomanFro
Last active October 18, 2018 10:36
Show Gist options
  • Save RomanFro/b8f938e8d35fa05b1f7af4fc9704dcf5 to your computer and use it in GitHub Desktop.
Save RomanFro/b8f938e8d35fa05b1f7af4fc9704dcf5 to your computer and use it in GitHub Desktop.
state_switcher
// Forecasting -> Forecasting finished
if (state === forecasting && forecastingEndTimestamp < block.timestamp) {
switch state -> forecasting_finished;
}
// Forecasting completed -> Crowdfunding deadline missed
if (state === forecasting_completed && forecastingEndTimestamp < (block.timestamp - secondsInDay * crowdsaleStartTimeout)) {
switch state -> crowdfunding_deadline_missed;
}
// Crowdfunding countdown -> Crowdfunding
if (state === crowdfunding_countdown && crowdsaleStartTimestamp < block.timestamp) {
switch state -> crowdfunding;
}
// Crowdfunding -> Crowdfunding Successful
if (state === crowdfunding && ((crowdsaleEndTimestamp < block.timestamp && totalCollected >= minimalGoal) || totalCollected >= hardCap)) {
switch state -> crowdfunding_successful;
update crowdsaleEndTimestamp;
}
// Crowdfunding -> Crowdfunding Failed
if (state === crowdfunding && crowdsaleEndTimestamp < block.timestamp && (totalCollected < minimalGoal || totalCollected === null)) {
switch state -> crowdfunding_failed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment