solidity-cron
Version:
[](https://travis-ci.com/Frontier-project/cron) [ • 275 kB
JSON
{
"contractName": "Period",
"abi": [
{
"constant": true,
"inputs": [],
"name": "age",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "T",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "blockOffset",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "isOwner",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "previousLength",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "epochOffset",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_T",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"constant": false,
"inputs": [
{
"name": "_T",
"type": "uint256"
}
],
"name": "setPeriodLength",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_T",
"type": "uint256"
}
],
"name": "hardAgeTransition",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getPeriodNumber",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getLength",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "height",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ageHeight",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getFirstEpochBlock",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getLastEpochBlock",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getRelativeIndex",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "isAgeTransition",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b50604051602080610abe83398101806040528101908080519060200190929190505050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600081111515610167576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600c8152602001807f454d5054595f504552494f44000000000000000000000000000000000000000081525060200191505060405180910390fd5b436004819055508060018190555050610939806101856000396000f300608060405260043610610107576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630ef267431461010c5780631c5633d714610137578063262a9dff146101645780632bc80f3a1461018f57806346bf6a55146101ba5780634c1ce7b4146101e55780634d3a67751461021057806355569a2f1461023b578063715018a61461026a578063731b3a03146102815780637fc15a2e146102ac5780638da5cb5b146102d75780638f32d59b1461032e578063a091fd6b1461035d578063b9f7fb291461038a578063be1c766b146103b5578063dd6239fc146103e0578063f2fde38b1461040b578063f866dd821461044e575b600080fd5b34801561011857600080fd5b50610121610479565b6040518082815260200191505060405180910390f35b34801561014357600080fd5b50610162600480360381019080803590602001909291905050506104b2565b005b34801561017057600080fd5b5061017961053d565b6040518082815260200191505060405180910390f35b34801561019b57600080fd5b506101a4610543565b6040518082815260200191505060405180910390f35b3480156101c657600080fd5b506101cf610549565b6040518082815260200191505060405180910390f35b3480156101f157600080fd5b506101fa61054f565b6040518082815260200191505060405180910390f35b34801561021c57600080fd5b50610225610580565b6040518082815260200191505060405180910390f35b34801561024757600080fd5b506102506105b3565b604051808215151515815260200191505060405180910390f35b34801561027657600080fd5b5061027f6105bf565b005b34801561028d57600080fd5b50610296610691565b6040518082815260200191505060405180910390f35b3480156102b857600080fd5b506102c16106ae565b6040518082815260200191505060405180910390f35b3480156102e357600080fd5b506102ec6106bd565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561033a57600080fd5b506103436106e6565b604051808215151515815260200191505060405180910390f35b34801561036957600080fd5b506103886004803603810190808035906020019092919050505061073d565b005b34801561039657600080fd5b5061039f6107b8565b6040518082815260200191505060405180910390f35b3480156103c157600080fd5b506103ca6107be565b6040518082815260200191505060405180910390f35b3480156103ec57600080fd5b506103f56107dd565b6040518082815260200191505060405180910390f35b34801561041757600080fd5b5061044c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506107ee565b005b34801561045a57600080fd5b5061046361080d565b6040518082815260200191505060405180910390f35b60006104836105b3565b156104925760055490506104af565b60025460055460015460045443038115156104a957fe5b04010190505b90565b60006104bc6106bd565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156104f557600080fd5b6104fd610479565b90506001610509610691565b0160048190555080600581905550600260008154809291906001019190505550600154600381905550816001819055505050565b60025481565b60015481565b60045481565b60006105596105b3565b1561056857600554905061057d565b600154600454430381151561057957fe5b0490505b90565b600061058a6105b3565b1561059d576003546004540390506105b0565b6001546105a861054f565b026004540190505b90565b60004360045411905090565b6105c76106e6565b15156105d257600080fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000600161069d6107dd565b6106a56107be565b43010303905090565b60006106b8610479565b905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b6107456106bd565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561077e57600080fd5b610786610479565b600581905550436004819055506002600081548092919060010191905055506001546003819055508060018190555050565b60035481565b60004360045411156107d45760035490506107da565b60015490505b90565b60006107e7610580565b4303905090565b6107f66106e6565b151561080157600080fd5b61080a81610813565b50565b60055481565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415151561084f57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505600a165627a7a7230582036336430d11e09bdd6c1a64b8bdc2dcb625a03cec66275202098348aa560ac050029",
"deployedBytecode": "0x608060405260043610610107576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630ef267431461010c5780631c5633d714610137578063262a9dff146101645780632bc80f3a1461018f57806346bf6a55146101ba5780634c1ce7b4146101e55780634d3a67751461021057806355569a2f1461023b578063715018a61461026a578063731b3a03146102815780637fc15a2e146102ac5780638da5cb5b146102d75780638f32d59b1461032e578063a091fd6b1461035d578063b9f7fb291461038a578063be1c766b146103b5578063dd6239fc146103e0578063f2fde38b1461040b578063f866dd821461044e575b600080fd5b34801561011857600080fd5b50610121610479565b6040518082815260200191505060405180910390f35b34801561014357600080fd5b50610162600480360381019080803590602001909291905050506104b2565b005b34801561017057600080fd5b5061017961053d565b6040518082815260200191505060405180910390f35b34801561019b57600080fd5b506101a4610543565b6040518082815260200191505060405180910390f35b3480156101c657600080fd5b506101cf610549565b6040518082815260200191505060405180910390f35b3480156101f157600080fd5b506101fa61054f565b6040518082815260200191505060405180910390f35b34801561021c57600080fd5b50610225610580565b6040518082815260200191505060405180910390f35b34801561024757600080fd5b506102506105b3565b604051808215151515815260200191505060405180910390f35b34801561027657600080fd5b5061027f6105bf565b005b34801561028d57600080fd5b50610296610691565b6040518082815260200191505060405180910390f35b3480156102b857600080fd5b506102c16106ae565b6040518082815260200191505060405180910390f35b3480156102e357600080fd5b506102ec6106bd565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561033a57600080fd5b506103436106e6565b604051808215151515815260200191505060405180910390f35b34801561036957600080fd5b506103886004803603810190808035906020019092919050505061073d565b005b34801561039657600080fd5b5061039f6107b8565b6040518082815260200191505060405180910390f35b3480156103c157600080fd5b506103ca6107be565b6040518082815260200191505060405180910390f35b3480156103ec57600080fd5b506103f56107dd565b6040518082815260200191505060405180910390f35b34801561041757600080fd5b5061044c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506107ee565b005b34801561045a57600080fd5b5061046361080d565b6040518082815260200191505060405180910390f35b60006104836105b3565b156104925760055490506104af565b60025460055460015460045443038115156104a957fe5b04010190505b90565b60006104bc6106bd565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156104f557600080fd5b6104fd610479565b90506001610509610691565b0160048190555080600581905550600260008154809291906001019190505550600154600381905550816001819055505050565b60025481565b60015481565b60045481565b60006105596105b3565b1561056857600554905061057d565b600154600454430381151561057957fe5b0490505b90565b600061058a6105b3565b1561059d576003546004540390506105b0565b6001546105a861054f565b026004540190505b90565b60004360045411905090565b6105c76106e6565b15156105d257600080fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000600161069d6107dd565b6106a56107be565b43010303905090565b60006106b8610479565b905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b6107456106bd565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561077e57600080fd5b610786610479565b600581905550436004819055506002600081548092919060010191905055506001546003819055508060018190555050565b60035481565b60004360045411156107d45760035490506107da565b60015490505b90565b60006107e7610580565b4303905090565b6107f66106e6565b151561080157600080fd5b61080a81610813565b50565b60055481565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415151561084f57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505600a165627a7a7230582036336430d11e09bdd6c1a64b8bdc2dcb625a03cec66275202098348aa560ac050029",
"sourceMap": "1830:4401:3:-;;;2378:131;8:9:-1;5:2;;;30:1;27;20:12;5:2;2378:131:3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;518:10:11;509:6;;:19;;;;;;;;;;;;;;;;;;572:6;;;;;;;;;;;539:40;;568:1;539:40;;;;;;;;;;;;2432:1:3;2427:2;:6;2419:31;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2474:12;2460:11;:26;;;;2500:2;2496:1;:6;;;;2378:131;1830:4401;;;;;;",
"deployedSourceMap": "1830:4401:3:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4515:291;;8:9:-1;5:2;;;30:1;27;20:12;5:2;4515:291:3;;;;;;;;;;;;;;;;;;;;;;;3145:269;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3145:269:3;;;;;;;;;;;;;;;;;;;;;;;;;;1986:18;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1986:18:3;;;;;;;;;;;;;;;;;;;;;;;1897:16;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1897:16:3;;;;;;;;;;;;;;;;;;;;;;;2163:26;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2163:26:3;;;;;;;;;;;;;;;;;;;;;;;4944:274;;8:9:-1;5:2;;;30:1;27;20:12;5:2;4944:274:3;;;;;;;;;;;;;;;;;;;;;;;5358:235;;8:9:-1;5:2;;;30:1;27;20:12;5:2;5358:235:3;;;;;;;;;;;;;;;;;;;;;;;6126:103;;8:9:-1;5:2;;;30:1;27;20:12;5:2;6126:103:3;;;;;;;;;;;;;;;;;;;;;;;;;;;1273:127:11;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1273:127:11;;;;;;5716:133:3;;8:9:-1;5:2;;;30:1;27;20:12;5:2;5716:133:3;;;;;;;;;;;;;;;;;;;;;;;3914:89;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3914:89:3;;;;;;;;;;;;;;;;;;;;;;;639:70:11;;8:9:-1;5:2;;;30:1;27;20:12;5:2;639:70:11;;;;;;;;;;;;;;;;;;;;;;;;;;;926:83;;8:9:-1;5:2;;;30:1;27;20:12;5:2;926:83:11;;;;;;;;;;;;;;;;;;;;;;;;;;;3587:221:3;;8:9:-1;5:2;;;30:1;27;20:12;5:2;3587:221:3;;;;;;;;;;;;;;;;;;;;;;;;;;2081:29;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2081:29:3;;;;;;;;;;;;;;;;;;;;;;;4108:255;;8:9:-1;5:2;;;30:1;27;20:12;5:2;4108:255:3;;;;;;;;;;;;;;;;;;;;;;;5917:117;;8:9:-1;5:2;;;30:1;27;20:12;5:2;5917:117:3;;;;;;;;;;;;;;;;;;;;;;;1561:101:11;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1561:101:11;;;;;;;;;;;;;;;;;;;;;;;;;;;;2228:26:3;;8:9:-1;5:2;;;30:1;27;20:12;5:2;2228:26:3;;;;;;;;;;;;;;;;;;;;;;;4515:291;4554:7;4577:17;:15;:17::i;:::-;4573:227;;;4660:11;;4653:18;;;;4573:227;4786:3;;4772:11;;4768:1;;4753:11;;4738:12;:26;4737:32;;;;;;;;:46;:52;4730:59;;4515:291;;:::o;3145:269::-;3239:17;3221:7;:5;:7::i;:::-;3207:21;;:10;:21;;;3199:30;;;;;;;;3259:8;:6;:8::i;:::-;3239:28;;3313:1;3291:19;:17;:19::i;:::-;:23;3277:11;:37;;;;3338:9;3324:11;:23;;;;3357:3;;:6;;;;;;;;;;;;;3390:1;;3373:14;:18;;;;3405:2;3401:1;:6;;;;3145:269;;:::o;1986:18::-;;;;:::o;1897:16::-;;;;:::o;2163:26::-;;;;:::o;4944:274::-;4986:7;5009:17;:15;:17::i;:::-;5005:207;;;5092:11;;5085:18;;;;5005:207;5200:1;;5185:11;;5170:12;:26;5169:32;;;;;;;;5162:39;;4944:274;;:::o;5358:235::-;5409:7;5432:17;:15;:17::i;:::-;5428:159;;;5486:14;;5472:11;;:28;5465:35;;;;5428:159;5575:1;;5561:11;:9;:11::i;:::-;:15;5547:11;;:29;5540:36;;5358:235;;:::o;6126:103::-;6174:4;6210:12;6196:11;;:26;6189:33;;6126:103;:::o;1273:127:11:-;824:9;:7;:9::i;:::-;816:18;;;;;;;;1367:1;1330:40;;1351:6;;;;;;;;;;;1330:40;;;;;;;;;;;;1393:1;1376:6;;:19;;;;;;;;;;;;;;;;;;1273:127::o;5716:133:3:-;5766:7;5841:1;5820:18;:16;:18::i;:::-;5806:11;:9;:11::i;:::-;5791:12;:26;:47;:51;5784:58;;5716:133;:::o;3914:89::-;3962:7;3988:8;:6;:8::i;:::-;3981:15;;3914:89;:::o;639:70:11:-;676:7;698:6;;;;;;;;;;;691:13;;639:70;:::o;926:83::-;965:4;998:6;;;;;;;;;;;984:20;;:10;:20;;;977:27;;926:83;:::o;3587:221:3:-;3665:7;:5;:7::i;:::-;3651:21;;:10;:21;;;3643:30;;;;;;;;3697:8;:6;:8::i;:::-;3683:11;:22;;;;3729:12;3715:11;:26;;;;3751:3;;:6;;;;;;;;;;;;;3784:1;;3767:14;:18;;;;3799:2;3795:1;:6;;;;3587:221;:::o;2081:29::-;;;;:::o;4108:255::-;4150:7;4187:12;4173:11;;:26;4169:188;;;4265:14;;4258:21;;;;4169:188;4345:1;;4338:8;;4108:255;;:::o;5917:117::-;5966:7;6007:20;:18;:20::i;:::-;5992:12;:35;5985:42;;5917:117;:::o;1561:101:11:-;824:9;:7;:9::i;:::-;816:18;;;;;;;;1629:28;1648:8;1629:18;:28::i;:::-;1561:101;:::o;2228:26:3:-;;;;:::o;1796:169:11:-;1885:1;1865:22;;:8;:22;;;;1857:31;;;;;;;;1928:8;1899:38;;1920:6;;;;;;;;;;;1899:38;;;;;;;;;;;;1952:8;1943:6;;:17;;;;;;;;;;;;;;;;;;1796:169;:::o",
"source": "pragma solidity 0.4.24;\n\nimport \"openzeppelin-solidity/contracts/math/SafeMath.sol\";\nimport \"openzeppelin-solidity/contracts/ownership/Ownable.sol\";\n\n\n\n/**\n* A periodic contract. Enables any contract to change state on a periodic basis.\n* Before going into code, it might be helpful to familiarize with the naming convention:\n* T ≡ Period Length --> Number of blocks to complete a cycle\n* Epoch: Counter of the number of cycles that went by since a given block (blockOffset)\n* Height == current epoch\n* Age: Time where Period Length has remained stable\n* BlockOffset --> First block inside an age \n* Epoch offset --> Starting value of height()\n\n\nHeight\n 9.00 ┼ ╭\n 8.00 ┤ ╭──╯\n 7.00 ┤ ╭──╯\n 6.00 ┤ ╭──╯\n 5.00 ┤ ╭──╯\n 4.00 ┤ ╭──╯\n 3.00 ┤ ╭──╯\n 2.00 ┤ ╭──╯ \n 1.00 ┤ ╭────╯ ^ \n 0.00 ┼────╯──────|─────────────────────── \n Block \n ^ T=3\n | \n \n T = 6\n \n <-------><----------------------->\n Age 1 Age 2\n\nThe contract was designed in order to be deterministic, so no need of state changes are required. Thus, most of the parameters are calculated via functions. \n\nThe exception comes when the owner (EOA, or Contract/DAO) decides to modify the period length. This is considered a breaking change in the behaviour, and the result is the transition to a new age.\n\n**/\n\n\ncontract Period is Ownable { \n\n // Current period length\n uint256 public T;\n\n // Number of changes that have been made to the period length\n uint256 public age;\n\n // Previous epoch's length, required for transitions between ages\n uint256 public previousLength;\n\n // Initial Block where an age has started\n uint256 public blockOffset;\n \n // Initial epoch offset\n uint256 public epochOffset;\n\n /*\n * Constructor\n * Creates a new Period object \n * @param _T Number of blocks of a Period\n */\n \n constructor(uint256 _T) public {\n require(_T > 0, 'EMPTY_PERIOD');\n blockOffset = block.number;\n T = _T;\n }\n\n /**\n * @dev Modifies the period length. \n * It was created with those use cases where a Smart Contract needs to modify the period length, keeping the same epoch numeration (height)\n * After this parameter is set, the flag isAgeTransition will turn to true()\n * After the current epoch ends (with previous length set) ends, it will start a new age.\n * To do that, it is modified the epoch offset, in order to allow future calculation of blocks\n * Also, it is calculated the new block offset, from the point where period will be applied. \n * @param _T The period lentgh to be applied to the new age\n */\n\n function setPeriodLength(uint256 _T) public {\n require(msg.sender == owner());\n uint256 tmpHeight = height();\n blockOffset = getLastEpochBlock() + 1;\n epochOffset = tmpHeight;\n age ++;\n previousLength = T;\n T = _T;\n }\n\n \n /**\n * @dev Forces a transition to a new Age without waiting for the transition time\n @ param _T The period lentgh to be applied to the new age\n */\n\n function hardAgeTransition(uint256 _T) public {\n require(msg.sender == owner());\n epochOffset = height();\n blockOffset = block.number;\n age ++;\n previousLength = T;\n T = _T;\n }\n\n\n /**\n * @dev Deprecated getter of the height number, now just pointing to height()\n */\n\n function getPeriodNumber() public view returns (uint256) {\n return height();\n }\n\n /**\n * @dev Deprecated getter of the height number, now just pointing to height()\n */\n\n function getLength() public view returns (uint256) {\n if (blockOffset > block.number) { // Period has been scheduled or modified. \n return previousLength;\n }\n else { // Normal behaviour\n return T;\n }\n }\n\n /**\n * @dev Getter for the total height included in this periodic contract, including age transitions\n * @return current height\n */\n\n function height() public view returns (uint256) {\n if (isAgeTransition()) { // Period has been scheduled or modified. \n return epochOffset;\n }\n else { // Normal behaviour\n return (block.number - blockOffset) / T + epochOffset + age;\n }\n }\n\n /**\n * @dev Returns the height inside the current age\n * @return height (number of epochs) inside the current age\n */\n\n function ageHeight() public view returns (uint256) {\n if (isAgeTransition()) { // Period has been scheduled or modified. \n return epochOffset;\n }\n else { // Normal behaviour\n return (block.number - blockOffset) / T;\n }\n }\n\n /**\n * @dev Calculates and returns the first block of the current epoch\n * @return First block of the current epoch\n */\n\n function getFirstEpochBlock() public view returns (uint256) {\n if (isAgeTransition()) {\n return blockOffset - previousLength;\n }\n else { \n return blockOffset + ageHeight() * T;\n }\n }\n\n /**\n * @dev Returns the last block in the current epoch\n * @return Last block of the current epoch\n */\n\n function getLastEpochBlock() public view returns (uint256){\n return block.number + getLength() - getRelativeIndex() - 1;\n }\n\n /*\n * @return Index inside the current epoch. \n */\n\n function getRelativeIndex() public view returns (uint256) {\n return block.number - getFirstEpochBlock();\n }\n \n /**\n * @dev Condition to check if an age transition is in progress\n */\n\n function isAgeTransition() public view returns (bool){\n return blockOffset > block.number;\n }\n}",
"sourcePath": "/Users/carlosbuendia/Documents/Projects/consensys/Frontier/cron/contracts/blocks/Period.sol",
"ast": {
"absolutePath": "/Users/carlosbuendia/Documents/Projects/consensys/Frontier/cron/contracts/blocks/Period.sol",
"exportedSymbols": {
"Period": [
364
]
},
"id": 365,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 117,
"literals": [
"solidity",
"0.4",
".24"
],
"nodeType": "PragmaDirective",
"src": "0:23:3"
},
{
"absolutePath": "openzeppelin-solidity/contracts/math/SafeMath.sol",
"file": "openzeppelin-solidity/contracts/math/SafeMath.sol",
"id": 118,
"nodeType": "ImportDirective",
"scope": 365,
"sourceUnit": 1861,
"src": "25:59:3",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "openzeppelin-solidity/contracts/ownership/Ownable.sol",
"file": "openzeppelin-solidity/contracts/ownership/Ownable.sol",
"id": 119,
"nodeType": "ImportDirective",
"scope": 365,
"sourceUnit": 1970,
"src": "85:63:3",
"symbolAliases": [],
"unitAlias": ""
},
{
"baseContracts": [
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 120,
"name": "Ownable",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 1969,
"src": "1849:7:3",
"typeDescriptions": {
"typeIdentifier": "t_contract$_Ownable_$1969",
"typeString": "contract Ownable"
}
},
"id": 121,
"nodeType": "InheritanceSpecifier",
"src": "1849:7:3"
}
],
"contractDependencies": [
1969
],
"contractKind": "contract",
"documentation": " A periodic contract. Enables any contract to change state on a periodic basis.\n Before going into code, it might be helpful to familiarize with the naming convention:\n T ≡ Period Length --> Number of blocks to complete a cycle\n Epoch: Counter of the number of cycles that went by since a given block (blockOffset)\n Height == current epoch\n Age: Time where Period Length has remained stable\n BlockOffset --> First block inside an age \n Epoch offset --> Starting value of height()\nHeight\n9.00 ┼ ╭\n8.00 ┤ ╭──╯\n7.00 ┤ ╭──╯\n6.00 ┤ ╭──╯\n5.00 ┤ ╭──╯\n4.00 ┤ ╭──╯\n3.00 ┤ ╭──╯\n2.00 ┤ ╭──╯ \n1.00 ┤ ╭────╯ ^ \n0.00 ┼────╯──────|─────────────────────── \nBlock \n^ T=3\n| \nT = 6\n<-------><----------------------->\nAge 1 Age 2\nThe contract was designed in order to be deterministic, so no need of state changes are required. Thus, most of the parameters are calculated via functions. \nThe exception comes when the owner (EOA, or Contract/DAO) decides to modify the period length. This is considered a breaking change in the behaviour, and the result is the transition to a new age.*",
"fullyImplemented": true,
"id": 364,
"linearizedBaseContracts": [
364,
1969
],
"name": "Period",
"nodeType": "ContractDefinition",
"nodes": [
{
"constant": false,
"id": 123,
"name": "T",
"nodeType": "VariableDeclaration",
"scope": 364,
"src": "1897:16:3",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 122,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1897:7:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "public"
},
{
"constant": false,
"id": 125,
"name": "age",
"nodeType": "VariableDeclaration",
"scope": 364,
"src": "1986:18:3",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 124,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1986:7:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "public"
},
{
"constant": false,
"id": 127,
"name": "previousLength",
"nodeType": "VariableDeclaration",
"scope": 364,
"src": "2081:29:3",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 126,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "2081:7:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "public"
},
{
"constant": false,
"id": 129,
"name": "blockOffset",
"nodeType": "VariableDeclaration",
"scope": 364,
"src": "2163:26:3",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 128,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "2163:7:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "public"
},
{
"constant": false,
"id": 131,
"name": "epochOffset",
"nodeType": "VariableDeclaration",
"scope": 364,
"src": "2228:26:3",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 130,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "2228:7:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "public"
},
{
"body": {
"id": 152,
"nodeType": "Block",
"src": "2409:100:3",
"statements": [
{
"expression": {
"argumentTypes": null,
"arguments": [
{
"argumentTypes": null,
"commonType": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"id": 139,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftExpression": {
"argumentTypes": null,
"id": 137,
"name": "_T",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 133,
"src": "2427:2:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"nodeType": "BinaryOperation",
"operator": ">",
"rightExpression": {
"argumentTypes": null,
"hexValue": "30",
"id": 138,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "2432:1:3",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_0_by_1",
"typeString": "int_const 0"
},
"value": "0"
},
"src": "2427:6:3",
"typeDescriptions": {
"typeIdentifier": "t_bool",
"typeString": "bool"
}
},
{
"argumentTypes": null,
"hexValue": "454d5054595f504552494f44",
"id": 140,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "string",
"lValueRequested": false,
"nodeType": "Literal",
"src": "2435:14:3",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_stringliteral_4f8281f0537e0ef0f7dd16395f7d3fad5d747cff14b0600828f0b836854eecef",
"typeString": "literal_string \"EMPTY_PERIOD\""
},
"value": "EMPTY_PERIOD"
}
],
"expression": {
"argumentTypes": [
{
"typeIdentifier": "t_bool",
"typeString": "bool"
},
{
"typeIdentifier": "t_stringliteral_4f8281f0537e0ef0f7dd16395f7d3fad5d747cff14b0600828f0b836854eecef",
"typeString": "literal_string \"EMPTY_PERIOD\""
}
],
"id": 136,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
1987,
1988
],
"referencedDeclaration": 1988,
"src": "2419:7:3",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$",
"typeString": "function (bool,string memory) pure"
}
},
"id": 141,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "2419:31:3",
"typeDescriptions": {
"typeIdentifier": "t_tuple$__$",
"typeString": "tuple()"
}
},
"id": 142,
"nodeType": "ExpressionStatement",
"src": "2419:31:3"
},
{
"expression": {
"argumentTypes": null,
"id": 146,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftHandSide": {
"argumentTypes": null,
"id": 143,
"name": "blockOffset",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 129,
"src": "2460:11:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"nodeType": "Assignment",
"operator": "=",
"rightHandSide": {
"argumentTypes": null,
"expression": {
"argumentTypes": null,
"id": 144,
"name": "block",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 1974,
"src": "2474:5:3",
"typeDescriptions": {
"typeIdentifier": "t_magic_block",
"typeString": "block"
}
},
"id": 145,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "number",
"nodeType": "MemberAccess",
"referencedDeclaration": null,
"src": "2474:12:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"src": "2460:26:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"id": 147,
"nodeType": "ExpressionStatement",
"src": "2460:26:3"
},
{
"expression": {
"argumentTypes": null,
"id": 150,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftHandSide": {
"argumentTypes": null,
"id": 148,
"name": "T",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 123,
"src": "2496:1:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"nodeType": "Assignment",
"operator": "=",
"rightHandSide": {
"argumentTypes": null,
"id": 149,
"name": "_T",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 133,
"src": "2500:2:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"src": "2496:6:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"id": 151,
"nodeType": "ExpressionStatement",
"src": "2496:6:3"
}
]
},
"documentation": null,
"id": 153,
"implemented": true,
"isConstructor": true,
"isDeclaredConst": false,
"modifiers": [],
"name": "",
"nodeType": "FunctionDefinition",
"parameters": {
"id": 134,
"nodeType": "ParameterList",
"parameters": [
{
"constant": false,
"id": 133,
"name": "_T",
"nodeType": "VariableDeclaration",
"scope": 153,
"src": "2390:10:3",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 132,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "2390:7:3",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
}
],
"src": "2389:12:3"
},
"payable": false,
"returnParameters": {
"id": 135,
"nodeType": "ParameterList",
"parameters": [],
"src": "2409:0:3"
},
"scope": 364,
"src": "2378:131:3",
"stateMutability": "nonpayable",
"superFunction": null,
"visibility": "public"
},
{
"body": {
"id": 193,
"nodeType": "Block",
"src": "3189:225:3",
"statements": [
{
"expression": {
"argumentTypes": null,
"arguments": [
{
"argumentTypes": null,
"commonType": {
"typeIdentifier": "t_address",
"typeString": "address"
},
"id": 163,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftExpression": {
"argumentTypes": null,
"expression": {
"argumentTypes": null,
"id": 159,
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 1984,
"src": "3207:3:3",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
"typeString": "msg"
}
},
"id": 160,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberName": "sender",
"nodeType": "MemberAccess",
"referencedDeclaration": null,
"src": "3207:10:3",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"nodeType": "BinaryOperation",
"operator": "==",
"rightExpression": {
"argumentTypes": null,
"arguments": [],
"expression": {
"argumentTypes": [],
"id": 161,
"name": "owner",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 1894,
"src": "3221:5:3",
"typeDescriptions": {
"typeIdentifier": "t_function_internal_view$__$returns$_t_address_$",
"typeString": "function () view returns (address)"
}
},
"id": 162,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "3221:7:3",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"src": "3207:21:3",
"typeDescriptions": {
"typeIdentifier": "t_bool",
"typeString": "bool"
}
}
],
"expression": {
"argumentTypes": [
{
"typeIdentifier": "t_bool",
"typeString": "bool"
}
],
"id": 158,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
1987,
1988
],
"referencedDeclaration": 1987,
"src": "3199:7:3",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
"typeString": "function (bool) pure"
}
},
"id": 164,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",