-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
380 lines (345 loc) · 12.6 KB
/
index.html
File metadata and controls
380 lines (345 loc) · 12.6 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tx Summary Tester</title>
<style>
body {
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
"Segoe UI Emoji";
max-width: 980px;
margin: 28px auto;
padding: 0 16px;
line-height: 1.4;
color: #111827;
}
.input-group {
margin: 16px 0;
}
label {
display: block;
font-size: 13px;
color: #374151;
margin-bottom: 6px;
}
input {
width: 100%;
box-sizing: border-box;
padding: 10px 12px;
font-size: 14px;
border: 1px solid #d1d5db;
border-radius: 8px;
background: #fff;
}
button {
padding: 10px 14px;
font-size: 14px;
background-color: #111827;
color: #fff;
border: 1px solid #111827;
border-radius: 10px;
cursor: pointer;
transition: background-color 120ms ease, border-color 120ms ease, opacity 120ms ease;
}
button:hover {
background-color: #0b1220;
border-color: #0b1220;
}
button:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.row {
display: grid;
grid-template-columns: 1fr;
gap: 12px;
}
@media (min-width: 860px) {
.row {
grid-template-columns: 1fr 1fr;
}
}
.actions {
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap;
margin-top: 14px;
}
.hint {
font-size: 13px;
color: #6b7280;
}
.status {
margin-top: 16px;
padding: 12px 12px;
border-radius: 10px;
border: 1px solid #e5e7eb;
background: #f9fafb;
color: #111827;
}
#result {
margin-top: 20px;
padding: 14px;
border-radius: 10px;
border: 1px solid #e5e7eb;
background: #fff;
}
details {
margin: 10px 0;
padding: 10px 12px;
border-radius: 10px;
border: 1px solid #e5e7eb;
background: #fafafa;
}
summary {
cursor: pointer;
font-weight: 600;
color: #111827;
}
pre {
margin: 10px 0 0;
padding: 12px;
border-radius: 10px;
background: #0b1220;
color: #e5e7eb;
overflow: auto;
font-size: 12px;
line-height: 1.45;
}
.pill {
display: inline-block;
padding: 2px 8px;
border-radius: 999px;
font-size: 12px;
border: 1px solid #e5e7eb;
background: #fff;
color: #111827;
}
.pill.ok { border-color: #86efac; background: #dcfce7; color: #166534; }
.pill.bad { border-color: #fca5a5; background: #fee2e2; color: #991b1b; }
.pill.warn { border-color: #fde68a; background: #fef3c7; color: #92400e; }
</style>
</head>
<body>
<h1 style="margin: 0 0 8px;">Tx Summary Tester</h1>
<div class="hint">
Fetches <span class="pill">GET</span> <code>/<txHash>/summary?just_request_body=true</code> from Blockscout and then
posts that JSON to the summary endpoint (<span class="pill">POST</span>) after adding <code>no_cache: true</code>.
</div>
<div class="row" style="margin-top: 18px;">
<div class="input-group">
<label for="blockscoutUrlInput">BLOCKSCOUT_API_URL</label>
<input id="blockscoutUrlInput" placeholder="https://eth.blockscout.com/api/v2/transactions" />
<div class="hint" style="margin-top: 6px;">Example: <code>https://eth.blockscout.com/api/v2/transactions</code></div>
</div>
<div class="input-group">
<label for="summaryUrlInput">SUMMARY_API_URL</label>
<input id="summaryUrlInput" placeholder="https://tx-summary.k8s-dev.blockscout.com/transactions/summary" />
<div class="hint" style="margin-top: 6px;">Example: <code>https://tx-summary.k8s-dev.blockscout.com/transactions/summary</code></div>
</div>
</div>
<div class="input-group">
<label for="txHashInput">Transaction hash</label>
<input id="txHashInput" placeholder="0x…" />
</div>
<div class="actions">
<button id="runBtn" type="button">Fetch & Summarize</button>
<button id="resetBtn" type="button" style="background:#fff;color:#111827;border-color:#d1d5db;">Reset defaults</button>
<span id="statusPill" class="pill">Idle</span>
<span class="hint" id="timingHint"></span>
</div>
<div class="status" id="statusBox" style="display:none;"></div>
<div id="result" aria-live="polite">
<details open>
<summary>Summary response</summary>
<pre id="summaryResponsePre">No data yet.</pre>
</details>
<details open>
<summary>Blockscout GET</summary>
<div class="hint" id="blockscoutRequestUrl"></div>
<pre id="blockscoutResponsePre">No data yet.</pre>
</details>
<details open>
<summary>Request body sent to Summary POST</summary>
<div class="hint" id="summaryRequestUrl"></div>
<pre id="summaryRequestPre">No data yet.</pre>
</details>
<details>
<summary>Logs</summary>
<pre id="logPre">Ready.</pre>
</details>
</div>
<script>
const DEFAULT_BLOCKSCOUT_API_URL = 'https://eth.blockscout.com/api/v2/transactions';
const DEFAULT_SUMMARY_API_URL = 'https://tx-summary.k8s-dev.blockscout.com/transactions/summary';
const LS_BLOCKSCOUT = 'tx_summary_tester:blockscout_api_url';
const LS_SUMMARY = 'tx_summary_tester:summary_api_url';
const LS_TXHASH = 'tx_summary_tester:tx_hash';
const els = {
blockscoutUrlInput: document.getElementById('blockscoutUrlInput'),
summaryUrlInput: document.getElementById('summaryUrlInput'),
txHashInput: document.getElementById('txHashInput'),
runBtn: document.getElementById('runBtn'),
resetBtn: document.getElementById('resetBtn'),
statusPill: document.getElementById('statusPill'),
timingHint: document.getElementById('timingHint'),
statusBox: document.getElementById('statusBox'),
blockscoutRequestUrl: document.getElementById('blockscoutRequestUrl'),
summaryRequestUrl: document.getElementById('summaryRequestUrl'),
blockscoutResponsePre: document.getElementById('blockscoutResponsePre'),
summaryRequestPre: document.getElementById('summaryRequestPre'),
summaryResponsePre: document.getElementById('summaryResponsePre'),
logPre: document.getElementById('logPre'),
};
function setStatus(kind, text, extra) {
els.statusPill.className = 'pill ' + (kind === 'ok' ? 'ok' : kind === 'bad' ? 'bad' : kind === 'warn' ? 'warn' : '');
els.statusPill.textContent = text;
if (extra) {
els.statusBox.style.display = 'block';
els.statusBox.textContent = extra;
} else {
els.statusBox.style.display = 'none';
els.statusBox.textContent = '';
}
}
function log(line) {
const ts = new Date().toISOString();
const current = els.logPre.textContent || '';
els.logPre.textContent = (current ? current + '\n' : '') + `[${ts}] ${line}`;
}
function prettyJson(value) {
try {
return JSON.stringify(value, null, 2);
} catch (_) {
return String(value);
}
}
function normalizeBaseUrl(url) {
return (url || '').trim().replace(/\/+$/, '');
}
async function readJsonOrText(response) {
const contentType = response.headers.get('content-type') || '';
if (contentType.includes('application/json')) {
try {
return { kind: 'json', value: await response.json() };
} catch (e) {
return { kind: 'text', value: await response.text() };
}
}
return { kind: 'text', value: await response.text() };
}
function loadDefaults() {
els.blockscoutUrlInput.value = localStorage.getItem(LS_BLOCKSCOUT) || DEFAULT_BLOCKSCOUT_API_URL;
els.summaryUrlInput.value = localStorage.getItem(LS_SUMMARY) || DEFAULT_SUMMARY_API_URL;
els.txHashInput.value = localStorage.getItem(LS_TXHASH) || '';
}
function saveInputs() {
localStorage.setItem(LS_BLOCKSCOUT, els.blockscoutUrlInput.value.trim());
localStorage.setItem(LS_SUMMARY, els.summaryUrlInput.value.trim());
localStorage.setItem(LS_TXHASH, els.txHashInput.value.trim());
}
function resetDefaults() {
els.blockscoutUrlInput.value = DEFAULT_BLOCKSCOUT_API_URL;
els.summaryUrlInput.value = DEFAULT_SUMMARY_API_URL;
els.txHashInput.value = '';
saveInputs();
setStatus('', 'Idle');
els.timingHint.textContent = '';
els.blockscoutRequestUrl.textContent = '';
els.summaryRequestUrl.textContent = '';
els.blockscoutResponsePre.textContent = 'No data yet.';
els.summaryRequestPre.textContent = 'No data yet.';
els.summaryResponsePre.textContent = 'No data yet.';
els.logPre.textContent = 'Ready.';
}
async function fetchAndSummarize() {
saveInputs();
const txHash = els.txHashInput.value.trim();
const blockscoutBase = normalizeBaseUrl(els.blockscoutUrlInput.value);
const summaryUrl = els.summaryUrlInput.value.trim();
if (!blockscoutBase) {
setStatus('bad', 'Missing URL', 'Please provide BLOCKSCOUT_API_URL.');
return;
}
if (!summaryUrl) {
setStatus('bad', 'Missing URL', 'Please provide SUMMARY_API_URL.');
return;
}
if (!txHash) {
setStatus('bad', 'Missing tx hash', 'Please provide a transaction hash.');
return;
}
if (!/^0x[a-fA-F0-9]{64}$/.test(txHash)) {
setStatus('warn', 'Tx hash looks odd', 'Expected a 0x-prefixed 32-byte hash (66 chars). I will still try.');
} else {
setStatus('', 'Ready');
}
els.runBtn.disabled = true;
els.resetBtn.disabled = true;
const started = performance.now();
els.timingHint.textContent = '';
try {
setStatus('', 'Fetching…');
log(`Fetching transaction data for ${txHash}…`);
const blockscoutUrl = `${blockscoutBase}/${txHash}/summary?just_request_body=true`;
els.blockscoutRequestUrl.textContent = blockscoutUrl;
const response = await fetch(blockscoutUrl, { method: 'GET' });
const parsed = await readJsonOrText(response);
els.blockscoutResponsePre.textContent =
`HTTP ${response.status}\n\n` + (parsed.kind === 'json' ? prettyJson(parsed.value) : String(parsed.value));
if (!response.ok) {
throw new Error(`Blockscout HTTP ${response.status}`);
}
if (parsed.kind !== 'json' || !parsed.value || typeof parsed.value !== 'object') {
throw new Error('Blockscout response is not JSON object (cannot POST to summary).');
}
// Mutate payload like your script
parsed.value.no_cache = true;
log('Sending to summary endpoint…');
setStatus('', 'Posting…');
els.summaryRequestUrl.textContent = summaryUrl;
els.summaryRequestPre.textContent = prettyJson(parsed.value);
const summaryResponse = await fetch(summaryUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(parsed.value),
});
const summaryParsed = await readJsonOrText(summaryResponse);
els.summaryResponsePre.textContent =
`HTTP ${summaryResponse.status}\n\n` +
(summaryParsed.kind === 'json' ? prettyJson(summaryParsed.value) : String(summaryParsed.value));
if (!summaryResponse.ok) {
log(`Summary endpoint failed: HTTP ${summaryResponse.status}`);
setStatus('bad', 'Summary failed', `Summary HTTP ${summaryResponse.status} (see response below).`);
return;
}
log('Done.');
setStatus('ok', 'Success');
} catch (error) {
const msg = error && error.message ? error.message : String(error);
log(`Error: ${msg}`);
// This often happens due to CORS in browsers
setStatus('bad', 'Error', msg);
} finally {
const ms = Math.round(performance.now() - started);
els.timingHint.textContent = `Last run: ${ms}ms`;
els.runBtn.disabled = false;
els.resetBtn.disabled = false;
}
}
// Init
loadDefaults();
setStatus('', 'Idle');
els.runBtn.addEventListener('click', fetchAndSummarize);
els.resetBtn.addEventListener('click', resetDefaults);
els.blockscoutUrlInput.addEventListener('change', saveInputs);
els.summaryUrlInput.addEventListener('change', saveInputs);
els.txHashInput.addEventListener('change', saveInputs);
els.txHashInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') fetchAndSummarize();
});
</script>
</body>
</html>