Cron
Last updated
Was this helpful?
Last updated
Was this helpful?
Cron will be will determine the beginning or the end of a competition, and provide the current number of the competition. Its major purpose is to enable the generation of clock signals specified in natural language, rather than time intervals, to manage different bounty pools.This will enable to set Weekly, or Monthly competitions, always driven by the Gregorian calendar.
The Smart Contracts can be found , and below it is explained the basic behaviour to be used in other applications.
A common interface (IPeriod.sol
) is shared by every Smart Contract, where the following functions are implemented:
Function
Description
getLength() public view returns (uint256)
Returns the number of units per period
unit() public view returns (string)
Returns a string, specifying the type of unit used (eg: seconds, blocks)
height() public view returns (uint256)
Returns the current epoch (number of periods at the current timestamp)
heightOf(uint _timestamp)
Returns the height of a given timestamp
Implementing an internal clock compliant with IPeriod
can be done in an easy way, by deploying an IPeriod
contract and then linking it to your Smart Contract.
The following steps are required:
In order to enable granularity and capability to be shared among different Smart Contracts, every period (referenced in blocks, seconds or date format) is defined on a different Smart Contract instance. To include an internal clock into your Smart Contract instance, you will need to include an IPeriod
instance into your solidity code:
Now that you have your periodic contract deployed, you can lazily assign it to your Smart Contract. In case you're using truffle migrations, this could be done as follows:
Now, your can create periodic states from your initially deployed contract, by just mapping every variable to the height of the periodic contract, using period.height().
You will need now to deploy new periodic contract, compliant with the IPeriod
interface. Depending on your use case, you will need a different period instance. Today, the following types of period implementations are provided in the repo:
: A periodic Smart Contract, where a provided by constructor length (T) specified. Thus, every T blocks, height is incremented.
: Increments height()
every month (e.g January, February), since the deployment of the periodic Smart Contract
: Increments height()
every day (eg Monday, Tuesday), since the deployment of the periodic Smart Contract
: Increments height()
every year (e.g 2018, 2019), since the deployment of the periodic Smart Contract