forked from peercoin/peercoin-POSCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
289 lines (264 loc) · 16.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title id=title>Curecoin POS Calculator</title>
<link rel=icon href="data:image/vnd.microsoft.icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A7PT4Mszm8pmw3e3bltjr+ofZ6vqM4O3bq+jxmebz9zL///8A////AP///wD///8A////AP///wD6/P0Jy+fzmqjc8P2O0+n9edXp/XDf7/1s6fX9Z+z3/WDq9v1T5vP9oefwm/r7/Qn///8A////AP///wD6+/0Jwef0wZLS6f1esdP9SKbD/0Kmv/8/r8b/P8bc/0Hd7/9F6vf/WfL7/V/u+f2a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N5/hkz+fZpd7tl+nz+DH///8A////AP///wD///8A+B8AAOAHAADAAwAAgAEAAIABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAAgAEAAMADAADgBwAA+B8AAA==">
<style>
/* CSS based on peercoin.net by super3 and other contributors */
html { font-family: 'Segoe UI', Helvetica, Arial, sans-serif; overflow-y: scroll; }
body { margin: 0; }
header { background-color: #f8f8f8; color: #526476; padding-top: 17px; text-align: center; }
header section#languages label { display: inline-block; }
header section#languages a { color: #526476; display: inline-block; padding: 5px 10px; text-decoration: none; transition: 0.25s ease; }
header section#languages a:hover { color: #1abc9c; }
header h1 { background-color: #21262c; color: #fff; font-size: 190%; padding: 30px; }
article#content { color: #000; margin: 0 auto; max-width: 940px; padding: 0 10px; }
article#content ul li { padding: 5px; }
input[type=number] { width: 120px; }
table.result, table.result th, table.result td, table.result td.num { border: 1px solid #000; padding: 5px; }
table.result { border-collapse: collapse; width: 100%; }
table.result td { text-align: left; }
table.result td.num { text-align: right; }
footer { background-color: #1abc9c; padding: 20px; text-align: center; }
footer a { color: #fff; display: inline-block; padding: 5px 10px; text-decoration: none; }
footer a:hover { text-decoration: underline; }
section#noscript { background-color: #d9534f; color: #fff; font-weight: bold; position: fixed; top: 0; text-align: center; width: 100%; }
section#noscript-padding { padding-bottom: 52px; }
@media screen and (max-width: 691px) {
section#noscript-padding { padding-top: 28px; }
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="translations.js"></script>
</head>
<body>
<div id="wrap">
<header>
<noscript>
<section id="noscript-padding"></section>
</noscript>
<section id="languages">
<label id="header_prefix">Languages:</label>
<a href="#" onclick="translate_page('en')">English</a>
<a href="#" onclick="translate_page('de')">Deutsch</a>
<a href="#" onclick="translate_page('es')">Español</a>
<a href="#" onclick="translate_page('fr')">Français</a>
<a href="#" onclick="translate_page('nl')">Nederlands</a>
<a href="#" onclick="translate_page('ru')">русский</a>
<a href="#" onclick="translate_page('zh-cn')">简体中文</a>
<a href="#" onclick="translate_page('cs')">Česky</a>
<a href="#" onclick="translate_page('no')">Norsk</a>
</section>
<h1><label id="header_title">Curecoin Proof-Of-Stake (POS) Calculator v0.0.1</label></h1>
</header>
<article id="content">
<p>
<span><label id="intro">Currently it is very early days... so only basic functions but you can:</label></span>
<ul>
<li><label id="desc1">Enter the amount of coins you sent in a transaction, the number of days that have passed and the POS difficulty to get a readout.</label>
<li><label id="desc2">The probability of minting a block reaches its maximum after 90 days and doesn't increase after that.</label>
<li><label id="desc3">The POS difficulty value can be obtained from the console window of ppcoin-qt, you can get it with the command: getdifficulty. Or, if you have ppcoind running, in a command prompt: ppcoind getdifficulty.</label>
<li><label id="desc4">More features to come...</label>
</ul>
<br>
<table>
<tr>
<td><label id="entry_coins">Number Of Coins</label></td>
<td><input type="number" id="NumberOfCoinsStart" value="1000" onBlur="return is_int(this)"></td>
<td> </td>
</tr>
<tr>
<td><label id="entry_days">Age of transaction (days)</label></td>
<td><input type="number" id="AgeOfTransaction" value="31"></td>
<td style="color:red;font-size:80%" id="AgeOfTransaction_error">Probability maxed at 90 days</td>
</tr>
<tr>
<td><label id="entry_difficulty">POS difficulty</label></td>
<td><input type="number" id="POSDifficulty" value="10"></td>
<td> </td>
</tr>
</table>
<br>
<table class=result>
<tr>
<th><label id="prob_mint">Minting POS block within</label></th>
<th><label id="prob_10m">10 min</label></th>
<th><label id="prob_24h">24 hours</label></th>
<th><label id="prob_31d">31 days</label></th>
<th><label id="prob_90d">90 days</label></th>
<th><label id="prob_1y">1 year</label></th>
</tr>
<tr>
<th><label id="prob_prob">Probability</label></th>
<td class=num><label id="probNextBlock"></label></td>
<td class=num><label id="probBlockToday"></label></td>
<td class=num><label id="probBlock31d"></label></td>
<td class=num><label id="probBlock90d"></label></td>
<td class=num><label id="probBlockYear"></label></td>
</tr>
<tr>
<th><label id="reward_block">Reward</label></td>
<td class=num><label id="rewardNextBlock"></label></td>
<td class=num><label id="rewardBlockToday"></label></td>
<td class=num><label id="rewardBlock31d"></label></td>
<td class=num><label id="rewardBlock90d"></label></td>
<td class=num><label id="rewardBlockYear"></label></td>
</tr>
</table>
<br>
</article>
<footer>
<a id="footer_peer4commit" href="http://peer4commit.com/projects/5" target="_blank">Donate to the development of this project</a>
<a id="footer_peercointalk" href="http://donate.peercointalk.org/" target="_blank">Donate to Peercointalk projects</a>
<a id="footer_github" href="https://github.com/FuzzyBearBTC/peercoin-POSCalculator" target="_blank">Contribute to this project on GitHub</a>
</footer>
</div>
<noscript>
<section id=noscript>
<p>Peercoin POS Calculator requires JavaScript. Please enable it in your browser and refresh.
</section>
</noscript>
<script>
var is_int = function(value) {
return ((parseFloat(value) === parseInt(value)) && !isNaN(value));
};
var toFixed = function(value, precision) {
precision = (precision || 0);
var neg = (value < 0);
var power = Math.pow(10, precision);
value = Math.round(value * power);
var integral = String((neg ? Math.ceil : Math.floor)(value / power));
var fraction = String((neg ? -value : value) % power);
var padding = new Array(Math.max(precision - fraction.length, 0) + 1).join('0');
var res = precision ? (integral + '.' + padding + fraction) : integral;
return res;
};
var calculateProbStake = function(days, coins, difficulty) {
var prob = 0;
if (days > 30) {
var maxTarget = Math.pow(2, 224);
var target = maxTarget / difficulty;
var dayWeight = Math.min(days, 90) - 30;
prob = (target * coins * dayWeight) / Math.pow(2, 256);
}
return prob;
};
var calculateProbNextBlock = function(days, coins, difficulty) {
var prob = calculateProbStake(days, coins, difficulty);
var res = 1 - Math.pow(1 - prob, 60 * 10);
return res;
};
var calculateProbBlockToday = function(days, coins, difficulty) {
var prob = calculateProbStake(days, coins, difficulty);
var res = 1 - Math.pow(1 - prob, 60 * 10 * 6 * 24);
return res;
};
var calculateProbBlockNDays = function(days, coins, difficulty, n) {
var prob = 1;
var p = 0;
for (var i = 0; i < n; i++) {
p = calculateProbBlockToday(parseFloat(days) + i, coins, difficulty);
prob = prob * (1 - p);
}
prob = 1 - prob;
return prob;
};
var calculateReward = function(days, coins) {
var res = 0;
if (days > 30) {
res = 0.01 * (days * coins * 33) / (365 * 33 + 8);
}
return toFixed(res, 2);
};
var run = function() {
var coinValue = document.getElementById('NumberOfCoinsStart').value;
var Days = document.getElementById('AgeOfTransaction').value;
var difficulty = document.getElementById('POSDifficulty').value;
if (Days > 90) {
$('#AgeOfTransaction_error').show();
}
else {
$('#AgeOfTransaction_error').hide();
}
// Minting probabilities
var probNextBlock = calculateProbNextBlock(Days, coinValue, difficulty);
var probBlockToday = calculateProbBlockToday(Days, coinValue, difficulty);
var probBlock31d = calculateProbBlockNDays(Days, coinValue, difficulty, 31);
var probBlock90d = calculateProbBlockNDays(Days, coinValue, difficulty, 90);
var probBlockYear = calculateProbBlockNDays(Days, coinValue, difficulty, 365);
document.getElementById('probNextBlock').innerHTML = toFixed(probNextBlock * 100, 6) + '%';
document.getElementById('probBlockToday').innerHTML = toFixed(probBlockToday * 100, 6) + '%';
document.getElementById('probBlock31d').innerHTML = toFixed(probBlock31d * 100, 6) + '%';
document.getElementById('probBlock90d').innerHTML = toFixed(probBlock90d * 100, 6) + '%';
document.getElementById('probBlockYear').innerHTML = toFixed(probBlockYear * 100, 6) + '%';
// Rewards
var rewardNextBlock = calculateReward(parseFloat(Days), coinValue);
var rewardBlockToday = calculateReward(parseFloat(Days) + 1, coinValue);
var rewardBlock31d = calculateReward(parseFloat(Days) + 31, coinValue);
var rewardBlock90d = calculateReward(parseFloat(Days) + 90, coinValue);
var rewardBlockYear = calculateReward(parseFloat(Days) + 365, coinValue);
document.getElementById('rewardNextBlock').innerHTML = toFixed(rewardNextBlock, 2) + ' PPC';
document.getElementById('rewardBlockToday').innerHTML = toFixed(rewardBlockToday, 2) + ' PPC';
document.getElementById('rewardBlock31d').innerHTML = toFixed(rewardBlock31d, 2) + ' PPC';
document.getElementById('rewardBlock90d').innerHTML = toFixed(rewardBlock90d, 2) + ' PPC';
document.getElementById('rewardBlockYear').innerHTML = toFixed(rewardBlockYear, 2) + ' PPC';
};
var translate_page = function(lang) {
var id;
var dict;
if (lang === "undefined") {
lang = "en";
}
dict = translations[lang];
for (id in dict) {
if (document.getElementById(id)) {
if (document.getElementById(id).value) {
document.getElementById(id).value = dict[id];
} else {
document.getElementById(id).innerHTML = dict[id];
}
}
}
};
translate_page();
// Calculate the POS reward dynamically, without having to press a button
var coinValueInput = document.querySelector('#NumberOfCoinsStart');
var daysInput = document.querySelector('#AgeOfTransaction');
var difficultyInput = document.querySelector('#POSDifficulty');
// Reward is calculated when typing or when the input loses focus
coinValueInput.addEventListener('keyup', run);
coinValueInput.addEventListener('change', run);
daysInput.addEventListener('keyup', run);
daysInput.addEventListener('change', run);
difficultyInput.addEventListener('keyup', run);
difficultyInput.addEventListener('change', run);
// Because it runs dynamically, it should run at least once initially
run();
// Dynamically pull the current POS difficulty using peerchain's api and YQL to bypass cross-origin-request restrictions.
// to do - add curecoin api
$.ajax({
url: "http://query.yahooapis.com/v1/public/yql",
jsonp: "callback",
dataType: "jsonp",
data: {
q: "select * from json where url=\"http://peerchain.net/api/network/last\"",
format: "json"
},
success: function( response ) {
difficultyInput.value = response.query.results.json.pos_difficulty;
run();
}
});
</script>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-11111111-4', 'curecoin.net');
ga('send', 'pageview');
</script>
</body>
</html>