@taqueria/plugin-smartpy-legacy 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +73 -0
- package/index.d.ts +1 -0
- package/index.js +328 -0
- package/index.js.map +1 -0
- package/index.mjs +308 -0
- package/index.mjs.map +1 -0
- package/install.sh +128 -0
- package/package.json +78 -0
- package/smartpy-v0.16.0/smart-ts-cli.js +17 -0
- package/smartpy-v0.16.0/smart.js +348 -0
- package/smartpy-v0.16.0/smartpyc.js +274828 -0
- package/smartpy-v0.16.0/theme.js +251 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// Copyright 2019-2022 Smart Chain Arena LLC.
|
|
2
|
+
|
|
3
|
+
function copyMichelson(x) {
|
|
4
|
+
var range = document.createRange();
|
|
5
|
+
var children = x.parentNode.parentNode.childNodes;
|
|
6
|
+
children.forEach(function (child) {
|
|
7
|
+
if (child.nodeType != Node.TEXT_NODE) {
|
|
8
|
+
if (child.className.includes('michelson')) {
|
|
9
|
+
range.selectNode(child);
|
|
10
|
+
console.log(child);
|
|
11
|
+
window.getSelection().removeAllRanges();
|
|
12
|
+
window.getSelection().addRange(range);
|
|
13
|
+
document.execCommand('copy');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function copyMichelsonTextArea(x) {
|
|
20
|
+
document.getElementById(x).select();
|
|
21
|
+
document.execCommand('copy');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function openTabLazy(evt, id, global_id) {
|
|
25
|
+
var i, tabcontent, tablinks;
|
|
26
|
+
|
|
27
|
+
tabcontent = evt.currentTarget.parentNode.parentNode.childNodes;
|
|
28
|
+
for (i = 0; i < tabcontent.length; i++) {
|
|
29
|
+
if (tabcontent[i].className == 'tabcontent') tabcontent[i].style.display = 'none';
|
|
30
|
+
}
|
|
31
|
+
tablinks = evt.currentTarget.parentNode.childNodes;
|
|
32
|
+
for (i = 0; i < tablinks.length; i++) {
|
|
33
|
+
if (tablinks[i].nodeType != Node.TEXT_NODE) {
|
|
34
|
+
tablinks[i].className = tablinks[i].className.replace(' active', '');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
tablinks = evt.currentTarget.parentNode.parentNode.childNodes;
|
|
38
|
+
k = 0;
|
|
39
|
+
for (i = 0; i < tablinks.length; i++) {
|
|
40
|
+
if (tablinks[i].nodeType != Node.TEXT_NODE) {
|
|
41
|
+
if (id + 1 == k) {
|
|
42
|
+
tablinks[i].style.display = 'block';
|
|
43
|
+
lazy_tab = window.smartmlCtx.call_exn_handler('lazy_tab', id, global_id);
|
|
44
|
+
if (lazy_tab) tablinks[i].innerHTML = lazy_tab;
|
|
45
|
+
}
|
|
46
|
+
k += 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
evt.currentTarget.className += ' active';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function openTab(evt, name) {
|
|
54
|
+
var i, tabcontent, tablinks;
|
|
55
|
+
|
|
56
|
+
tabcontent = evt.currentTarget.parentNode.parentNode.childNodes;
|
|
57
|
+
for (i = 0; i < tabcontent.length; i++) {
|
|
58
|
+
if (tabcontent[i].className == 'tabcontent') tabcontent[i].style.display = 'none';
|
|
59
|
+
}
|
|
60
|
+
tablinks = evt.currentTarget.parentNode.childNodes;
|
|
61
|
+
for (i = 0; i < tablinks.length; i++) {
|
|
62
|
+
if (tablinks[i].nodeType != Node.TEXT_NODE) {
|
|
63
|
+
tablinks[i].className = tablinks[i].className.replace(' active', '');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
tablinks = evt.currentTarget.parentNode.parentNode.childNodes;
|
|
67
|
+
k = 0;
|
|
68
|
+
for (i = 0; i < tablinks.length; i++) {
|
|
69
|
+
if (tablinks[i].nodeType != Node.TEXT_NODE) {
|
|
70
|
+
if (name + 1 == k) tablinks[i].style.display = 'block';
|
|
71
|
+
k += 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
evt.currentTarget.className += ' active';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function initDefaultButtons() {
|
|
79
|
+
var defaults = document.getElementsByName('button_default');
|
|
80
|
+
var i;
|
|
81
|
+
for (i = 0; i < defaults.length; i++) {
|
|
82
|
+
defaults[i].click();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function ppInvocationResult(result) {
|
|
87
|
+
var returnMessage = '';
|
|
88
|
+
var originatedContract = '';
|
|
89
|
+
var hasError = false;
|
|
90
|
+
try {
|
|
91
|
+
console.log('Results:');
|
|
92
|
+
console.log(result);
|
|
93
|
+
if (result.hasOwnProperty('results')) {
|
|
94
|
+
result = result['results'];
|
|
95
|
+
}
|
|
96
|
+
if (result.hasOwnProperty('response')) {
|
|
97
|
+
result = JSON.parse(result['response']);
|
|
98
|
+
}
|
|
99
|
+
if (result.hasOwnProperty('errors')) {
|
|
100
|
+
return result.errors;
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(result) && result.length == 1) {
|
|
103
|
+
result = result[0];
|
|
104
|
+
}
|
|
105
|
+
if (result.hasOwnProperty('contents')) {
|
|
106
|
+
var contents = result['contents'];
|
|
107
|
+
contents.forEach(function (content) {
|
|
108
|
+
var metadata = content.metadata;
|
|
109
|
+
var operation_result = metadata.operation_result;
|
|
110
|
+
var status = operation_result['status'];
|
|
111
|
+
returnMessage += 'Status: ' + status + '\n';
|
|
112
|
+
if (status == 'failed' || status == 'backtracked') {
|
|
113
|
+
hasError = true;
|
|
114
|
+
operation_result.errors.forEach(function (error) {
|
|
115
|
+
returnMessage += '\nError: ' + error.id;
|
|
116
|
+
if (error['id'].endsWith('script_rejected')) {
|
|
117
|
+
try {
|
|
118
|
+
returnMessage += '\n ' + error['with'].string;
|
|
119
|
+
} catch (__error) {
|
|
120
|
+
console.log(error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (error['id'].endsWith('invalid_contract_notation')) {
|
|
124
|
+
try {
|
|
125
|
+
returnMessage += '\n ' + error['notation'];
|
|
126
|
+
} catch (__error) {
|
|
127
|
+
console.log(error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (error['id'].endsWith('storage_exhausted.operation')) {
|
|
131
|
+
returnMessage += ' \n (please increase storage limit)';
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
operation_result.originated_contracts.forEach(function (originated) {
|
|
137
|
+
originatedContract = originated;
|
|
138
|
+
returnMessage += ' \n\nOriginatedContract: ' + originated;
|
|
139
|
+
});
|
|
140
|
+
} catch (__error) {
|
|
141
|
+
hasError = true;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
} else if (result.hasOwnProperty('kind') && result.hasOwnProperty('id')) {
|
|
145
|
+
hasError = true;
|
|
146
|
+
returnMessage += 'Error: ' + result['id'];
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.log(error);
|
|
150
|
+
hasError = true;
|
|
151
|
+
returnMessage += '\n(Error while parsing result)';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
returnMessage += '\n\n\nDetails:\n\n' + JSON.stringify(result, null, 2);
|
|
155
|
+
return { message: returnMessage, contract: originatedContract, hasError: hasError };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
class SmartmlCtx {
|
|
159
|
+
constructor() {}
|
|
160
|
+
call(f, ...rest) {
|
|
161
|
+
try {
|
|
162
|
+
return exports[f](...rest);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
var result = 0;
|
|
165
|
+
try {
|
|
166
|
+
result = this.call('stringOfException', true, error);
|
|
167
|
+
} catch (_error) {
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
if (typeof window.toException === 'function' && !window.location.pathname.includes('ts-ide'))
|
|
171
|
+
throw toException(result);
|
|
172
|
+
else throw result;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
call_exn(f, ...rest) {
|
|
176
|
+
return exports[f](...rest);
|
|
177
|
+
}
|
|
178
|
+
call_exn_handler(f, ...rest) {
|
|
179
|
+
try {
|
|
180
|
+
return exports[f](...rest);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
try {
|
|
183
|
+
var result = '';
|
|
184
|
+
try {
|
|
185
|
+
result = this.call('stringOfException', false, error);
|
|
186
|
+
} catch (_error) {
|
|
187
|
+
showErrorPre(error);
|
|
188
|
+
}
|
|
189
|
+
console.log(result);
|
|
190
|
+
showErrorPre(result);
|
|
191
|
+
} catch (_error) {
|
|
192
|
+
showErrorPre(error);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
class SmartmlJS {
|
|
199
|
+
constructor(contract) {
|
|
200
|
+
this.ctx = new SmartmlCtx();
|
|
201
|
+
this.time = 0;
|
|
202
|
+
if (contract != null) {
|
|
203
|
+
//console.log(contract);
|
|
204
|
+
//console.log(contract.exp);
|
|
205
|
+
this.contract = this.ctx.call('importContract', contract.exp());
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
smartpy() {
|
|
210
|
+
return this.ctx.call('string_of_contract', this.contract);
|
|
211
|
+
}
|
|
212
|
+
string_of_value(s) {
|
|
213
|
+
return this.ctx.call('string_of_value', s);
|
|
214
|
+
}
|
|
215
|
+
html(self) {
|
|
216
|
+
return this.ctx.call('htmlContract', this.contract);
|
|
217
|
+
}
|
|
218
|
+
fullHtml() {
|
|
219
|
+
var def = 'Stripped';
|
|
220
|
+
var onlyDefault = false;
|
|
221
|
+
return this.ctx.call('fullHtmlContract', def, onlyDefault, this.contract);
|
|
222
|
+
}
|
|
223
|
+
messageEffects(result) {
|
|
224
|
+
return this.ctx.call('messageEffects', result);
|
|
225
|
+
}
|
|
226
|
+
messageHtml(result) {
|
|
227
|
+
return this.ctx.call('messageHtml', result);
|
|
228
|
+
}
|
|
229
|
+
messageErrors(result) {
|
|
230
|
+
return this.ctx.call('messageErrors', result);
|
|
231
|
+
}
|
|
232
|
+
messageContract(message) {
|
|
233
|
+
return this.ctx.call('messageContract', message);
|
|
234
|
+
}
|
|
235
|
+
listLength(l) {
|
|
236
|
+
return this.ctx.call('List.length', l);
|
|
237
|
+
}
|
|
238
|
+
listNth(l, n) {
|
|
239
|
+
return this.ctx.call('List.nth', l, n);
|
|
240
|
+
}
|
|
241
|
+
list_to_ocaml(l) {
|
|
242
|
+
result = this.ctx.call('list.[]');
|
|
243
|
+
for (var x in reversed(l)) {
|
|
244
|
+
result = this.ctx.call('list.append', x, result);
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
list(l) {
|
|
249
|
+
r = range(0, this.listLength(l));
|
|
250
|
+
return r.map((i) => this.listNth(l, i));
|
|
251
|
+
}
|
|
252
|
+
ocamlString(s) {
|
|
253
|
+
return this.ctx.call('string', s);
|
|
254
|
+
}
|
|
255
|
+
of_ocamlString(s) {
|
|
256
|
+
return this.ctx.call('of_ocamlString', s);
|
|
257
|
+
}
|
|
258
|
+
pair(l1, l2) {
|
|
259
|
+
return this.ctx.call('pair', l1, l2);
|
|
260
|
+
}
|
|
261
|
+
list_empty(self) {
|
|
262
|
+
return this.ctx.call('list.[]');
|
|
263
|
+
}
|
|
264
|
+
list_unit(x) {
|
|
265
|
+
return this.ctx.call('list.unit', x);
|
|
266
|
+
}
|
|
267
|
+
list_concat(l1, l2) {
|
|
268
|
+
return this.ctx.call('list.concat', l1, l2);
|
|
269
|
+
}
|
|
270
|
+
importValue(value) {
|
|
271
|
+
if (isinstance(value, str)) return this.importSimpleValue('string', value);
|
|
272
|
+
if (isinstance(value, int)) return this.importSimpleValue('int', str(value));
|
|
273
|
+
if (isinstance(value, Record)) return this.ctx.call('importValue', value.export());
|
|
274
|
+
if (isinstance(value, SpExpr)) return this.ctx.call('importValue', value.export());
|
|
275
|
+
throw 'Unsupported type for value ${value}';
|
|
276
|
+
}
|
|
277
|
+
importSimpleValue(t, s) {
|
|
278
|
+
return this.ctx.call('importSimpleValue', t, s);
|
|
279
|
+
}
|
|
280
|
+
getVariableType(name) {
|
|
281
|
+
return SmartmlType(this.ctx.call('getVariableType', this.contract, name));
|
|
282
|
+
}
|
|
283
|
+
setTime(time) {
|
|
284
|
+
this.time = time;
|
|
285
|
+
return 'Setting time to [%s].<br>' % time;
|
|
286
|
+
}
|
|
287
|
+
// execMessage(message, sender = "", **kargs){
|
|
288
|
+
// kargs_values = [(name, this.importValue(x)) for (name, x) in sorted(kargs.items())]
|
|
289
|
+
// kargs_values_pp = [(name, this.string_of_value(x)) for (name, x) in kargs_values]
|
|
290
|
+
// kargs_ml = this.list_empty()
|
|
291
|
+
// for (name, value) in kargs_values:
|
|
292
|
+
// kargs_ml = this.list_concat(kargs_ml, this.list_unit(this.pair(this.ocamlString(name), value)))
|
|
293
|
+
// result = this.ctx.call("execMessage", sender, this.time, this.contract, message, kargs_ml)
|
|
294
|
+
// errors = this.messageErrors(result)
|
|
295
|
+
// errors = [this.of_ocamlString(x) for x in this.list(errors)]
|
|
296
|
+
// effects = this.messageEffects(result)
|
|
297
|
+
// effects = [this.of_ocamlString(x) for x in this.list(effects)]
|
|
298
|
+
// if len(errors) == 0:
|
|
299
|
+
// this.contract = this.messageContract(result)
|
|
300
|
+
// return ExecMessage(this.messageHtml(result), errors, effects);
|
|
301
|
+
// }
|
|
302
|
+
ppMich(mich, indent) {
|
|
303
|
+
return this.ctx.call('mich.pp', indent, mich);
|
|
304
|
+
}
|
|
305
|
+
ppMichStorage(mich, indent = '') {
|
|
306
|
+
return this.ctx.call('mich.ppStorage', indent, mich);
|
|
307
|
+
}
|
|
308
|
+
ppMichStorageHtml(storage, t) {
|
|
309
|
+
return this.ctx.call('mich.htmlStorage', storage, t);
|
|
310
|
+
}
|
|
311
|
+
ppMichInfos(address, balance, counter, manager, spendable) {
|
|
312
|
+
return this.ctx.call('mich.htmlInfos', address, balance, counter, manager, spendable);
|
|
313
|
+
}
|
|
314
|
+
ppMichStorageType(storageType) {
|
|
315
|
+
return this.ctx.call('mich.htmlType', storageType);
|
|
316
|
+
}
|
|
317
|
+
parseMich(code) {
|
|
318
|
+
if (isinstance(code, str)) return this.ctx.call('mich.string', code);
|
|
319
|
+
if (hasattr(code, 'int')) return this.ctx.call('mich.int', code.int);
|
|
320
|
+
if (hasattr(code, 'string')) return this.ctx.call('mich.string', code.string);
|
|
321
|
+
if (!hasattr(code, 'prim')) {
|
|
322
|
+
//#alert(str(code) + " " + str(dir(code)))
|
|
323
|
+
seq = code.map((c) => this.parseMich(c));
|
|
324
|
+
seq = this.list_to_ocaml(seq);
|
|
325
|
+
return this.ctx.call('mich.sequence', seq);
|
|
326
|
+
}
|
|
327
|
+
if (hasattr(code, 'args')) args = code.args.map((arg) => this.parseMich(arg));
|
|
328
|
+
else args = [];
|
|
329
|
+
argsML = this.list_to_ocaml(args);
|
|
330
|
+
if (hasattr(code, 'annots')) {
|
|
331
|
+
annots = code.annots;
|
|
332
|
+
window.console.log(annots);
|
|
333
|
+
} else {
|
|
334
|
+
annots = [];
|
|
335
|
+
}
|
|
336
|
+
annots = this.list_to_ocaml(annots.map((x) => this.ocamlString(x)));
|
|
337
|
+
return this.ctx.call('mich.primitive', code.prim, annots, argsML);
|
|
338
|
+
}
|
|
339
|
+
static hashString(s) {
|
|
340
|
+
return hashed(window.smartmlCtx.call('hashString', s));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
smartmlCtx = new SmartmlCtx();
|
|
345
|
+
in_browser = true;
|
|
346
|
+
function buildSmartlmJS(x) {
|
|
347
|
+
return new SmartmlJS(x);
|
|
348
|
+
}
|