adjust start_epoch and end_epoch calculation

This commit is contained in:
snogcel 2017-01-25 15:24:06 -07:00
parent 6649870039
commit 643eba11c2
2 changed files with 25 additions and 19 deletions

View file

@ -36,15 +36,17 @@
var socket;
var paymentCycle;
var mainnetProvider = 'https://dev-test.dash.org/';
var testnetProvider = 'https://dev-test.dash.org/';
var mainnetProvider = 'http://insight.dev.dash.org';
var mainnetPrefix = '/api';
var init = function(network, provider) {
var testnetProvider = 'http://test-insight.dev.dash.org';
var testnetPrefix = '/insight-api-dash';
var init = function(network, provider, prefix) {
var gov = new Bitcore.GovObject.Proposal();
gov.network = network || 'testnet';
paymentCycle = new PaymentCycle(gov, provider);
paymentCycle.updateDropdowns();
paymentCycle = new PaymentCycle(gov, provider, prefix);
socket = io(provider);
@ -77,10 +79,10 @@
$(document).ready(function() {
var gov = init('testnet', testnetProvider); // default network;
var gov = init('testnet', testnetProvider, testnetPrefix); // default network;
$('#mainnet').change(function() { gov = init('mainnet', mainnetProvider); });
$('#testnet').change(function() { gov = init('testnet', testnetProvider); });
$('#mainnet').change(function() { gov = init('mainnet', mainnetProvider, mainnetPrefix); });
$('#testnet').change(function() { gov = init('testnet', testnetProvider, testnetPrefix); });
$('#start_epoch').change(function() {
paymentCycle.selectedStartIndex = $('#start_epoch').find(':selected').data('index');

View file

@ -4,23 +4,24 @@
* @param gov
* @constructor
*/
function PaymentCycle(gov, provider) {
function PaymentCycle(gov, provider, prefix) {
var self = this;
this.network = gov.network;
this.provider = provider;
this.prefix = prefix;
this.paymentCycle = 16616;
this.proposalMaturity = 1662 + 10; // ~(60*24*3)/2.6 = about three days
this.proposalMaturity = 1662; // ~(60*24*3)/2.6 = about three days
this.budgetCycles = 24;
this.selectedStartIndex = 0;
this.selectedPeriods = 1;
if (this.network == 'testnet') this.paymentCycle = 23;
if (this.network == 'testnet') this.proposalMaturity = 24 + 1; // a little more than one hour
if (this.network == 'testnet') this.proposalMaturity = 24; // a little more than one hour
if (this.network == 'testnet') this.budgetCycles = 99;
this.blockHeight = null;
this.blockHeight = 0;
this.startDate = [];
this.endDate = [];
@ -43,9 +44,10 @@ function PaymentCycle(gov, provider) {
};
this.getInfo(function(err, res) {
console.log("current blockheight: " + res.info.blocks);
self.blockHeight = res.info.blocks;
console.log("current blockheight: " + self.blockHeight);
self.updateDropdowns();
});
}
@ -105,8 +107,10 @@ PaymentCycle.prototype.updateDropdowns = function() {
var superblock = this.getNextSuperblock(blockHeight);
var timestamp = this.getBlockTimestamp(superblock);
var before = this.getBlockTimestamp((superblock-this.proposalMaturity));
var after = this.getBlockTimestamp((superblock+(this.paymentCycle/2))); // set end_epoch to halfway after the last superblock
var before = this.getBlockTimestamp((superblock-(this.paymentCycle/2))); // set start_epoch to halfway before superblock
var after = this.getBlockTimestamp((superblock+(this.paymentCycle/2))); // set end_epoch to halfway after superblock
var votingDeadline = this.getBlockTimestamp((superblock-this.proposalMaturity)); // if superblock is within ~3 days skip to the next one
var label = new Date(timestamp).toLocaleDateString();
if (this.network == 'testnet') label += " @ " + new Date(timestamp).toLocaleTimeString();
@ -120,7 +124,7 @@ PaymentCycle.prototype.updateDropdowns = function() {
};
// include superblock if proposal maturity date is later than now
if (superblockDate.before > now) {
if (votingDeadline > now) {
this.startDate.push(superblockDate);
this.endDate.push(superblockDate);
}
@ -189,7 +193,7 @@ PaymentCycle.prototype.updateEndEpoch = function() {
};
PaymentCycle.prototype.getInfo = function(cb) {
$.getJSON(this.provider + "insight-api-dash/status?q=getinfo", function( data ) {
$.getJSON(this.provider + this.prefix + "/status?q=getinfo", function( data ) {
cb(null, data);
});
};