This repository has been archived by the owner on Jan 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pool_transaction.html
236 lines (221 loc) · 9.25 KB
/
pool_transaction.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
<div class="cardpad card">
<div class="card-header">
<h2>Transaction <small id="transaction.hash"></small></h2>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm-12">
<div class="cardpad card">
<div class="card-header">
<h3>Transaction status</h3>
</div>
<div class="card-body">
<p>
<span data-toggle="popover" data-trigger="hover" data-placement="top" data-content="transaction fee">
<i class="fas fa-donate"></i> Fee: <span id="transaction.fee"></span>
</span>
</p>
<p>
<span data-toggle="popover" data-trigger="hover" data-placement="top"
data-content="Sum of amounts">
<i class="fas fa-dollar-sign"></i> Sum of outputs: <span id="transaction.amount_out"></span>
</span>
</p>
<p>
<span data-toggle="popover" data-trigger="hover" data-placement="top"
data-content="Transaction size">
<i class="far fa-hdd"></i> Size: <span id="transaction.size"></span>
</span>
</p>
<p id="div_transaction_paymentId">
<span data-toggle="popover" data-trigger="hover" data-placement="top"
data-content="Transaction payment ID">
<i class="fas fa-id-badge"></i> Payment ID: <span id="transaction.paymentId"></span>
</span>
</p>
<p id="div_transaction_mixin">
<span data-toggle="popover" data-trigger="hover" data-placement="top"
data-content="Transaction mixin">
<i class="fas fa-random"></i> Mixin count: <span id="transaction.mixin"></span>
</span>
</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="cardpad card">
<div class="card-header">
<h3>Inputs</h3>
</div>
<div id="tx_table" class="card-body table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th><i class="far fa-money-bill-alt"></i> Amount</th>
<th><i class="far fa-image"></i> Image</th>
</tr>
</thead>
<tbody id="inputs_rows">
</tbody>
</table>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="cardpad card">
<div class="card-header">
<h3>Outputs</h3>
</div>
<div id="tx_table" class="card-body table-responsive">
<table class="table table-hover">
<thead>
<tr>
<tr>
<th><i class="far fa-money-bill-alt"></i> Amount</th>
<th><i class="fas fa-key"></i> Key</th>
</tr>
</tr>
</thead>
<tbody id="outputs_rows">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
currentPage = {
init: function (){
if(typeof poolUpdate !== 'undefined') {
clearTimeout(poolUpdate);
}
if(typeof poolPulse !== 'undefined') {
clearTimeout(poolPulse);
}
if(typeof txPulse !== 'undefined') {
clearTimeout(txPulse);
}
if(typeof tx_wheel !== 'undefined') {
clearTimeout(tx_wheel);
}
renderTransaction();
},
destroy: function(){
},
update: function(){
if ((typeof lastMinedBlockHeader !== 'undefined') && parseInt(lastMinedBlockHeader.block_header.height, 10) !== parseInt($('#blockchainHeight').attr('data-height'), 10)) {
}
}
};
let xhrGetTransaction;
function renderTransaction(){
if (xhrGetTransaction) xhrGetTransaction.abort();
xhrGetTransaction = $.ajax({
url: api + '/json_rpc',
method: "POST",
data: JSON.stringify({
jsonrpc: "2.0",
id: "test",
method: "f_pool_transaction_json",
params: {
hash: urlParam('hash')
}
}),
dataType: 'json',
cache: 'false'
})
.done(function (data) {
if (data.hasOwnProperty('result')) {
transaction = data.result.txDetails;
inputs = data.result.tx.vin;
outputs = data.result.tx.vout;
block = data.result.block;
updateText('transaction.hash', transaction.hash);
updateText('transaction.amount_out',getReadableCoins(transaction.amount_out, 2, false));
updateText('transaction.fee', getReadableCoins(transaction.fee, 2, true));
if (!transaction.mixin)
$('#div_transaction_mixin').hide();
updateText('transaction.mixin', transaction.mixin);
if (!transaction.paymentId)
$('#div_transaction_paymentId').hide();
updateText('transaction.paymentId', transaction.paymentId);
updateText('transaction.size', transaction.size);
//
renderInputs(inputs);
renderOutputs(outputs);
$('#loading').hide();
}
})
.fail(function (xhrGetBlock, textStatus) {
if (textStatus != "abort") {
showalert('alert-danger', 'Can\'t connect to api : ', textStatus);
$('#loading').hide();
}
});
}
function getInputCells(input){
return '<td>' + getReadableCoins(input.value.amount) + '</td>' +
'<td>' + input.value.k_image + '</td>';
}
function getInputRowElement(input, jsonString){
const row = document.createElement('tr');
row.setAttribute('data-json', jsonString);
row.setAttribute('data-k_image', input.value.k_image);
row.setAttribute('id', 'inputRow' + input.value.k_image);
row.innerHTML = getInputCells(input);
return row;
}
function renderInputs(inputResults){
const $inputsRows = $('#inputs_rows');
for (let i = 0; i < inputResults.length; i++){
let input = inputResults[i];
if (!input.value.amount)
continue;
let inputJson = JSON.stringify(input);
let existingRow = document.getElementById('inputRow' + input.value.k_image);
if (existingRow && existingRow.getAttribute('data-json') !== inputJson){
$(existingRow).replaceWith(getInputRowElement(input, inputJson));
}
else if (!existingRow){
let inputElement = getInputRowElement(input, inputJson);
$inputsRows.append(inputElement);
}
}
}
function getOutputCells(output){
return '<td>' + getReadableCoins(output.amount) + '</td>' +
'<td>' + output.target.data.key + '</td>';
}
function getOutputRowElement(output, jsonString){
const row = document.createElement('tr');
row.setAttribute('data-json', jsonString);
row.setAttribute('data-k_image', output.target.data.key);
row.setAttribute('id', 'outputRow' + output.target.data.key);
row.innerHTML = getOutputCells(output);
return row;
}
function renderOutputs(outputResults){
const $outputsRows = $('#outputs_rows');
for (let i = 0; i < outputResults.length; i++){
let output = outputResults[i];
let outputJson = JSON.stringify(output);
let existingRow = document.getElementById('outputRow' + output.target.data.key);
if (existingRow && existingRow.getAttribute('data-json') !== outputJson){
$(existingRow).replaceWith(getOutputRowElement(output, outputJson));
}
else if (!existingRow){
let outputElement = getOutputRowElement(output, outputJson);
$outputsRows.append(outputElement);
}
}
}
// enable popover
$(document).ready(function(){
$('[data-toggle="popover"]').popover({
})
});
</script>