forked from ethgasstation/ethgasstation-frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
/
calculatorTxV.php
executable file
·458 lines (389 loc) · 17.3 KB
/
calculatorTxV.php
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
<?php require_once 'build/php/common.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo EGS_TITLE; ?> | Consumer oriented metrics for the Ethereum gas market </title>
<meta name="keywords" content="Ethereum ETH gas blockchain market price transactions miners users">
<meta name="description" content="<?php echo EGS_DESCRIPTION; ?>">
<meta property="og:title" content="<?php echo EGS_TITLE; ?>" />
<meta property="og:type" content="website" />
<meta property="og:image" content="/images/ETHGasStation.png" />
<meta property="og:description" content="ETH gas price recommendations." />
<meta property="og:url" content="https://ethgasstation.info/" />
<!-- Bootstrap -->
<link href="vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<!--Favicon-->
<link rel="apple-touch-icon" sizes="57x57" href="images/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="images/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="images/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="images/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="images/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="images/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="images/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="images/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="images/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="images/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-134672026-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-134672026-1');
</script>
<!-- Custom Theme Style -->
<link href="build/css/custom.css?d=3" rel="stylesheet">
<?php include 'build/php/minerT_py.php'; ?>
</head>
<body class="nav-md">
<?php include 'unofficial.php'; ?>
<div class="container body calculator">
<div class="main_container calculator">
<!-- Sidebar -->
<?php include 'sidebar.php'; ?>
<?php include '_header.php'; ?>
<!-- page content -->
<div class="right_col calculator" role="main">
<div class="row tx_calculator">
<div class="col-md-6 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h4>Transaction Inputs</h4>
<div class="clearfix"></div>
</div>
<div class="x_content">
<br />
<form class="form-horizontal form-label-left input_mask">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Gas Used<span class="required">*</span></label>
<div class="col-md-9 col-sm-9 col-xs-12">
<input type="number" class="form-control" placeholder="21000" id="gas_used">
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-sm-3 col-xs-12 control-label">Gas Price<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="checkbox">
<label>
<input type="checkbox" class="flat" id="fastest"> Fastest
<?php echo ("(".($gpRecs2['fastest']/10)." Gwei)") ?></label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" class="flat" id="fast"> Fast
<?php echo ("(".($gpRecs2['fast']/10)." Gwei)") ?></label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" class="flat" checked="checked" id="avg"> Average
<?php echo ("(".($gpRecs2['average']/10)." Gwei)") ?></label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" class="flat" id="cheap"> Cheap
<?php if ($gpRecs2['safeLow'] ==0){$gpRecs2['safeLow']=1;} echo ("(".($gpRecs2['safeLow']/10)." Gwei)") ?></label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" class="flat" id="other"> Other
</label>
</div>
<div>
<input type="number step=.1" class="form-control" placeholder="(Gwei)" id="oth_val">
</div>
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
<button class="btn btn-primary" type="reset" id="reset">Reset</button>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h4 id="txArgs">Predictions:</h4>
<div class="clearfix"></div>
</div>
<div class="x_content">
<table class="table table-bordered">
<thead>
<tr>
<th>Outcome</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>% of last 200 blocks accepting this gas price</td>
<td id="hp"></td>
</tr>
<tr>
<td>Transactions At or Above in Current Txpool</td>
<td id="txatabove"></td>
</tr>
<tr>
<td>Mean Time to Confirm (Blocks)</td>
<td id="meanBlocks"></td>
</tr>
<tr>
<td>Mean Time to Confirm (Seconds)</td>
<td id="meanSecs"></td>
</tr>
<tr>
<td>Transaction fee (ETH)</td>
<td id="txEth"></td>
</tr>
<tr>
<td>Transaction fee (Fiat)</td>
<td id="txFiat"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /misc transactions -->
</div>
<?php include '_footer.php'; ?>
</div>
<!-- /page content -->
</div>
</div>
<!-- jQuery -->
<script src="vendors/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Chart.js -->
<script src="vendors/Chart.js/dist/Chart.min.js"></script>
<!-- Custom Theme Scripts -->
<script>
var txGasPrice;
var predictArray = [];
$(document).ready(function() {
_loadPredictionTable();
_bindFormFieldListeners();
});
//Curency Support
$("#eur").click(function(){
location = location.origin + "/calculatorTxV.php?curr=eur";
});
$("#usd").click(function() {
location = location.origin + "/calculatorTxV.php?curr=usd";
});
$("#cny").click(function() {
location = location.origin + "/calculatorTxV.php?curr=cny";
});
$("#gbp").click(function() {
location = location.origin + "/calculatorTxV.php?curr=gbp";
});
$('#reset').click(function() {
$('#txatabove').html("");
$('#minedprob').html("");
$('#hp').html("");
$('#meanBlocks').html("");
$('#meanSecs').html("");
$('#txEth').html("");
$('#txFiat').html("");
$('#txArgs').html("Predictions:");
$("#oth_val").parent().next(".validation").remove();
$("#gas_used").parent().next(".validation").remove();
});
$('form').submit(function(event) {
event.preventDefault(); // prevent form from POST to server
_calculate();
});
function _calculate() {
/* remove previosly shown error message */
var errorMsg = $("#oth_val").parent().next(".validation");
if (errorMsg) errorMsg.remove();
errorMsg = $("#gas_used").parent().next(".validation");
if (errorMsg) errorMsg.remove();
/* Set gas used amount */
var gasLimit = $('#gas_used').val();
if(!gasLimit) {
txGasUsed = 21000; /* use minimum gas limit */
} else if (gasLimit > 8000000) {
if ($("#gas_used").parent().next(".validation").length == 0) {
$string = "<div class='validation' style='color:red;margin-bottom: 20px;'>Please enter gas used less than 80,00,000 (block limit)";
$("#gas_used").parent().after($string);
}
$('#gas_used').focus();
focusSet = true;
return;
} else {
txGasUsed = gasLimit;
}
/* Gas Used Set - Now find Gas Price */
if($('#other').prop('checked') === true) {
otherGasPrice = $('#oth_val').val();
if (!otherGasPrice || otherGasPrice < 0.1) {
if ($("#oth_val").parent().next(".validation").length === 0){ // only add if not added
$("#oth_val").parent().after("<div class='validation' style='color:red;margin-bottom: 20px;'>Please enter gas price >= 0.1 gwei</div>");
}
$('#oth_val').focus();
focusSet = true;
return;
} else {
txGasPrice = $("#oth_val").val();
}
} else {
if ($('#fastest').prop('checked') === true) {
txGasPrice = <?php echo($gpRecs2['fastest'] / 10) ?>;
} else if ($('#fast').prop('checked') === true) {
txGasPrice = <?php echo($gpRecs2['fast'] / 10) ?>;
} else if ($('#avg').prop('checked') === true) {
txGasPrice = <?php echo($gpRecs2['average'] / 10) ?>;
} else if ($('#cheap').prop('checked') === true) {
txGasPrice = <?php echo($gpRecs2['safeLow'] / 10) ?>;
} else {
txGasPrice = 1;
}
$('#oth_val').val("");
}
pdValues = _estimateWait(_getIndex(txGasPrice, predictArray), txGasUsed);
txArgs = "Predictions: <small><span style='color:red'> Gas Used = "+ txGasUsed + "; Gas Price = " + txGasPrice + " gwei</span></small>";
$('#txArgs').html(txArgs);
console.log(pdValues);
blocksWait = pdValues[0];
hashpower = pdValues[1];
txatabove = pdValues[2];
minedprob = pdValues[3];
console.log(blocksWait);
currency = '<?php echo ($currency) ?>';
console.log(currency);
exchangeRate =<?php echo ($exchangeRate) ?>;
blockInterval = <?php echo ($gpRecs2['block_time']) ?>;
txMeanSecs = blocksWait * blockInterval;
txMeanSecs = Number(txMeanSecs.toFixed(0));
blocksWait = Number(blocksWait.toFixed(1));
txFeeEth = txGasPrice/1e9 * txGasUsed;
txFeeEth = Number((txFeeEth).toFixed(7))
txFeeFiat = txFeeEth * exchangeRate;
txFeeFiat = Number(txFeeFiat.toFixed(5));
$('#meanBlocks').html(blocksWait);
$('#hp').html(hashpower);
$('#txatabove').html(txatabove);
$('#meanSecs').html(txMeanSecs);
$('#txEth').html(txFeeEth);
if (currency === 'usd') {
string = "$" + txFeeFiat;
$('#txFiat').html(string);
} else if (currency === 'eur') {
string = "€" + txFeeFiat;
$('#txFiat').html(string);
} else if (currency === 'cny') {
string = "¥" + txFeeFiat;
$('#txFiat').html(string);
} else if (currency === 'gbp') {
string = "£" + txFeeFiat;
$('#txFiat').html(string);
}
}
function _estimateWait (index, gasoffered) {
var sum1, sum2;
var intercept = 4.2794;
var hpa = .0329;
var hgo = -3.2836;
var wb = -0.0048;
var tx = -0.0004;
var intercept2 = 7.5375;
var hpa_coef = -0.0801;
var txatabove_coef= 0.0003;
var high_gas_coef = .3532;
if (gasoffered > 1000000) {
sum1 = intercept + (predictArray[index]['hashpower_accepting'] * hpa) + hgo + (predictArray[index]['tx_atabove'] * tx);
sum2 = intercept2 + (predictArray[index]['hashpower_accepting'] * hpa_coef) + (predictArray[index]['tx_atabove'] * txatabove_coef) + high_gas_coef;
} else {
sum1 = intercept + (predictArray[index]['hashpower_accepting'] * hpa) + (predictArray[index]['tx_atabove'] * tx);
sum2 = intercept2 + (predictArray[index]['tx_atabove'] * txatabove_coef) + (predictArray[index]['hashpower_accepting'] * hpa_coef);
}
var factor = Math.exp(- 1 * sum1);
prob = 1 / (1 + factor);
if (prob > .95) {
minedProb = 'Very High';
} else if (prob > .9 && prob <= .95) {
minedProb = 'Medium'
} else {
minedProb = 'Low';
}
expectedWait = Math.exp(sum2);
if (expectedWait < 2) {
expectedWait = 2;
}
if (gasoffered > 2000000) {
expectedWait += 100;
}
return [expectedWait, predictArray[index]['hashpower_accepting'], predictArray[index]['tx_atabove'], minedProb];
}
function _getIndex(gasprice, predictArray) {
var index = 0;
for( ; index < predictArray.length; index++) {
if (predictArray[index]['gasprice'] == gasprice){
break;
}
}
/* if gas price doesn't match show result for closest value */
if (index >= predictArray.length) {
var closest = predictArray.reduce(function(prev, curr) {
return (Math.abs(curr['gasprice'] - gasprice) < Math.abs(prev['gasprice'] - gasprice) ? curr : prev);
});
var closestGasPrice = closest.gasprice;
if ($('#other').prop('checked') === true) {
txGasPrice = closestGasPrice;
$("#oth_val").parent().after("<div class='validation' style='color:red;margin-bottom: 20px;'>Provided gas price does not match, showing result for the closest value: " + closestGasPrice + " Gwei</div>");
}
index = predictArray.findIndex(function(item) {
return item['gasprice'] === closestGasPrice;
});
}
return index;
}
function _loadPredictionTable() {
$.ajax({
url: "json/predictTable.json",
method: "GET",
dataType: "json",
success: function(data) {
predictArray = data;
// _calculate();
}
});
}
function _bindFormFieldListeners() {
$('.checkbox input.flat').change(function() {
$('input.flat').not(this).prop('checked',false);
// _calculate();
});
$('#oth_val').change(function() {
$('.checkbox input.flat').prop('checked', false);
$('#other').prop('checked', true);
});
$('#gas_used, #oth_val').change(function() {
// _calculate();
})
}
</script>
<script src="build/js/custom3.js"></script>
</body>
</html>