-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmodules.html
318 lines (290 loc) · 10.7 KB
/
modules.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
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
<html>
<head>
<title>Kadena Code Viewer</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
<link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/pact-lang-api-global.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.min.js" integrity="sha512-GoORoNnxst42zE3rYPj4bNBm0Q6ZRXKNH2D9nEmNvVF/z24ywVnijAWVi/09iBiVDQVf3UlZHpzhAJIdd9BXqw==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/mode-clojure.min.js" integrity="sha512-98A+a0mNRbC5aD1wC0SutvdbIkdEdhZTl7VZCDwJO3moIvChukHxGTkI7sZ0J+njnD6FgoCc/7ATLTJywVYA3g==" crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
function attachCell(tag, value, parentId, cellId){
var node = document.createElement(tag);
var textnode = document.createTextNode(value);
if (!document.getElementById(cellId)){
node.setAttribute("id", cellId);
node.appendChild(textnode);
document.getElementById(parentId).appendChild(node);
} else{
document.getElementById(cellId).textContent = value;
}
}
function urlParam (name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)')
.exec(window.location.search);
return (results !== null) ? results[1] || 0 : false;
}
var chainIds = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
var chainBal = {}
const creationTime = () => Math.round((new Date).getTime()/1000)-15;
//mkMeta takes in account name, chain id, gas price, gas limit, creation time, time-to-live
const dumMeta = (chainId) => Pact.lang.mkMeta("not-real", chainId, 0.00000001, 6000, creationTime(), 600)
async function getVersion(server){
try {
const res = await fetch(`https://${server}/info`);
const resJSON = await res.json();
const av = resJSON.nodeApiVersion;
const nv = resJSON.nodeVersion;
if (resJSON.nodeChains.length !== 10) {
const bh = resJSON.nodeGraphHistory[0][0]
const len = resJSON.nodeGraphHistory[0][1].length
const cut = await fetch(`https://${server}/chainweb/${av}/${nv}/cut`)
const cutJSON = await cut.json();
const h = cutJSON.height
if (h > bh) {
let cids = Array.from(Array(len).keys());
cids = cids.map(x => x.toString())
chainIds = cids;
} else {
chainIds = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
}
} else {
chainIds = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
}
return {
nv: nv
}
}
catch(e){
console.log(e)
attachCell("h4", "Unable to fetch from " + JSON.stringify(server), "total", `total-value`)
}
}
function restore(id, storage, qry) {
if (urlParam(qry)) {
document.getElementById(id).value=urlParam(qry);
return urlParam(qry);
} else if (localStorage.getItem(storage)) {
document.getElementById(id).value=localStorage.getItem(storage);
}
return false;
}
async function go () {
document.getElementById("minfo").style.display="none";
document.getElementById("result").style.display="block";
const server = document.getElementById('server').value;
const module = document.getElementById('module').value;
const chain = document.getElementById('chain').value;
const info = await getVersion(server);
const host = `https://${server}/chainweb/0.0/${info.nv}/chain/${chain}/pact`;
document.getElementById("module-field").className = "field"
document.getElementById("kadena-form").className = "ui form"
localStorage.setItem("kadena-module-server", document.getElementById('server').value);
localStorage.setItem("kadena-module", document.getElementById('module').value);
localStorage.setItem("kadena-chain", document.getElementById('chain').value);
await getCode(server,host,module,chain);
console.log("done");
if (urlParam("line")) {
var l = parseInt(urlParam("line"));
l = l > 0 ? l - 1 : 0;
await editor.scrollToLine(l,false,true,null);
editor.getSession().selection.moveCursorTo(l,0,false);
}
}
async function getCode (server, host, module, chainId) {
try {
const response = await Pact.fetch.local({
pactCode: `(describe-module "${module}")`,
meta: dumMeta(chainId)
}, host)
const result = response.result;
const resultElem = document.getElementById("result");
if (result.status==="success"){
resultElem.style.height = "600px";
resultElem.style.width = "800px";
editor.setValue(result.data.code);
editor.setReadOnly(true);
editor.resize();
editor.getSession().selection.clearSelection();
document.getElementById("minfo").style.display="table";
document.getElementById("minfo").style.width="600px";
resultElem.style.boxShadow="10px 10px 8px #888888";
resultElem.style.border="thin solid lightgrey";
document.getElementById("mhash").textContent=result.data.hash;
document.getElementById("mname").textContent=result.data.name;
document.getElementById("mblessed").textContent=JSON.stringify(result.data.blessed);
document.getElementById("mlink").textContent="Link"
document.getElementById("mlink").href=`?server=${server}&module=${module}&chain=${chainId}`
} else if (result.status==="failure"){
resultElem.textContent = result.error.message;
resultElem.className = "warning";
} else {
resultElem.textContent = "Request failed";
resultElem.className = "warning";
}
} catch(e){
console.log(e)
resultElem.textContent = "Request failed";
resultElem.className = "warning";
}
}
window.addEventListener('load', function (event) {
const s = restore("server","kadena-module-server","server");
const m = restore("module","kadena-module","module");
const c = restore("chain","kadena-chain","chain");
if (s && m && c) {
go();
}
}, false);
document.addEventListener('click', async function (event) {
chainBal = {}
if (!event.target.matches('#getcode')) return;
event.preventDefault();
go();
}, false);
</script>
</head>
<body>
<div id="main">
<div class="container">
<h1>Kadena Code Viewer</h1>
<div id="subhead">
<a class="headlink" href="index.html">Balance Checker</a>
<span class="headlink">Code Viewer</span>
</div>
<form id ="kadena-form"class="ui form">
<div id="node-field" class="field">
<label>Server</label>
<input type="text" id="server" placeholder="Enter Your Node Server">
</div>
<div id="chain-field" class="field">
<label>Chain ID</label>
<select name="chain" id="chain" placeholder="Enter Chain ID">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
</select>
</div>
<div id="module-field" class="field">
<label>Module Name</label>
<input type="text" id="module" placeholder="Enter Your Account Name">
<div id="acct-err" class="ui center error message">
<div class="header">Module name</div>
</div>
</div>
<button id="getcode" class="ui primary button">Get Code</button>
</form>
<div class="result">
<table id="data-table">
<tr><td><table id="minfo">
<tr><td class="ml">Name</td><td class="md" id="mname"></td></tr>
<tr><td class="ml">Hash</td><td class="md" id="mhash"></td></tr>
<tr><td class="ml">Blessed</td><td class="md" id="mblessed"></td></tr>
<tr><td class="ml">Share</td><td class="md"><a href="#" id="mlink"></a></td></tr>
</table></td></tr>
<tr><td><div id="result"></div></td></tr>
</table>
</div>
</div>
</body>
<style>
.container {
text-align: center;
margin-top: 20px;
}
.result {
margin-top: 20px;
}
.check-button {
margin-top: 15px;
}
.ui #server {
margin-top: 5px;
width: 300px;
}
.ui #chain {
margin-top: 5px;
width: 300px;
margin: auto;
}
.ui #module {
margin-top: 5px;
width: 300px;
}
.ui #acct-err {
margin-top: 5px;
width: 300px;
margin: auto;
font-size: 13px;
}
table#data-table {
margin-left:auto;
margin-right:auto;
}
table#data-table th{
text-align: center;
width: 100px;
}
table#data-table td{
text-align: left;
}
.result {
margin-left:auto;
margin-right:auto;
text-align:center;
}
#result {
width = 600px;
margin-left:auto;
margin-right:auto;
text-align:left;
padding: 10px;
height: 100%;
display: none;
}
#minfo {
width = 600px;
display: none;
}
#subhead {
margin-top: -10px;
margin-bottom: 10px;
}
.headlink {
padding: 1em;
}
span.headlink {
color: lightgrey;
}
.ml {
width: 100px;
color: grey;
}
.md {
width: auto;
}
</style>
<script>
var editor = ace.edit("result");
editor.session.setMode("ace/mode/clojure");
</script>
</html>