0

I'm having trouble implementing a time out factor in my election. Lets say when the contract is deployed the timer kicks off, after the timer runs out the election ends and it announces the results of the election.

How can I generate reports in solidity?

2 Answers 2

0

You don't generate reports in Solidity.

What you'd usually do would be to have a closing time after which votes are no longer accepted, and have that time checked every time someone tries to vote. So as of the closing time, the state of the votes would be automatically locked.

To turn the final, locked state into a human-readable report would normally be the job of some external software that makes read requests to its node and formats those for humans. This is most commonly done in JavaScript, often using a tool like Truffle.

0

You have to invert the flow slightly because you can't just kick off a process when the deadline arrives.

You can (and should) restrict the voting to the period when the election is open. That is, don't allow any voting after the deadline. You can also return a bool to indicate open/closed status, so clients can know if the election is open or closed.

modifier onlyIfOpen {
  require(isOpen());
  _;
}

function isOpen() public view returns(bool isIndeed) {
  return now < deadlinel;
}

You can also optionally return a winner.

function blueTeamIsWinner() public view returns(bool isIndeed) {
  return blueCount > redCount;
}

Everything is predicated on the client inspecting the contract rather than launching a process on a schedule.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.