mirror of
https://github.com/seigler/govobject-proposal
synced 2025-07-27 06:46:10 +00:00
866 lines
40 KiB
HTML
866 lines
40 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Dash Governance Tools</title>
|
|
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
|
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/themes/smoothness/jquery-ui.css">
|
|
<link rel="stylesheet" href="css/master.css">
|
|
|
|
<script src="https://code.jquery.com/jquery-3.1.0.js" integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk=" crossorigin="anonymous"></script>
|
|
<script src="https://use.fontawesome.com/f0153b9f7b.js"></script>
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
|
|
<script src="bitcore-lib-dash.js"></script>
|
|
|
|
<script src="https://dev-test.dash.org:3001/socket.io/socket.io.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
var Bitcore = require('bitcore-lib-dash');
|
|
|
|
var apiserversocket = 'https://dev-test.dash.org:3001/';
|
|
|
|
var bufferdays = 3; //number of days to have as buffer for proposal start date before jumping to next month
|
|
|
|
var blockheight;
|
|
|
|
var progresstxt = "As of yet your transaction has 0 confirmations. We'll wait for 6 confirmations until you can submit your proposal. Waiting for new blocks to confirm...";
|
|
|
|
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
var gov = new Bitcore.GovObject.Proposal();
|
|
|
|
gov.network = 'testnet';
|
|
|
|
var cycle = new PaymentCycle(gov);
|
|
|
|
|
|
$("#time").val(Math.floor((new Date).getTime() / 1000));
|
|
|
|
cycle.updateDropdowns(); // update dropdown menus based on network and current time
|
|
|
|
// prepareTime(gov);
|
|
|
|
|
|
$("#progresstxt").text(progresstxt);
|
|
|
|
$('#prepareProposal').click(function() {
|
|
copyToClipboard($(this).attr('id'));
|
|
});
|
|
|
|
$('#submitProposal').click(function() {
|
|
copyToClipboard($(this).attr('id'));
|
|
});
|
|
|
|
$('#feeTxid').focus(function() {
|
|
if ($(this).hasClass('validationError')) {
|
|
$(this).val('');
|
|
}
|
|
$(this).removeClass('validationError');
|
|
});
|
|
|
|
$('.createProposal input').focus(function() {
|
|
if ($(this).hasClass('validationError')) {
|
|
$(this).val('');
|
|
}
|
|
$(this).removeClass('validationError');
|
|
});
|
|
|
|
$('#btnPrepare').click(function() {
|
|
|
|
var proposal = new ProposalGenerator(gov);
|
|
|
|
var validProposal = proposal.validate();
|
|
|
|
if (validProposal) {
|
|
|
|
proposal.walletCommands();
|
|
|
|
proposal.transactionListener(proposal);
|
|
|
|
$('#btnEdit').click(function() {
|
|
proposal.createProposal();
|
|
});
|
|
|
|
$('#btnNew').click(function() {
|
|
proposal.resetProposal();
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
var ProposalGenerator = function(gov) {
|
|
this._mode = 'proposal';
|
|
if(!gov.network) gov.network = 'livenet';
|
|
|
|
this.gov = gov;
|
|
|
|
// proposal basic fields
|
|
this.gov.name = $('#name').val();
|
|
this.gov.url = $('#url').val();
|
|
this.gov.payment_address = $('#payment_address').val();
|
|
this.gov.payment_amount = parseFloat($('#payment_amount').val());
|
|
this.gov.start_epoch = $('#start_epoch').val();
|
|
this.gov.end_epoch = $('#end_epoch').val();
|
|
|
|
// hidden elements
|
|
this.gov.type = parseInt($('#type').val());
|
|
};
|
|
|
|
ProposalGenerator.prototype.validate = function() {
|
|
try {
|
|
var gov = this.gov.serialize();
|
|
}
|
|
catch (e) {
|
|
|
|
switch(e.message) {
|
|
|
|
case 'Invalid Name':
|
|
console.log("error: invalid name");
|
|
$('#name').addClass('validationError');
|
|
$('#name').val("Invalid name. Please enter a name without spaces and weird characters. E.g. can use a '-' or '_' instead of a space.");
|
|
break;
|
|
|
|
case 'Invalid URL':
|
|
console.log("Error: invalid url");
|
|
$('#url').addClass('validationError');
|
|
$('#url').val("There is a formatting error in your URL. Did you forget the leading 'http://'?");
|
|
break;
|
|
|
|
case 'Invalid Payment Amount':
|
|
console.log("Error: invalid payment amount");
|
|
$('#payment_amount').addClass('validationError');
|
|
$('#payment_amount').val("Invalid payment amount. Please enter a number from 1 - 7500");
|
|
break;
|
|
|
|
case 'Invalid Timespan':
|
|
console.log("Error: invalid timespan");
|
|
$('#start_epoch, #end_epoch').addClass('validationError');
|
|
break;
|
|
|
|
case 'Invalid Start Date':
|
|
console.log("Error: invalid start date");
|
|
$('#start_epoch').addClass('validationError');
|
|
break;
|
|
|
|
case 'Invalid End Date':
|
|
console.log("Error: invalid end date");
|
|
$('#end_epoch').addClass('validationError');
|
|
break;
|
|
|
|
case 'Invalid Address':
|
|
console.log("Error: invalid address");
|
|
$('#payment_address').addClass('validationError');
|
|
$('#payment_address').val("Invalid Dash Address. Please just copy & paste from wallet.");
|
|
break;
|
|
|
|
default:
|
|
console.log(e);
|
|
break;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
ProposalGenerator.prototype.walletCommands = function() {
|
|
var gov = this.gov;
|
|
|
|
var prepCommand = "gobject prepare "+$('#parentHash').val() + " " + $('#revision').val() +" " + $('#time').val() +" " + gov.serialize();
|
|
console.log(prepCommand);
|
|
$("textarea#prepareProposal").val(prepCommand);
|
|
|
|
if(this._mode == 'proposal') {
|
|
setFormEditable(true);
|
|
|
|
$('.walletCommands#walletCommandsHeader').removeClass('hidden');
|
|
$('.walletCommands#walletCommandsPrepare').removeClass('hidden');
|
|
$('.walletCommands#walletCommandsTx').removeClass('hidden');
|
|
//$('.walletCommands#walletCommandsProgress').removeClass('hidden');
|
|
//$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
|
|
|
|
this._mode = 'command';
|
|
}
|
|
};
|
|
|
|
ProposalGenerator.prototype.createProposal = function() {
|
|
$('#feeTxid').val("");
|
|
$('#submitProposal').val("");
|
|
|
|
if(this._mode == 'command') {
|
|
setFormEditable(false);
|
|
|
|
$('.walletCommands#walletCommandsHeader').addClass('hidden');
|
|
$('.walletCommands#walletCommandsPrepare').addClass('hidden');
|
|
$('.walletCommands#walletCommandsTx').addClass('hidden');
|
|
$('.walletCommands#walletCommandsProgress').addClass('hidden');
|
|
$('.walletCommands#walletCommandsSubmit').addClass('hidden');
|
|
|
|
this._mode = 'proposal';
|
|
}
|
|
};
|
|
|
|
ProposalGenerator.prototype.resetProposal = function() {
|
|
$('.createProposal input').each(function() {
|
|
$(this).val('');
|
|
});
|
|
setFormEditable(true);
|
|
};
|
|
|
|
ProposalGenerator.prototype.transactionListener = function(proposal) {
|
|
|
|
$('#feeTxid').on('input', function() {
|
|
if ($(this).val().length > 0) {
|
|
|
|
var submitCommand = "gobject submit " + $('#parentHash').val() + " " + $('#revision').val() + " " + $('#time').val() + " " + proposal.gov.serialize() + " " + $(this).val();
|
|
console.log(submitCommand);
|
|
|
|
var txidfield = $('#feeTxid');
|
|
console.log('value entered: ' + txidfield.val());
|
|
|
|
$('textarea#submitProposal').val(submitCommand);
|
|
|
|
txidfield.change(function() {
|
|
// Check input( $( this ).val() ) for validity here
|
|
console.log('there is something wrong with your transaction ID: ' + $('#feeTxid').val() + ' Please copy and paste it here .');
|
|
txidfield.val('')
|
|
});
|
|
|
|
//some checks if feeTxid seems valid before we check the api
|
|
if (txidfield.val().length == 64) {
|
|
if (isAlphaNumeric(txidfield.val())) {
|
|
txidfield.unbind( "change" );
|
|
console.log('feeTxid seems good: ' + txidfield.val());
|
|
console.log("wait while we check the api!");
|
|
|
|
// first check if transactionid is already in api
|
|
$.getJSON(apiserversocket + 'insight-api-dash/tx/' + txidfield.val(), function(data) {
|
|
txidfield.attr("disabled", true);
|
|
$('.walletCommands#walletCommandsProgress').removeClass('hidden');
|
|
var txid = data.tx;
|
|
var confirmations = data.confirmations;
|
|
var conftxt;
|
|
var conftxt2;
|
|
var progbarval;
|
|
console.log('Transaction has ' + confirmations + ' confirmation(s)');
|
|
progbarval = 100/6*confirmations;
|
|
$("#progressbar").progressbar({value: progbarval})
|
|
.children('.ui-progressbar-value')
|
|
.html(progbarval.toPrecision(3) + '%')
|
|
.css("display", "block");
|
|
if (confirmations != 'undefined' && $.isNumeric(confirmations)) {
|
|
var socket = io(apiserversocket);
|
|
if (confirmations == 0) {
|
|
// we have to count the blocks and wait for 6 confirmations
|
|
console.log("we have to count the blocks and wait for 6 confirmations");
|
|
eventToListenTo = 'block';
|
|
room = 'inv';
|
|
socket.on('connect', function() {
|
|
// Join the room.
|
|
socket.emit('subscribe', room);
|
|
console.log("listening for '" + eventToListenTo + "' in '" + room + "'");
|
|
});
|
|
socket.on(eventToListenTo, function(data) {
|
|
console.log("New block received: " + data + " time: " + data.time);
|
|
blockhash = data;
|
|
// let's check if transaction is really in this block or not
|
|
if (confirmations == 0) {
|
|
$.getJSON(apiserversocket + 'insight-api-dash/txs/?block=' + blockhash, function(data) {
|
|
var txs = data.txs;
|
|
var found;
|
|
var numOfTxs = txs.length;
|
|
for (var i = 0; i < numOfTxs; i++) {
|
|
console.log('txs' + i + ': ' + txs[i].txid);
|
|
if (txs[i].txid == txidfield.val()) {
|
|
console.log('found tx!');
|
|
found = true;
|
|
}
|
|
}
|
|
if (found) {
|
|
console.log('all good. Count up confirmations.');
|
|
confirmations = confirmations + 1;
|
|
progbarval = 100/6*confirmations;
|
|
$("#progressbar").progressbar({value: progbarval})
|
|
.children('.ui-progressbar-value')
|
|
.html(progbarval.toPrecision(3) + '%')
|
|
.css("display", "block");
|
|
if (confirmations == 1) {
|
|
conftxt = 'confirmation';
|
|
conftxt2 = 'confirmations';
|
|
}
|
|
else if (confirmations == 5) {
|
|
conftxt = 'confirmations';
|
|
conftxt2 = 'confirmation';
|
|
}
|
|
else {
|
|
conftxt = 'confirmations';
|
|
conftxt2 = 'confirmations';
|
|
}
|
|
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
|
|
console.log('we have ' + confirmations + ' confirmations...');
|
|
}
|
|
else {
|
|
console.log('txid not in new block');
|
|
}
|
|
}).fail(function(jqXHR) {
|
|
if (jqXHR.status == 400) {
|
|
// there seems to be a problem with your feeTxid because txid is not found in api
|
|
console.log('block hash not found in api!');
|
|
} else {
|
|
console.log('There seems to be a problem with the api connection. Maybe endpoint resyncing?');
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
// for the time being just count up the confirmations without confirming everytime if the transaction is still inside the previous blocks
|
|
confirmations = confirmations + 1;
|
|
progbarval = 100/6*confirmations;
|
|
if (confirmations == 1) {
|
|
conftxt = 'confirmation';
|
|
conftxt2 = 'confirmations';
|
|
}
|
|
else if (confirmations == 5) {
|
|
conftxt = 'confirmations';
|
|
conftxt2 = 'confirmation';
|
|
}
|
|
else {
|
|
conftxt = 'confirmations';
|
|
conftxt2 = 'confirmations';
|
|
}
|
|
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
|
|
console.log('we have ' + confirmations + ' confirmations...');
|
|
}
|
|
|
|
if (confirmations >= 6) {
|
|
progbarval = 100;
|
|
$("#progresstxt").text("Your transaction has " + confirmations + " confirmations. You can now submit the proposal.");
|
|
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
|
|
}
|
|
$("#progressbar").progressbar({value: progbarval})
|
|
.children('.ui-progressbar-value')
|
|
.html(progbarval.toPrecision(3) + '%')
|
|
.css("display", "block");
|
|
});
|
|
}
|
|
else if (confirmations > 0 && confirmations <= 5) {
|
|
// we have to count the blocks and wait for outstanding confirmations
|
|
console.log("we have to count the blocks and wait for outstanding confirmations");
|
|
eventToListenTo = 'block';
|
|
room = 'inv';
|
|
socket.on('connect', function() {
|
|
// Join the room.
|
|
socket.emit('subscribe', room);
|
|
console.log("listening for '" + eventToListenTo + "' in '" + room + "'");
|
|
});
|
|
socket.on(eventToListenTo, function(data) {
|
|
console.log("New block received: " + data + " time: " + data.time);
|
|
// for the time being just count up the confirmations without confirming everytime if the transaction is still inside the previous blocks
|
|
confirmations = confirmations + 1;
|
|
progbarval = 100/6*confirmations;
|
|
$("#progressbar").progressbar({value: progbarval})
|
|
.children('.ui-progressbar-value')
|
|
.html(progbarval.toPrecision(3) + '%')
|
|
.css("display", "block");
|
|
if (confirmations = 1) {
|
|
conftxt = 'confirmation';
|
|
conftxt2 = 'confirmations';
|
|
}
|
|
else if (confirmations = 5) {
|
|
conftxt = 'confirmations';
|
|
conftxt2 = 'confirmation';
|
|
}
|
|
else {
|
|
conftxt = 'confirmations';
|
|
conftxt2 = 'confirmations';
|
|
}
|
|
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
|
|
console.log('we have ' + confirmations + ' confirmations...');
|
|
if (confirmations >= 6) {
|
|
progbarval = 100;
|
|
$("#progressbar").progressbar({value: progbarval})
|
|
.children('.ui-progressbar-value')
|
|
.html(progbarval + '%')
|
|
.css("display", "block");
|
|
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
// already reached 6 or more confirmations, so we can proceed
|
|
progbarval = 100;
|
|
$("#progressbar").progressbar({value: progbarval})
|
|
.children('.ui-progressbar-value')
|
|
.html(progbarval + '%')
|
|
.css("display", "block");
|
|
$("#progresstxt").text("Your transaction has " + confirmations + " confirmations. You can now submit the proposal.");
|
|
console.log("already reached 6 or more confirmations, so we can proceed");
|
|
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
|
|
}
|
|
}
|
|
else {
|
|
console.log('Something went terribly wrong. Faulty api data?');
|
|
txidfield.attr("disabled", false);
|
|
}
|
|
}).fail(function(jqXHR) {
|
|
if (jqXHR.status == 400) {
|
|
// there seems to be a problem with your feeTxid because txid is not found in api
|
|
console.log('problem with feeTxid! Ask for new input!');
|
|
alert("Check again and please enter your correct TxID!");
|
|
txidfield.attr("disabled", false);
|
|
} else {
|
|
txidfield.attr("disabled", false);
|
|
console.log('There seems to be a problem with the api connection');
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$('#feeTxid').addClass('validationError');
|
|
$('#feeTxid').val('Your transacton ID is invalid. It must be alphanumeric. Please just copy & paste from console.');
|
|
console.log("there is something wrong with your transaction ID. It must be alphanumeric!")
|
|
}
|
|
}
|
|
else {
|
|
$('#feeTxid').addClass('validationError');
|
|
$('#feeTxid').val('Your transacton ID is invalid. Please just copy & paste from console.');
|
|
console.log("there is something wrong with your transaction ID. It must be exactly 64 characters!")
|
|
}
|
|
}
|
|
else {
|
|
$('textarea#submitProposal').val('');
|
|
$('.walletCommands#walletCommandsSubmit').addClass('hidden');
|
|
}
|
|
|
|
});
|
|
};
|
|
|
|
function setFormEditable(edit) {
|
|
$('.createProposal input').each(function() {
|
|
$(this).attr("disabled", edit);
|
|
});
|
|
$('.createProposal select').each(function() {
|
|
$(this).attr("disabled", edit);
|
|
});
|
|
|
|
if (edit === true) {
|
|
$('#btnPrepare').addClass('hidden');
|
|
$('#btnEdit').removeClass('hidden');
|
|
$('#btnNew').removeClass('hidden');
|
|
} else {
|
|
$('#btnPrepare').removeClass('hidden');
|
|
$('#btnEdit').addClass('hidden');
|
|
$('#btnNew').addClass('hidden');
|
|
}
|
|
}
|
|
|
|
|
|
/***
|
|
* Payment Cycle Generator
|
|
*
|
|
* @param gov
|
|
* @constructor
|
|
*/
|
|
function PaymentCycle(gov) {
|
|
var self = this;
|
|
|
|
this.network = gov.network;
|
|
this.paymentCycle = 16616; // mainnet
|
|
this.budgetCycles = 24;
|
|
|
|
if (this.network == 'testnet') this.paymentCycle = 24;
|
|
if (this.network == 'testnet') this.budgetCycles = 96;
|
|
|
|
this.blockHeight = null;
|
|
|
|
this.Messages = {
|
|
paymentCycle: {
|
|
months: "Months",
|
|
month: "Month",
|
|
days: "Days",
|
|
day: "Day",
|
|
hours: "Hours",
|
|
hour: "Hour",
|
|
minutes: "Minutes",
|
|
minute: "Minute",
|
|
seconds: "Seconds",
|
|
second: "Second"
|
|
}
|
|
};
|
|
|
|
this.getInfo(function(err,res) {
|
|
console.log("current blockheight: " + res.info.blocks);
|
|
|
|
self.blockHeight = res.info.blocks;
|
|
});
|
|
}
|
|
|
|
PaymentCycle.prototype.getNextSuperblock = function(block) {
|
|
return (Math.floor((block/this.paymentCycle)) * this.paymentCycle + this.paymentCycle);
|
|
};
|
|
|
|
PaymentCycle.prototype.getBlockTimestamp = function(block) {
|
|
var blocks = block - this.blockHeight;
|
|
var now = Math.floor(Date.now());
|
|
|
|
return (now + (blocks * (155 * 1000))); // 155 seconds per block x 1000 = ms per block
|
|
};
|
|
|
|
PaymentCycle.prototype.getTimeDifference = function(opts, start, end) {
|
|
|
|
var precision = opts.precision;
|
|
|
|
var millisec = end - start;
|
|
|
|
var seconds = (millisec / 1000).toFixed(precision);
|
|
|
|
var minutes = (millisec / (1000 * 60)).toFixed(precision);
|
|
|
|
var hours = (millisec / (1000 * 60 * 60)).toFixed(precision);
|
|
|
|
var days = (millisec / (1000 * 60 * 60 * 24)).toFixed(precision);
|
|
|
|
var months = (millisec / (1000 * 60 * 60 * 24 * 30)).toFixed(precision);
|
|
|
|
if (seconds < 60) {
|
|
if (seconds <= 1) return seconds + " " + this.Messages.paymentCycle.second; // singular
|
|
return seconds + " " + this.Messages.paymentCycle.seconds;
|
|
} else if (minutes < 60) {
|
|
if (minutes <= 1) return minutes + " " + this.Messages.paymentCycle.minute; // singular
|
|
return minutes + " " + this.Messages.paymentCycle.minutes;
|
|
} else if (hours < 24) {
|
|
if (hours <= 1) return hours + " " + this.Messages.paymentCycle.hour; // singular
|
|
return hours + " " + this.Messages.paymentCycle.hours;
|
|
} else if (days < 30) {
|
|
if (days <= 1) return days + " " + this.Messages.paymentCycle.day; // singular
|
|
return days + " " + this.Messages.paymentCycle.days;
|
|
} else {
|
|
if (months <= 1) return months + " " + this.Messages.paymentCycle.month; // singular
|
|
return months + " " + this.Messages.paymentCycle.months;
|
|
}
|
|
};
|
|
|
|
PaymentCycle.prototype.updateDropdowns = function() {
|
|
var self = this;
|
|
|
|
var blockHeight = this.blockHeight;
|
|
|
|
var startDate = [];
|
|
var endDate = [];
|
|
|
|
for (i = 0; i < this.budgetCycles + 1; i++) {
|
|
|
|
var superblock = this.getNextSuperblock(blockHeight);
|
|
var timestamp = this.getBlockTimestamp(superblock);
|
|
|
|
var label = new Date(timestamp).toLocaleDateString();
|
|
if (this.network == 'testnet') label = new Date(timestamp).toLocaleString();
|
|
|
|
var superblockDate = {
|
|
superblock: superblock,
|
|
timestamp: timestamp,
|
|
label: label
|
|
};
|
|
startDate.push(superblockDate);
|
|
endDate.push(superblockDate);
|
|
|
|
blockHeight = superblock;
|
|
|
|
}
|
|
|
|
endDate.shift(); // remove first element of endDate
|
|
startDate.pop(); // remove last element of startDate to keep length even
|
|
|
|
var now = Math.floor(Date.now());
|
|
|
|
var opts = {
|
|
precision: 2
|
|
}; // 2 unit of precision for eta formatting
|
|
|
|
// calculate the amount of time between start and stop, show: e.g. 5 Months or 5 Hours
|
|
|
|
var start_epoch = $("#start_epoch");
|
|
start_epoch.find('option').remove();
|
|
$.each(startDate, function(index) {
|
|
|
|
var eta = self.getTimeDifference(opts, now, this.timestamp);
|
|
var time = this.timestamp - now;
|
|
var option = $("<option />").val((Math.floor(this.timestamp / 1000))).text(this.label).attr('data-index', index).attr('data-time', time).attr('data-eta', eta).attr('data-block', this.superblock);
|
|
start_epoch.append(option);
|
|
|
|
});
|
|
|
|
|
|
opts.precision = null; // 0 units of precision for eta formatting
|
|
|
|
var end_epoch = $("#end_epoch");
|
|
end_epoch.find('option').remove();
|
|
$.each(endDate, function(index) {
|
|
|
|
var eta = self.getTimeDifference(opts, startDate[0].timestamp, this.timestamp);
|
|
var time = this.timestamp - startDate[0].timestamp;
|
|
|
|
var option = $("<option />").val((Math.floor(this.timestamp / 1000))).text(eta + " (" + this.label + ")").attr('data-index', index).attr('data-time', time).attr('data-eta', eta).attr('data-block', this.superblock);
|
|
end_epoch.append(option);
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
PaymentCycle.prototype.getInfo = function(cb) {
|
|
$.getJSON(apiserversocket + "insight-api-dash/status?q=getinfo", function( data ) {
|
|
cb(null, data);
|
|
});
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var copyToClipboard = function(id) {
|
|
document.getElementById(id).select();
|
|
document.execCommand('copy');
|
|
};
|
|
|
|
getBudgetPaymentCycleBlocks = function() {
|
|
// Amount of blocks in a months period of time (using 2.6 minutes per) = (60*24*30)/2.6
|
|
if (gov.network == 'livenet') {
|
|
return 16616;
|
|
}
|
|
else {
|
|
return 50; // ten times per day
|
|
}
|
|
};
|
|
|
|
formattedDateForSuperblockHeight = function(startheight, months) {
|
|
months = months || 0;
|
|
var endheight;
|
|
var blockdiff;
|
|
if (months !== 0) {
|
|
endheight = (parseInt(startheight) + (getBudgetPaymentCycleBlocks()*months));
|
|
blockdiff = endheight - blockheight;
|
|
}
|
|
else {
|
|
blockdiff = startheight - blockheight;
|
|
}
|
|
var superblocktimestamp = $.now() + blockdiff * (2.6 * 60 * 1000);
|
|
return $.datepicker.formatDate('yy-mm-dd', new Date(superblocktimestamp));
|
|
};
|
|
|
|
function isAlphaNumeric(str) {
|
|
var code, i, len;
|
|
|
|
for (i = 0, len = str.length; i < len; i++) {
|
|
code = str.charCodeAt(i);
|
|
if (!(code > 47 && code < 58) && // numeric (0-9)
|
|
!(code > 64 && code < 91) && // upper alpha (A-Z)
|
|
!(code > 96 && code < 123)) { // lower alpha (a-z)
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container-fluid">
|
|
<div class="row" id="header">
|
|
<div class="col-sm-2">
|
|
<img src="images/dash_logo.png" alt="dash governance tools">
|
|
</div>
|
|
<div class="col-sm-4">
|
|
<h2 class="header_title">Dash Budget Proposal Generator</h2>
|
|
<h5 class="header_description">Generate budget proposal commands you can copy/paste into your Dash wallet to prepare a budget proposal and submit it to the network.</h5>
|
|
</div>
|
|
<div class="col-sm-4 col-sm-offset-2 text-right">
|
|
<i class="fa fa-twitter" aria-hidden="true"></i>
|
|
<i class="fa fa-facebook" aria-hidden="true"></i>
|
|
<i class="fa fa-rss" aria-hidden="true"></i>
|
|
<img id="lang_box" src="images/lang.png" alt="english language">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-sm-5 col-sm-offset-2 col-xs-12 col-xs-offset-0">
|
|
<div class="proposalBlock createProposal">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<div class="row" id="createProposalHeader">
|
|
<div class="col-xs-12">
|
|
<h1 class="removeMargin">Create a Proposal</h1>
|
|
<h5 class="header_description">Enter details for your proposal and click 'Create Proposal'. This will generate a command you can run in your local wallet to prepare the proposal at a cost of 0.33 Dash</h5>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="createProposalForm">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<div class="form-group">
|
|
<label for="name">Proposal Name:</label>
|
|
<input type="text" class="form-control" id="name" value="" placeholder="proposal-name">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="url">Proposal Description URL:</label>
|
|
<input type="text" class="form-control" id="url" value="" placeholder="https://www.dashcentral.org/p/proposal-name">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-xs-3">
|
|
<div class="form-group">
|
|
<label for="start_epoch">Start Date:</label>
|
|
<select name="start_epoch" class="form-control" id="start_epoch"></select>
|
|
</div>
|
|
</div>
|
|
<div class="col-xs-3">
|
|
<!-- -->
|
|
<!-- -->
|
|
<!-- ATTENTION: COMMENT FOR JON -->
|
|
<!-- -->
|
|
<!-- -->
|
|
<!-- The following form group is a placeholder for proposal end time. Please change to the correct id. -->
|
|
<div class="form-group">
|
|
<label for="start_epoch">End Date:</label>
|
|
<select name="start_epoch" class="form-control" id="end_epoch"></select>
|
|
</div>
|
|
<!-- -->
|
|
<!-- -->
|
|
<!-- -->
|
|
</div>
|
|
<div class="col-xs-6">
|
|
<div class="form-group">
|
|
<label for="payment_address">Payment Address:</label>
|
|
<input type="text" class="form-control" id="payment_address" value="" placeholder="">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-xs-7">
|
|
<div class="form-group">
|
|
<label for="payment_amount">Monthly Payment Amount in Dash:</label>
|
|
<input type="text" class="form-control" id="payment_amount" value="" placeholder="0">
|
|
</div>
|
|
</div>
|
|
<div class="col-xs-4 col-xs-offset-1">
|
|
<div type="submit" class="btn btn-success" id="btnPrepare">Create Proposal</div>
|
|
<div type="submit" class="btn btn-primary hidden" id="btnEdit">Edit Proposal</div>
|
|
<div type="submit" class="btn btn-primary hidden" id="btnNew">New Proposal</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group" style="display:none;">
|
|
<label for="type">type:</label>
|
|
<input type="text" class="form-control" id="type" value="1" placeholder="1">
|
|
</div>
|
|
|
|
<div class="form-group" style="display:none;">
|
|
<label for="parentHash">parent-hash:</label>
|
|
<input type="text" class="form-control" id="parentHash" value="0" placeholder="0">
|
|
</div>
|
|
|
|
<div class="form-group" style="display:none;">
|
|
<label for="revision">revision:</label>
|
|
<input type="text" class="form-control" id="revision" value="1" placeholder="1">
|
|
</div>
|
|
|
|
<div class="form-group" style="display:none;">
|
|
<label for="time">Creation Time:</label>
|
|
<input type="text" class="form-control" id="time" value="" placeholder="">
|
|
</div>
|
|
|
|
<!-- -->
|
|
<!-- -->
|
|
<!-- -->
|
|
<!-- ATTENTION: COMMENT FOR JON -->
|
|
<!-- The following form group is commented out because it's not a part of the design mock. Staying here for safe keeping just in case still needed. -->
|
|
|
|
<!-- <div class="form-group">
|
|
<label for="end_epoch">Choose payment cycle:</label>
|
|
<select name="end_epoch" class="form-control" id="end_epoch"></select>
|
|
</div> -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="row walletCommands hidden" id="walletCommandsHeader">
|
|
<div class="col-xs-12">
|
|
<h2>Wallet Commands</h2>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row walletCommands hidden" id="walletCommandsPrepare">
|
|
|
|
<div class="col-xs-12">
|
|
|
|
<div class="form-group">
|
|
<label for="prepareProposal">Prepare-Proposal Command:</label>
|
|
<div>Paste this proposal command into your Dash wallet console to spend a Fee transaction of 0.33 DASH.</div>
|
|
<textarea readonly class="form-control" id="prepareProposal" rows="4" placeholder=""></textarea>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row walletCommands hidden" id="walletCommandsTx">
|
|
|
|
<div class="col-xs-12">
|
|
|
|
<div class="form-group">
|
|
<label for="feeTxid">Fee Transaction ID:</label>
|
|
<div>Paste the transaction ID returned by the wallet below to generate the final submit command.</div>
|
|
<input type="text" class="form-control" id="feeTxid" value="" placeholder="<fee-txid>">
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row walletCommands hidden" id="walletCommandsProgress">
|
|
|
|
<div class="col-xs-12">
|
|
|
|
<div class="form-group">
|
|
<label for="feeTxid">Fee Transaction Progress:</label>
|
|
<div id="progresstxt">We'll wait for 6 confirmations. Waiting for new blocks to confirm...</div>
|
|
<div id="progressbar"></div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row walletCommands hidden" id="walletCommandsSubmit">
|
|
|
|
<div class="col-xs-12">
|
|
|
|
<div class="form-group">
|
|
<label for="submitProposal">Submit Proposal Command:</label>
|
|
<div>Paste the Fee TX id to generate the proposal submit command. This is the final step and can be completed after 6 confirmations on the fee tx.</div>
|
|
<textarea readonly class="form-control" id="submitProposal" rows="4" placeholder=""></textarea>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|