stxer 0.4.2 → 0.4.5
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/dist/clarity-api.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/stxer.cjs.development.js +684 -829
- package/dist/stxer.cjs.development.js.map +1 -1
- package/dist/stxer.cjs.production.min.js +1 -1
- package/dist/stxer.cjs.production.min.js.map +1 -1
- package/dist/stxer.esm.js +687 -832
- package/dist/stxer.esm.js.map +1 -1
- package/package.json +15 -14
- package/src/BatchAPI.ts +7 -4
- package/src/BatchProcessor.ts +2 -2
- package/src/clarity-api.ts +28 -15
- package/src/index.ts +1 -1
- package/src/sample/counter.ts +20 -24
- package/src/sample/read.ts +15 -18
- package/src/simulation.ts +104 -57
|
@@ -63,306 +63,130 @@ function _extends() {
|
|
|
63
63
|
return n;
|
|
64
64
|
}, _extends.apply(null, arguments);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
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
|
-
return o(a, "_invoke", {
|
|
101
|
-
value: makeInvokeMethod(t, r, c)
|
|
102
|
-
}), a;
|
|
103
|
-
}
|
|
104
|
-
function tryCatch(t, e, r) {
|
|
105
|
-
try {
|
|
106
|
-
return {
|
|
107
|
-
type: "normal",
|
|
108
|
-
arg: t.call(e, r)
|
|
109
|
-
};
|
|
110
|
-
} catch (t) {
|
|
111
|
-
return {
|
|
112
|
-
type: "throw",
|
|
113
|
-
arg: t
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
e.wrap = wrap;
|
|
118
|
-
var h = "suspendedStart",
|
|
119
|
-
l = "suspendedYield",
|
|
120
|
-
f = "executing",
|
|
121
|
-
s = "completed",
|
|
122
|
-
y = {};
|
|
123
|
-
function Generator() {}
|
|
124
|
-
function GeneratorFunction() {}
|
|
125
|
-
function GeneratorFunctionPrototype() {}
|
|
126
|
-
var p = {};
|
|
127
|
-
define(p, a, function () {
|
|
128
|
-
return this;
|
|
129
|
-
});
|
|
130
|
-
var d = Object.getPrototypeOf,
|
|
131
|
-
v = d && d(d(values([])));
|
|
132
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
133
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
134
|
-
function defineIteratorMethods(t) {
|
|
135
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
136
|
-
define(t, e, function (t) {
|
|
137
|
-
return this._invoke(e, t);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
function AsyncIterator(t, e) {
|
|
142
|
-
function invoke(r, o, i, a) {
|
|
143
|
-
var c = tryCatch(t[r], t, o);
|
|
144
|
-
if ("throw" !== c.type) {
|
|
145
|
-
var u = c.arg,
|
|
146
|
-
h = u.value;
|
|
147
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
148
|
-
invoke("next", t, i, a);
|
|
149
|
-
}, function (t) {
|
|
150
|
-
invoke("throw", t, i, a);
|
|
151
|
-
}) : e.resolve(h).then(function (t) {
|
|
152
|
-
u.value = t, i(u);
|
|
153
|
-
}, function (t) {
|
|
154
|
-
return invoke("throw", t, i, a);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
a(c.arg);
|
|
158
|
-
}
|
|
159
|
-
var r;
|
|
160
|
-
o(this, "_invoke", {
|
|
161
|
-
value: function (t, n) {
|
|
162
|
-
function callInvokeWithMethodAndArg() {
|
|
163
|
-
return new e(function (e, r) {
|
|
164
|
-
invoke(t, n, e, r);
|
|
165
|
-
});
|
|
66
|
+
function _regenerator() {
|
|
67
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
68
|
+
var e,
|
|
69
|
+
t,
|
|
70
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
71
|
+
n = r.iterator || "@@iterator",
|
|
72
|
+
o = r.toStringTag || "@@toStringTag";
|
|
73
|
+
function i(r, n, o, i) {
|
|
74
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
75
|
+
u = Object.create(c.prototype);
|
|
76
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
77
|
+
var i,
|
|
78
|
+
c,
|
|
79
|
+
u,
|
|
80
|
+
f = 0,
|
|
81
|
+
p = o || [],
|
|
82
|
+
y = !1,
|
|
83
|
+
G = {
|
|
84
|
+
p: 0,
|
|
85
|
+
n: 0,
|
|
86
|
+
v: e,
|
|
87
|
+
a: d,
|
|
88
|
+
f: d.bind(e, 4),
|
|
89
|
+
d: function (t, r) {
|
|
90
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
function d(r, n) {
|
|
94
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
95
|
+
var o,
|
|
96
|
+
i = p[t],
|
|
97
|
+
d = G.p,
|
|
98
|
+
l = i[2];
|
|
99
|
+
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
166
100
|
}
|
|
167
|
-
|
|
101
|
+
if (o || r > 1) return a;
|
|
102
|
+
throw y = !0, n;
|
|
168
103
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
104
|
+
return function (o, p, l) {
|
|
105
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
106
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
107
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
108
|
+
try {
|
|
109
|
+
if (f = 2, i) {
|
|
110
|
+
if (c || (o = "next"), t = i[o]) {
|
|
111
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
112
|
+
if (!t.done) return t;
|
|
113
|
+
u = t.value, c < 2 && (c = 0);
|
|
114
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
115
|
+
i = e;
|
|
116
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
117
|
+
} catch (t) {
|
|
118
|
+
i = e, c = 1, u = t;
|
|
119
|
+
} finally {
|
|
120
|
+
f = 1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
177
123
|
return {
|
|
178
124
|
value: t,
|
|
179
|
-
done:
|
|
125
|
+
done: y
|
|
180
126
|
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
var c = n.delegate;
|
|
184
|
-
if (c) {
|
|
185
|
-
var u = maybeInvokeDelegate(c, n);
|
|
186
|
-
if (u) {
|
|
187
|
-
if (u === y) continue;
|
|
188
|
-
return u;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
192
|
-
if (o === h) throw o = s, n.arg;
|
|
193
|
-
n.dispatchException(n.arg);
|
|
194
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
195
|
-
o = f;
|
|
196
|
-
var p = tryCatch(e, r, n);
|
|
197
|
-
if ("normal" === p.type) {
|
|
198
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
199
|
-
return {
|
|
200
|
-
value: p.arg,
|
|
201
|
-
done: n.done
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
127
|
+
};
|
|
128
|
+
}(r, o, i), !0), u;
|
|
207
129
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
130
|
+
var a = {};
|
|
131
|
+
function Generator() {}
|
|
132
|
+
function GeneratorFunction() {}
|
|
133
|
+
function GeneratorFunctionPrototype() {}
|
|
134
|
+
t = Object.getPrototypeOf;
|
|
135
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
136
|
+
return this;
|
|
137
|
+
}), t),
|
|
138
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
139
|
+
function f(e) {
|
|
140
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
216
141
|
}
|
|
217
|
-
function
|
|
218
|
-
|
|
219
|
-
|
|
142
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
143
|
+
return this;
|
|
144
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
145
|
+
return "[object Generator]";
|
|
146
|
+
}), (_regenerator = function () {
|
|
147
|
+
return {
|
|
148
|
+
w: i,
|
|
149
|
+
m: f
|
|
220
150
|
};
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
tryLoc: "root"
|
|
230
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
151
|
+
})();
|
|
152
|
+
}
|
|
153
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
154
|
+
var i = Object.defineProperty;
|
|
155
|
+
try {
|
|
156
|
+
i({}, "", {});
|
|
157
|
+
} catch (e) {
|
|
158
|
+
i = 0;
|
|
231
159
|
}
|
|
232
|
-
function
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (!isNaN(e.length)) {
|
|
238
|
-
var o = -1,
|
|
239
|
-
i = function next() {
|
|
240
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
241
|
-
return next.value = t, next.done = !0, next;
|
|
242
|
-
};
|
|
243
|
-
return i.next = i;
|
|
244
|
-
}
|
|
160
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
161
|
+
function o(r, n) {
|
|
162
|
+
_regeneratorDefine(e, r, function (e) {
|
|
163
|
+
return this._invoke(r, n, e);
|
|
164
|
+
});
|
|
245
165
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
void 0 === i && (i = Promise);
|
|
267
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
268
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
269
|
-
return t.done ? t.value : a.next();
|
|
270
|
-
});
|
|
271
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
272
|
-
return this;
|
|
273
|
-
}), define(g, "toString", function () {
|
|
274
|
-
return "[object Generator]";
|
|
275
|
-
}), e.keys = function (t) {
|
|
276
|
-
var e = Object(t),
|
|
277
|
-
r = [];
|
|
278
|
-
for (var n in e) r.push(n);
|
|
279
|
-
return r.reverse(), function next() {
|
|
280
|
-
for (; r.length;) {
|
|
281
|
-
var t = r.pop();
|
|
282
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
166
|
+
r ? i ? i(e, r, {
|
|
167
|
+
value: n,
|
|
168
|
+
enumerable: !t,
|
|
169
|
+
configurable: !t,
|
|
170
|
+
writable: !t
|
|
171
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
172
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
173
|
+
}
|
|
174
|
+
function _regeneratorValues(e) {
|
|
175
|
+
if (null != e) {
|
|
176
|
+
var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"],
|
|
177
|
+
r = 0;
|
|
178
|
+
if (t) return t.call(e);
|
|
179
|
+
if ("function" == typeof e.next) return e;
|
|
180
|
+
if (!isNaN(e.length)) return {
|
|
181
|
+
next: function () {
|
|
182
|
+
return e && r >= e.length && (e = void 0), {
|
|
183
|
+
value: e && e[r++],
|
|
184
|
+
done: !e
|
|
185
|
+
};
|
|
283
186
|
}
|
|
284
|
-
return next.done = !0, next;
|
|
285
187
|
};
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
reset: function (e) {
|
|
289
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
290
|
-
},
|
|
291
|
-
stop: function () {
|
|
292
|
-
this.done = !0;
|
|
293
|
-
var t = this.tryEntries[0].completion;
|
|
294
|
-
if ("throw" === t.type) throw t.arg;
|
|
295
|
-
return this.rval;
|
|
296
|
-
},
|
|
297
|
-
dispatchException: function (e) {
|
|
298
|
-
if (this.done) throw e;
|
|
299
|
-
var r = this;
|
|
300
|
-
function handle(n, o) {
|
|
301
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
302
|
-
}
|
|
303
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
304
|
-
var i = this.tryEntries[o],
|
|
305
|
-
a = i.completion;
|
|
306
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
307
|
-
if (i.tryLoc <= this.prev) {
|
|
308
|
-
var c = n.call(i, "catchLoc"),
|
|
309
|
-
u = n.call(i, "finallyLoc");
|
|
310
|
-
if (c && u) {
|
|
311
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
312
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
313
|
-
} else if (c) {
|
|
314
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
315
|
-
} else {
|
|
316
|
-
if (!u) throw Error("try statement without catch or finally");
|
|
317
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
abrupt: function (t, e) {
|
|
323
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
324
|
-
var o = this.tryEntries[r];
|
|
325
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
326
|
-
var i = o;
|
|
327
|
-
break;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
331
|
-
var a = i ? i.completion : {};
|
|
332
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
333
|
-
},
|
|
334
|
-
complete: function (t, e) {
|
|
335
|
-
if ("throw" === t.type) throw t.arg;
|
|
336
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
337
|
-
},
|
|
338
|
-
finish: function (t) {
|
|
339
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
340
|
-
var r = this.tryEntries[e];
|
|
341
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
342
|
-
}
|
|
343
|
-
},
|
|
344
|
-
catch: function (t) {
|
|
345
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
346
|
-
var r = this.tryEntries[e];
|
|
347
|
-
if (r.tryLoc === t) {
|
|
348
|
-
var n = r.completion;
|
|
349
|
-
if ("throw" === n.type) {
|
|
350
|
-
var o = n.arg;
|
|
351
|
-
resetTryEntry(r);
|
|
352
|
-
}
|
|
353
|
-
return o;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
throw Error("illegal catch attempt");
|
|
357
|
-
},
|
|
358
|
-
delegateYield: function (e, r, n) {
|
|
359
|
-
return this.delegate = {
|
|
360
|
-
iterator: values(e),
|
|
361
|
-
resultName: r,
|
|
362
|
-
nextLoc: n
|
|
363
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
364
|
-
}
|
|
365
|
-
}, e;
|
|
188
|
+
}
|
|
189
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
366
190
|
}
|
|
367
191
|
function _unsupportedIterableToArray(r, a) {
|
|
368
192
|
if (r) {
|
|
@@ -389,11 +213,11 @@ function batchRead(_x, _x2) {
|
|
|
389
213
|
return _batchRead.apply(this, arguments);
|
|
390
214
|
}
|
|
391
215
|
function _batchRead() {
|
|
392
|
-
_batchRead = _asyncToGenerator(/*#__PURE__*/
|
|
216
|
+
_batchRead = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(reads, options) {
|
|
393
217
|
var _options$stxerApi;
|
|
394
218
|
var ibh, payload, _iterator2, _step2, variable, _iterator3, _step3, map, _iterator4, _step4, ro, url, data, text, rs;
|
|
395
|
-
return
|
|
396
|
-
while (1) switch (_context.
|
|
219
|
+
return _regenerator().w(function (_context) {
|
|
220
|
+
while (1) switch (_context.n) {
|
|
397
221
|
case 0:
|
|
398
222
|
if (options === void 0) {
|
|
399
223
|
options = {};
|
|
@@ -426,7 +250,7 @@ function _batchRead() {
|
|
|
426
250
|
}
|
|
427
251
|
}
|
|
428
252
|
url = ((_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API) + "/sidecar/v2/batch";
|
|
429
|
-
_context.
|
|
253
|
+
_context.n = 1;
|
|
430
254
|
return fetch(url, {
|
|
431
255
|
method: 'POST',
|
|
432
256
|
body: JSON.stringify(payload),
|
|
@@ -434,526 +258,77 @@ function _batchRead() {
|
|
|
434
258
|
'Content-Type': 'application/json'
|
|
435
259
|
}
|
|
436
260
|
});
|
|
437
|
-
case
|
|
438
|
-
data = _context.
|
|
439
|
-
_context.
|
|
261
|
+
case 1:
|
|
262
|
+
data = _context.v;
|
|
263
|
+
_context.n = 2;
|
|
440
264
|
return data.text();
|
|
441
|
-
case
|
|
442
|
-
text = _context.
|
|
265
|
+
case 2:
|
|
266
|
+
text = _context.v;
|
|
443
267
|
if (!(!text.includes('Ok') && !text.includes('Err'))) {
|
|
444
|
-
_context.
|
|
268
|
+
_context.n = 3;
|
|
445
269
|
break;
|
|
446
270
|
}
|
|
447
271
|
throw new Error("Requesting batch reads failed: " + text + ", url: " + url + ", payload: " + JSON.stringify(payload));
|
|
448
|
-
case
|
|
272
|
+
case 3:
|
|
449
273
|
rs = JSON.parse(text);
|
|
450
|
-
return _context.
|
|
274
|
+
return _context.a(2, {
|
|
451
275
|
tip: rs.tip,
|
|
452
276
|
vars: convertResults(rs.vars),
|
|
453
277
|
maps: convertResults(rs.maps),
|
|
454
278
|
readonly: convertResults(rs.readonly)
|
|
455
279
|
});
|
|
456
|
-
case 17:
|
|
457
|
-
case "end":
|
|
458
|
-
return _context.stop();
|
|
459
280
|
}
|
|
460
281
|
}, _callee);
|
|
461
282
|
}));
|
|
462
283
|
return _batchRead.apply(this, arguments);
|
|
463
284
|
}
|
|
464
285
|
|
|
465
|
-
function
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
code = _ref.code;
|
|
475
|
-
var _contract_id$split = contract_id.split('.'),
|
|
476
|
-
contract_address = _contract_id$split[0],
|
|
477
|
-
contract_name = _contract_id$split[1];
|
|
478
|
-
// type 1: eval arbitrary code inside a contract
|
|
479
|
-
return transactions.tupleCV({
|
|
480
|
-
type: transactions.uintCV(1),
|
|
481
|
-
data: transactions.bufferCV(transactions.serializeCVBytes(transactions.tupleCV({
|
|
482
|
-
contract: transactions.contractPrincipalCV(contract_address, contract_name),
|
|
483
|
-
code: transactions.stringAsciiCV(code)
|
|
484
|
-
})))
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
function runSimulation(_x, _x2, _x3, _x4) {
|
|
488
|
-
return _runSimulation.apply(this, arguments);
|
|
489
|
-
}
|
|
490
|
-
function _runSimulation() {
|
|
491
|
-
_runSimulation = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(apiEndpoint, block_hash, block_height, txs) {
|
|
492
|
-
var header, heightBytes, view, hashHex, matches, hashBytes, txBytes, totalLength, body, offset, _iterator3, _step4, tx, rs;
|
|
493
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
494
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
495
|
-
case 0:
|
|
496
|
-
// Convert 'sim-v1' to Uint8Array
|
|
497
|
-
header = new TextEncoder().encode('sim-v1'); // Create 8 bytes for block height
|
|
498
|
-
heightBytes = new Uint8Array(8); // Convert block height to bytes
|
|
499
|
-
view = new DataView(heightBytes.buffer);
|
|
500
|
-
view.setBigUint64(0, BigInt(block_height), false); // false for big-endian
|
|
501
|
-
// Convert block hash to bytes
|
|
502
|
-
hashHex = block_hash.startsWith('0x') ? block_hash.substring(2) : block_hash; // Replace non-null assertion with null check
|
|
503
|
-
matches = hashHex.match(/.{1,2}/g);
|
|
504
|
-
if (matches) {
|
|
505
|
-
_context5.next = 8;
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
throw new Error('Invalid block hash format');
|
|
509
|
-
case 8:
|
|
510
|
-
hashBytes = new Uint8Array(matches.map(function (_byte) {
|
|
511
|
-
return Number.parseInt(_byte, 16);
|
|
512
|
-
})); // Convert transactions to bytes
|
|
513
|
-
txBytes = txs.map(function (t) {
|
|
514
|
-
return 'contract_id' in t && 'code' in t ? runEval(t) : runTx(t);
|
|
515
|
-
}).map(function (t) {
|
|
516
|
-
return transactions.serializeCVBytes(t);
|
|
517
|
-
}); // Combine all byte arrays
|
|
518
|
-
totalLength = header.length + heightBytes.length + hashBytes.length + txBytes.reduce(function (acc, curr) {
|
|
519
|
-
return acc + curr.length;
|
|
520
|
-
}, 0);
|
|
521
|
-
body = new Uint8Array(totalLength);
|
|
522
|
-
offset = 0;
|
|
523
|
-
body.set(header, offset);
|
|
524
|
-
offset += header.length;
|
|
525
|
-
body.set(heightBytes, offset);
|
|
526
|
-
offset += heightBytes.length;
|
|
527
|
-
body.set(hashBytes, offset);
|
|
528
|
-
offset += hashBytes.length;
|
|
529
|
-
for (_iterator3 = _createForOfIteratorHelperLoose(txBytes); !(_step4 = _iterator3()).done;) {
|
|
530
|
-
tx = _step4.value;
|
|
531
|
-
body.set(tx, offset);
|
|
532
|
-
offset += tx.length;
|
|
533
|
-
}
|
|
534
|
-
_context5.next = 22;
|
|
535
|
-
return fetch(apiEndpoint, {
|
|
536
|
-
method: 'POST',
|
|
537
|
-
body: body
|
|
538
|
-
}).then(/*#__PURE__*/function () {
|
|
539
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(rs) {
|
|
540
|
-
var response;
|
|
541
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
542
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
543
|
-
case 0:
|
|
544
|
-
_context4.next = 2;
|
|
545
|
-
return rs.text();
|
|
546
|
-
case 2:
|
|
547
|
-
response = _context4.sent;
|
|
548
|
-
if (response.startsWith('{')) {
|
|
549
|
-
_context4.next = 5;
|
|
550
|
-
break;
|
|
551
|
-
}
|
|
552
|
-
throw new Error("failed to submit simulation: " + response);
|
|
553
|
-
case 5:
|
|
554
|
-
return _context4.abrupt("return", JSON.parse(response));
|
|
555
|
-
case 6:
|
|
556
|
-
case "end":
|
|
557
|
-
return _context4.stop();
|
|
558
|
-
}
|
|
559
|
-
}, _callee4);
|
|
560
|
-
}));
|
|
561
|
-
return function (_x6) {
|
|
562
|
-
return _ref3.apply(this, arguments);
|
|
563
|
-
};
|
|
564
|
-
}());
|
|
565
|
-
case 22:
|
|
566
|
-
rs = _context5.sent;
|
|
567
|
-
return _context5.abrupt("return", rs.id);
|
|
568
|
-
case 24:
|
|
569
|
-
case "end":
|
|
570
|
-
return _context5.stop();
|
|
571
|
-
}
|
|
572
|
-
}, _callee5);
|
|
573
|
-
}));
|
|
574
|
-
return _runSimulation.apply(this, arguments);
|
|
575
|
-
}
|
|
576
|
-
var SimulationBuilder = /*#__PURE__*/function () {
|
|
577
|
-
function SimulationBuilder(options) {
|
|
578
|
-
var _options$network, _options$apiEndpoint, _options$stacksNodeAP;
|
|
579
|
-
if (options === void 0) {
|
|
580
|
-
options = {};
|
|
581
|
-
}
|
|
582
|
-
this.apiEndpoint = void 0;
|
|
583
|
-
this.stacksNodeAPI = void 0;
|
|
584
|
-
this.network = void 0;
|
|
585
|
-
// biome-ignore lint/style/useNumberNamespace: <explanation>
|
|
586
|
-
this.block = NaN;
|
|
587
|
-
this.sender = '';
|
|
588
|
-
this.steps = [];
|
|
589
|
-
this.network = (_options$network = options.network) != null ? _options$network : 'mainnet';
|
|
590
|
-
var isTestnet = this.network === 'testnet';
|
|
591
|
-
this.apiEndpoint = (_options$apiEndpoint = options.apiEndpoint) != null ? _options$apiEndpoint : isTestnet ? 'https://testnet-api.stxer.xyz' : 'https://api.stxer.xyz';
|
|
592
|
-
this.stacksNodeAPI = (_options$stacksNodeAP = options.stacksNodeAPI) != null ? _options$stacksNodeAP : isTestnet ? 'https://api.testnet.hiro.so' : 'https://api.hiro.so';
|
|
286
|
+
var BatchProcessor = /*#__PURE__*/function () {
|
|
287
|
+
function BatchProcessor(options) {
|
|
288
|
+
var _options$stxerAPIEndp;
|
|
289
|
+
this.queues = new Map();
|
|
290
|
+
this.timeoutIds = new Map();
|
|
291
|
+
this.stxerAPIEndpoint = void 0;
|
|
292
|
+
this.batchDelayMs = void 0;
|
|
293
|
+
this.stxerAPIEndpoint = (_options$stxerAPIEndp = options.stxerAPIEndpoint) != null ? _options$stxerAPIEndp : 'https://api.stxer.xyz';
|
|
294
|
+
this.batchDelayMs = options.batchDelayMs;
|
|
593
295
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
var _proto = SimulationBuilder.prototype;
|
|
598
|
-
_proto.useBlockHeight = function useBlockHeight(block) {
|
|
599
|
-
this.block = block;
|
|
600
|
-
return this;
|
|
601
|
-
};
|
|
602
|
-
_proto.withSender = function withSender(address) {
|
|
603
|
-
this.sender = address;
|
|
604
|
-
return this;
|
|
296
|
+
var _proto = BatchProcessor.prototype;
|
|
297
|
+
_proto.getQueueKey = function getQueueKey(tip) {
|
|
298
|
+
return tip != null ? tip : '_undefined';
|
|
605
299
|
};
|
|
606
|
-
_proto.
|
|
607
|
-
this
|
|
608
|
-
|
|
300
|
+
_proto.read = function read(request) {
|
|
301
|
+
var _this = this;
|
|
302
|
+
return new Promise(function (resolve, reject) {
|
|
303
|
+
_this.enqueue({
|
|
304
|
+
request: request,
|
|
305
|
+
resolve: resolve,
|
|
306
|
+
reject: reject
|
|
307
|
+
});
|
|
609
308
|
});
|
|
610
|
-
return this;
|
|
611
|
-
};
|
|
612
|
-
_proto.addSTXTransfer = function addSTXTransfer(params) {
|
|
613
|
-
var _params$sender, _params$fee;
|
|
614
|
-
if (params.sender == null && this.sender === '') {
|
|
615
|
-
throw new Error('Please specify a sender with useSender or adding a sender paramenter');
|
|
616
|
-
}
|
|
617
|
-
this.steps.push(_extends({}, params, {
|
|
618
|
-
sender: (_params$sender = params.sender) != null ? _params$sender : this.sender,
|
|
619
|
-
fee: (_params$fee = params.fee) != null ? _params$fee : 0
|
|
620
|
-
}));
|
|
621
|
-
return this;
|
|
622
309
|
};
|
|
623
|
-
_proto.
|
|
624
|
-
var
|
|
625
|
-
|
|
626
|
-
|
|
310
|
+
_proto.enqueue = function enqueue(request) {
|
|
311
|
+
var _this$queues$get,
|
|
312
|
+
_this2 = this;
|
|
313
|
+
var queueKey = this.getQueueKey(request.tip);
|
|
314
|
+
var queue = (_this$queues$get = this.queues.get(queueKey)) != null ? _this$queues$get : [];
|
|
315
|
+
if (!this.queues.has(queueKey)) {
|
|
316
|
+
this.queues.set(queueKey, queue);
|
|
627
317
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
_proto.addContractDeploy = function addContractDeploy(params) {
|
|
635
|
-
var _params$deployer, _params$fee3, _params$clarity_versi;
|
|
636
|
-
if (params.deployer == null && this.sender === '') {
|
|
637
|
-
throw new Error('Please specify a deployer with useSender or adding a deployer paramenter');
|
|
638
|
-
}
|
|
639
|
-
this.steps.push(_extends({}, params, {
|
|
640
|
-
deployer: (_params$deployer = params.deployer) != null ? _params$deployer : this.sender,
|
|
641
|
-
fee: (_params$fee3 = params.fee) != null ? _params$fee3 : 0,
|
|
642
|
-
clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : transactions.ClarityVersion.Clarity3
|
|
643
|
-
}));
|
|
644
|
-
return this;
|
|
645
|
-
};
|
|
646
|
-
_proto.addEvalCode = function addEvalCode(inside_contract_id, code) {
|
|
647
|
-
this.steps.push({
|
|
648
|
-
contract_id: inside_contract_id,
|
|
649
|
-
code: code
|
|
650
|
-
});
|
|
651
|
-
return this;
|
|
652
|
-
};
|
|
653
|
-
_proto.addMapRead = function addMapRead(contract_id, map, key) {
|
|
654
|
-
this.steps.push({
|
|
655
|
-
contract_id: contract_id,
|
|
656
|
-
code: "(map-get " + map + " " + key + ")"
|
|
657
|
-
});
|
|
658
|
-
return this;
|
|
659
|
-
};
|
|
660
|
-
_proto.addVarRead = function addVarRead(contract_id, variable) {
|
|
661
|
-
this.steps.push({
|
|
662
|
-
contract_id: contract_id,
|
|
663
|
-
code: "(var-get " + variable + ")"
|
|
664
|
-
});
|
|
665
|
-
return this;
|
|
666
|
-
};
|
|
667
|
-
_proto.getBlockInfo = /*#__PURE__*/function () {
|
|
668
|
-
var _getBlockInfo = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
669
|
-
var _yield$getNodeInfo, stacks_tip_height, info;
|
|
670
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
671
|
-
while (1) switch (_context.prev = _context.next) {
|
|
672
|
-
case 0:
|
|
673
|
-
if (!Number.isNaN(this.block)) {
|
|
674
|
-
_context.next = 6;
|
|
675
|
-
break;
|
|
676
|
-
}
|
|
677
|
-
_context.next = 3;
|
|
678
|
-
return tsClarity.getNodeInfo({
|
|
679
|
-
stacksEndpoint: this.stacksNodeAPI
|
|
680
|
-
});
|
|
681
|
-
case 3:
|
|
682
|
-
_yield$getNodeInfo = _context.sent;
|
|
683
|
-
stacks_tip_height = _yield$getNodeInfo.stacks_tip_height;
|
|
684
|
-
this.block = stacks_tip_height;
|
|
685
|
-
case 6:
|
|
686
|
-
_context.next = 8;
|
|
687
|
-
return tsClarity.richFetch(this.stacksNodeAPI + "/extended/v1/block/by_height/" + this.block + "?unanchored=true").then(function (r) {
|
|
688
|
-
return r.json();
|
|
689
|
-
});
|
|
690
|
-
case 8:
|
|
691
|
-
info = _context.sent;
|
|
692
|
-
if (!(info.height !== this.block || typeof info.hash !== 'string' || !info.hash.startsWith('0x'))) {
|
|
693
|
-
_context.next = 11;
|
|
694
|
-
break;
|
|
695
|
-
}
|
|
696
|
-
throw new Error("failed to get block info for block height " + this.block);
|
|
697
|
-
case 11:
|
|
698
|
-
return _context.abrupt("return", {
|
|
699
|
-
block_height: this.block,
|
|
700
|
-
block_hash: info.hash.substring(2),
|
|
701
|
-
index_block_hash: info.index_block_hash.substring(2)
|
|
702
|
-
});
|
|
703
|
-
case 12:
|
|
704
|
-
case "end":
|
|
705
|
-
return _context.stop();
|
|
706
|
-
}
|
|
707
|
-
}, _callee, this);
|
|
708
|
-
}));
|
|
709
|
-
function getBlockInfo() {
|
|
710
|
-
return _getBlockInfo.apply(this, arguments);
|
|
711
|
-
}
|
|
712
|
-
return getBlockInfo;
|
|
713
|
-
}();
|
|
714
|
-
_proto.run = /*#__PURE__*/function () {
|
|
715
|
-
var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
716
|
-
var _this = this;
|
|
717
|
-
var block, txs, nonce_by_address, nextNonce, network$1, _iterator, _step, step, previousSimulation, _iterator2, _step2, _step3, _step$function_args, nonce, _step$contract_id$spl, contractAddress, contractName, tx, _nonce, _tx, _nonce2, _tx2, id;
|
|
718
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
719
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
720
|
-
case 0:
|
|
721
|
-
console.log("--------------------------------\nThis product can never exist without your support!\n\nWe receive sponsorship funds with:\nSP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER\n\nFeedbacks and feature requests are welcome.\nTo get in touch: contact@stxer.xyz\n--------------------------------");
|
|
722
|
-
_context3.next = 3;
|
|
723
|
-
return this.getBlockInfo();
|
|
724
|
-
case 3:
|
|
725
|
-
block = _context3.sent;
|
|
726
|
-
console.log("Using block height " + block.block_height + " hash 0x" + block.block_hash + " to run simulation.");
|
|
727
|
-
txs = [];
|
|
728
|
-
nonce_by_address = new Map();
|
|
729
|
-
nextNonce = /*#__PURE__*/function () {
|
|
730
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(sender) {
|
|
731
|
-
var nonce, url, account;
|
|
732
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
733
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
734
|
-
case 0:
|
|
735
|
-
nonce = nonce_by_address.get(sender);
|
|
736
|
-
if (!(nonce == null)) {
|
|
737
|
-
_context2.next = 8;
|
|
738
|
-
break;
|
|
739
|
-
}
|
|
740
|
-
url = _this.stacksNodeAPI + "/v2/accounts/" + sender + "?proof=" + false + "&tip=" + block.index_block_hash;
|
|
741
|
-
_context2.next = 5;
|
|
742
|
-
return tsClarity.richFetch(url).then(function (r) {
|
|
743
|
-
return r.json();
|
|
744
|
-
});
|
|
745
|
-
case 5:
|
|
746
|
-
account = _context2.sent;
|
|
747
|
-
nonce_by_address.set(sender, account.nonce + 1);
|
|
748
|
-
return _context2.abrupt("return", account.nonce);
|
|
749
|
-
case 8:
|
|
750
|
-
nonce_by_address.set(sender, nonce + 1);
|
|
751
|
-
return _context2.abrupt("return", nonce);
|
|
752
|
-
case 10:
|
|
753
|
-
case "end":
|
|
754
|
-
return _context2.stop();
|
|
755
|
-
}
|
|
756
|
-
}, _callee2);
|
|
757
|
-
}));
|
|
758
|
-
return function nextNonce(_x5) {
|
|
759
|
-
return _ref2.apply(this, arguments);
|
|
760
|
-
};
|
|
761
|
-
}();
|
|
762
|
-
network$1 = this.network === 'mainnet' ? network.STACKS_MAINNET : network.STACKS_TESTNET;
|
|
763
|
-
if (this.stacksNodeAPI) {
|
|
764
|
-
network$1 = _extends({}, network$1, {
|
|
765
|
-
client: _extends({}, network$1.client, {
|
|
766
|
-
baseUrl: this.stacksNodeAPI
|
|
767
|
-
})
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
_iterator = _createForOfIteratorHelperLoose(this.steps);
|
|
771
|
-
case 11:
|
|
772
|
-
if ((_step = _iterator()).done) {
|
|
773
|
-
_context3.next = 57;
|
|
774
|
-
break;
|
|
775
|
-
}
|
|
776
|
-
step = _step.value;
|
|
777
|
-
if (!('simulationId' in step)) {
|
|
778
|
-
_context3.next = 20;
|
|
779
|
-
break;
|
|
780
|
-
}
|
|
781
|
-
_context3.next = 16;
|
|
782
|
-
return fetch("https://api.stxer.xyz/simulations/" + step.simulationId + "/request").then(function (x) {
|
|
783
|
-
return x.json();
|
|
784
|
-
});
|
|
785
|
-
case 16:
|
|
786
|
-
previousSimulation = _context3.sent;
|
|
787
|
-
for (_iterator2 = _createForOfIteratorHelperLoose(previousSimulation.steps); !(_step2 = _iterator2()).done;) {
|
|
788
|
-
_step3 = _step2.value;
|
|
789
|
-
if ('tx' in _step3) {
|
|
790
|
-
txs.push(transactions.deserializeTransaction(_step3.tx));
|
|
791
|
-
} else if ('code' in _step3 && 'contract' in _step3) {
|
|
792
|
-
txs.push({
|
|
793
|
-
contract_id: _step3.contract,
|
|
794
|
-
code: _step3.code
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
_context3.next = 55;
|
|
799
|
-
break;
|
|
800
|
-
case 20:
|
|
801
|
-
if (!('sender' in step && 'function_name' in step)) {
|
|
802
|
-
_context3.next = 32;
|
|
803
|
-
break;
|
|
804
|
-
}
|
|
805
|
-
_context3.next = 23;
|
|
806
|
-
return nextNonce(step.sender);
|
|
807
|
-
case 23:
|
|
808
|
-
nonce = _context3.sent;
|
|
809
|
-
_step$contract_id$spl = step.contract_id.split('.'), contractAddress = _step$contract_id$spl[0], contractName = _step$contract_id$spl[1];
|
|
810
|
-
_context3.next = 27;
|
|
811
|
-
return transactions.makeUnsignedContractCall({
|
|
812
|
-
contractAddress: contractAddress,
|
|
813
|
-
contractName: contractName,
|
|
814
|
-
functionName: step.function_name,
|
|
815
|
-
functionArgs: (_step$function_args = step.function_args) != null ? _step$function_args : [],
|
|
816
|
-
nonce: nonce,
|
|
817
|
-
network: network$1,
|
|
818
|
-
publicKey: '',
|
|
819
|
-
postConditionMode: transactions.PostConditionMode.Allow,
|
|
820
|
-
fee: step.fee
|
|
821
|
-
});
|
|
822
|
-
case 27:
|
|
823
|
-
tx = _context3.sent;
|
|
824
|
-
tx.auth.spendingCondition.signer = c32check.c32addressDecode(step.sender)[1];
|
|
825
|
-
txs.push(tx);
|
|
826
|
-
_context3.next = 55;
|
|
827
|
-
break;
|
|
828
|
-
case 32:
|
|
829
|
-
if (!('sender' in step && 'recipient' in step)) {
|
|
830
|
-
_context3.next = 43;
|
|
831
|
-
break;
|
|
832
|
-
}
|
|
833
|
-
_context3.next = 35;
|
|
834
|
-
return nextNonce(step.sender);
|
|
835
|
-
case 35:
|
|
836
|
-
_nonce = _context3.sent;
|
|
837
|
-
_context3.next = 38;
|
|
838
|
-
return transactions.makeUnsignedSTXTokenTransfer({
|
|
839
|
-
recipient: step.recipient,
|
|
840
|
-
amount: step.amount,
|
|
841
|
-
nonce: _nonce,
|
|
842
|
-
network: network$1,
|
|
843
|
-
publicKey: '',
|
|
844
|
-
fee: step.fee
|
|
845
|
-
});
|
|
846
|
-
case 38:
|
|
847
|
-
_tx = _context3.sent;
|
|
848
|
-
_tx.auth.spendingCondition.signer = c32check.c32addressDecode(step.sender)[1];
|
|
849
|
-
txs.push(_tx);
|
|
850
|
-
_context3.next = 55;
|
|
851
|
-
break;
|
|
852
|
-
case 43:
|
|
853
|
-
if (!('deployer' in step)) {
|
|
854
|
-
_context3.next = 54;
|
|
855
|
-
break;
|
|
856
|
-
}
|
|
857
|
-
_context3.next = 46;
|
|
858
|
-
return nextNonce(step.deployer);
|
|
859
|
-
case 46:
|
|
860
|
-
_nonce2 = _context3.sent;
|
|
861
|
-
_context3.next = 49;
|
|
862
|
-
return transactions.makeUnsignedContractDeploy({
|
|
863
|
-
contractName: step.contract_name,
|
|
864
|
-
codeBody: step.source_code,
|
|
865
|
-
nonce: _nonce2,
|
|
866
|
-
network: network$1,
|
|
867
|
-
publicKey: '',
|
|
868
|
-
postConditionMode: transactions.PostConditionMode.Allow,
|
|
869
|
-
fee: step.fee
|
|
870
|
-
});
|
|
871
|
-
case 49:
|
|
872
|
-
_tx2 = _context3.sent;
|
|
873
|
-
_tx2.auth.spendingCondition.signer = c32check.c32addressDecode(step.deployer)[1];
|
|
874
|
-
txs.push(_tx2);
|
|
875
|
-
_context3.next = 55;
|
|
876
|
-
break;
|
|
877
|
-
case 54:
|
|
878
|
-
if ('code' in step) {
|
|
879
|
-
txs.push(step);
|
|
880
|
-
} else {
|
|
881
|
-
// biome-ignore lint/style/noUnusedTemplateLiteral: <explanation>
|
|
882
|
-
console.log("Invalid simulation step:", step);
|
|
883
|
-
}
|
|
884
|
-
case 55:
|
|
885
|
-
_context3.next = 11;
|
|
886
|
-
break;
|
|
887
|
-
case 57:
|
|
888
|
-
_context3.next = 59;
|
|
889
|
-
return runSimulation(this.apiEndpoint + "/simulations", block.block_hash, block.block_height, txs);
|
|
890
|
-
case 59:
|
|
891
|
-
id = _context3.sent;
|
|
892
|
-
console.log("Simulation will be available at: https://stxer.xyz/simulations/" + this.network + "/" + id);
|
|
893
|
-
return _context3.abrupt("return", id);
|
|
894
|
-
case 62:
|
|
895
|
-
case "end":
|
|
896
|
-
return _context3.stop();
|
|
897
|
-
}
|
|
898
|
-
}, _callee3, this);
|
|
899
|
-
}));
|
|
900
|
-
function run() {
|
|
901
|
-
return _run.apply(this, arguments);
|
|
902
|
-
}
|
|
903
|
-
return run;
|
|
904
|
-
}();
|
|
905
|
-
_proto.pipe = function pipe(transform) {
|
|
906
|
-
return transform(this);
|
|
907
|
-
};
|
|
908
|
-
return SimulationBuilder;
|
|
909
|
-
}();
|
|
910
|
-
|
|
911
|
-
var BatchProcessor = /*#__PURE__*/function () {
|
|
912
|
-
function BatchProcessor(options) {
|
|
913
|
-
var _options$stxerAPIEndp;
|
|
914
|
-
this.queues = new Map();
|
|
915
|
-
this.timeoutIds = new Map();
|
|
916
|
-
this.stxerAPIEndpoint = void 0;
|
|
917
|
-
this.batchDelayMs = void 0;
|
|
918
|
-
this.stxerAPIEndpoint = (_options$stxerAPIEndp = options.stxerAPIEndpoint) != null ? _options$stxerAPIEndp : 'https://api.stxer.xyz';
|
|
919
|
-
this.batchDelayMs = options.batchDelayMs;
|
|
920
|
-
}
|
|
921
|
-
var _proto = BatchProcessor.prototype;
|
|
922
|
-
_proto.getQueueKey = function getQueueKey(tip) {
|
|
923
|
-
return tip != null ? tip : '_undefined';
|
|
924
|
-
};
|
|
925
|
-
_proto.read = function read(request) {
|
|
926
|
-
var _this = this;
|
|
927
|
-
return new Promise(function (resolve, reject) {
|
|
928
|
-
_this.enqueue({
|
|
929
|
-
request: request,
|
|
930
|
-
resolve: resolve,
|
|
931
|
-
reject: reject
|
|
932
|
-
});
|
|
933
|
-
});
|
|
934
|
-
};
|
|
935
|
-
_proto.enqueue = function enqueue(request) {
|
|
936
|
-
var _this$queues$get,
|
|
937
|
-
_this2 = this;
|
|
938
|
-
var queueKey = this.getQueueKey(request.tip);
|
|
939
|
-
var queue = (_this$queues$get = this.queues.get(queueKey)) != null ? _this$queues$get : [];
|
|
940
|
-
if (!this.queues.has(queueKey)) {
|
|
941
|
-
this.queues.set(queueKey, queue);
|
|
942
|
-
}
|
|
943
|
-
queue.push(request);
|
|
944
|
-
if (!this.timeoutIds.has(queueKey)) {
|
|
945
|
-
var timeoutId = setTimeout(function () {
|
|
946
|
-
return _this2.processBatch(queueKey);
|
|
947
|
-
}, this.batchDelayMs);
|
|
948
|
-
this.timeoutIds.set(queueKey, timeoutId);
|
|
318
|
+
queue.push(request);
|
|
319
|
+
if (!this.timeoutIds.has(queueKey)) {
|
|
320
|
+
var timeoutId = setTimeout(function () {
|
|
321
|
+
return _this2.processBatch(queueKey);
|
|
322
|
+
}, this.batchDelayMs);
|
|
323
|
+
this.timeoutIds.set(queueKey, timeoutId);
|
|
949
324
|
}
|
|
950
325
|
};
|
|
951
326
|
_proto.processBatch = /*#__PURE__*/function () {
|
|
952
|
-
var _processBatch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/
|
|
327
|
+
var _processBatch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(queueKey) {
|
|
953
328
|
var _this$queues$get2;
|
|
954
|
-
var currentQueue, timeoutId, readonlyRequests, mapRequests, variableRequests, tip, batchRequest, results, _iterator, _step, _step$value, index, result, _iterator2, _step2, _step2$value, _index, _result, _iterator3, _step3, _step3$value, _index2, _result2, _iterator4, _step4, item;
|
|
955
|
-
return
|
|
956
|
-
while (1) switch (_context.
|
|
329
|
+
var currentQueue, timeoutId, readonlyRequests, mapRequests, variableRequests, tip, batchRequest, results, _iterator, _step, _step$value, index, result, _iterator2, _step2, _step2$value, _index, _result, _iterator3, _step3, _step3$value, _index2, _result2, _iterator4, _step4, item, _t;
|
|
330
|
+
return _regenerator().w(function (_context) {
|
|
331
|
+
while (1) switch (_context.p = _context.n) {
|
|
957
332
|
case 0:
|
|
958
333
|
currentQueue = (_this$queues$get2 = this.queues.get(queueKey)) != null ? _this$queues$get2 : [];
|
|
959
334
|
this.queues["delete"](queueKey);
|
|
@@ -963,12 +338,12 @@ var BatchProcessor = /*#__PURE__*/function () {
|
|
|
963
338
|
this.timeoutIds["delete"](queueKey);
|
|
964
339
|
}
|
|
965
340
|
if (!(currentQueue.length === 0)) {
|
|
966
|
-
_context.
|
|
341
|
+
_context.n = 1;
|
|
967
342
|
break;
|
|
968
343
|
}
|
|
969
|
-
return _context.
|
|
970
|
-
case
|
|
971
|
-
_context.
|
|
344
|
+
return _context.a(2);
|
|
345
|
+
case 1:
|
|
346
|
+
_context.p = 1;
|
|
972
347
|
readonlyRequests = currentQueue.filter(function (q) {
|
|
973
348
|
return q.request.mode === 'readonly';
|
|
974
349
|
});
|
|
@@ -1005,12 +380,12 @@ var BatchProcessor = /*#__PURE__*/function () {
|
|
|
1005
380
|
}),
|
|
1006
381
|
index_block_hash: tip
|
|
1007
382
|
};
|
|
1008
|
-
_context.
|
|
383
|
+
_context.n = 2;
|
|
1009
384
|
return batchRead(batchRequest, {
|
|
1010
385
|
stxerApi: this.stxerAPIEndpoint
|
|
1011
386
|
});
|
|
1012
|
-
case
|
|
1013
|
-
results = _context.
|
|
387
|
+
case 2:
|
|
388
|
+
results = _context.v;
|
|
1014
389
|
// Handle readonly results
|
|
1015
390
|
for (_iterator = _createForOfIteratorHelperLoose(results.readonly.entries()); !(_step = _iterator()).done;) {
|
|
1016
391
|
_step$value = _step.value, index = _step$value[0], result = _step$value[1];
|
|
@@ -1038,20 +413,19 @@ var BatchProcessor = /*#__PURE__*/function () {
|
|
|
1038
413
|
mapRequests[_index2].resolve(_result2);
|
|
1039
414
|
}
|
|
1040
415
|
}
|
|
1041
|
-
_context.
|
|
416
|
+
_context.n = 4;
|
|
1042
417
|
break;
|
|
1043
|
-
case
|
|
1044
|
-
_context.
|
|
1045
|
-
|
|
418
|
+
case 3:
|
|
419
|
+
_context.p = 3;
|
|
420
|
+
_t = _context.v;
|
|
1046
421
|
for (_iterator4 = _createForOfIteratorHelperLoose(currentQueue); !(_step4 = _iterator4()).done;) {
|
|
1047
422
|
item = _step4.value;
|
|
1048
|
-
item.reject(
|
|
423
|
+
item.reject(_t);
|
|
1049
424
|
}
|
|
1050
|
-
case
|
|
1051
|
-
|
|
1052
|
-
return _context.stop();
|
|
425
|
+
case 4:
|
|
426
|
+
return _context.a(2);
|
|
1053
427
|
}
|
|
1054
|
-
}, _callee, this, [[
|
|
428
|
+
}, _callee, this, [[1, 3]]);
|
|
1055
429
|
}));
|
|
1056
430
|
function processBatch(_x) {
|
|
1057
431
|
return _processBatch.apply(this, arguments);
|
|
@@ -1069,11 +443,11 @@ function callReadonly(_x) {
|
|
|
1069
443
|
return _callReadonly.apply(this, arguments);
|
|
1070
444
|
}
|
|
1071
445
|
function _callReadonly() {
|
|
1072
|
-
_callReadonly = _asyncToGenerator(/*#__PURE__*/
|
|
446
|
+
_callReadonly = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
1073
447
|
var _params$batchProcesso;
|
|
1074
448
|
var processor, _params$contract$spli, deployer, contractName, fn, functionDef, argsKV, args, _iterator, _step, argDef;
|
|
1075
|
-
return
|
|
1076
|
-
while (1) switch (_context.
|
|
449
|
+
return _regenerator().w(function (_context) {
|
|
450
|
+
while (1) switch (_context.n) {
|
|
1077
451
|
case 0:
|
|
1078
452
|
processor = (_params$batchProcesso = params.batchProcessor) != null ? _params$batchProcesso : defaultProcessor;
|
|
1079
453
|
_params$contract$spli = params.contract.split('.', 2), deployer = _params$contract$spli[0], contractName = _params$contract$spli[1];
|
|
@@ -1082,18 +456,18 @@ function _callReadonly() {
|
|
|
1082
456
|
return def.name === params.functionName;
|
|
1083
457
|
});
|
|
1084
458
|
if (functionDef) {
|
|
1085
|
-
_context.
|
|
459
|
+
_context.n = 1;
|
|
1086
460
|
break;
|
|
1087
461
|
}
|
|
1088
462
|
throw new Error("failed to find function definition for " + params.functionName);
|
|
1089
|
-
case
|
|
463
|
+
case 1:
|
|
1090
464
|
argsKV = params.args;
|
|
1091
465
|
args = [];
|
|
1092
466
|
for (_iterator = _createForOfIteratorHelperLoose(functionDef.args); !(_step = _iterator()).done;) {
|
|
1093
467
|
argDef = _step.value;
|
|
1094
468
|
args.push(tsClarity.encodeAbi(argDef.type, argsKV[argDef.name]));
|
|
1095
469
|
}
|
|
1096
|
-
return _context.
|
|
470
|
+
return _context.a(2, new Promise(function (_resolve, reject) {
|
|
1097
471
|
processor.enqueue({
|
|
1098
472
|
request: {
|
|
1099
473
|
mode: 'readonly',
|
|
@@ -1114,9 +488,6 @@ function _callReadonly() {
|
|
|
1114
488
|
reject: reject
|
|
1115
489
|
});
|
|
1116
490
|
}));
|
|
1117
|
-
case 10:
|
|
1118
|
-
case "end":
|
|
1119
|
-
return _context.stop();
|
|
1120
491
|
}
|
|
1121
492
|
}, _callee);
|
|
1122
493
|
}));
|
|
@@ -1126,11 +497,11 @@ function readMap(_x2) {
|
|
|
1126
497
|
return _readMap.apply(this, arguments);
|
|
1127
498
|
}
|
|
1128
499
|
function _readMap() {
|
|
1129
|
-
_readMap = _asyncToGenerator(/*#__PURE__*/
|
|
500
|
+
_readMap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(params) {
|
|
1130
501
|
var _params$batchProcesso2;
|
|
1131
502
|
var processor, _params$contract$spli2, deployer, contractName, mapDef, key;
|
|
1132
|
-
return
|
|
1133
|
-
while (1) switch (_context2.
|
|
503
|
+
return _regenerator().w(function (_context2) {
|
|
504
|
+
while (1) switch (_context2.n) {
|
|
1134
505
|
case 0:
|
|
1135
506
|
processor = (_params$batchProcesso2 = params.batchProcessor) != null ? _params$batchProcesso2 : defaultProcessor;
|
|
1136
507
|
_params$contract$spli2 = params.contract.split('.', 2), deployer = _params$contract$spli2[0], contractName = _params$contract$spli2[1];
|
|
@@ -1138,13 +509,13 @@ function _readMap() {
|
|
|
1138
509
|
return m.name === params.mapName;
|
|
1139
510
|
});
|
|
1140
511
|
if (mapDef) {
|
|
1141
|
-
_context2.
|
|
512
|
+
_context2.n = 1;
|
|
1142
513
|
break;
|
|
1143
514
|
}
|
|
1144
515
|
throw new Error("failed to find map definition for " + params.mapName);
|
|
1145
|
-
case
|
|
516
|
+
case 1:
|
|
1146
517
|
key = tsClarity.encodeAbi(mapDef.key, params.key);
|
|
1147
|
-
return _context2.
|
|
518
|
+
return _context2.a(2, new Promise(function (_resolve2, reject) {
|
|
1148
519
|
processor.enqueue({
|
|
1149
520
|
request: {
|
|
1150
521
|
mode: 'mapEntry',
|
|
@@ -1173,9 +544,6 @@ function _readMap() {
|
|
|
1173
544
|
reject: reject
|
|
1174
545
|
});
|
|
1175
546
|
}));
|
|
1176
|
-
case 7:
|
|
1177
|
-
case "end":
|
|
1178
|
-
return _context2.stop();
|
|
1179
547
|
}
|
|
1180
548
|
}, _callee2);
|
|
1181
549
|
}));
|
|
@@ -1185,11 +553,11 @@ function readVariable(_x3) {
|
|
|
1185
553
|
return _readVariable.apply(this, arguments);
|
|
1186
554
|
}
|
|
1187
555
|
function _readVariable() {
|
|
1188
|
-
_readVariable = _asyncToGenerator(/*#__PURE__*/
|
|
556
|
+
_readVariable = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(params) {
|
|
1189
557
|
var _params$batchProcesso3;
|
|
1190
558
|
var processor, _params$contract$spli3, deployer, contractName, varDef;
|
|
1191
|
-
return
|
|
1192
|
-
while (1) switch (_context3.
|
|
559
|
+
return _regenerator().w(function (_context3) {
|
|
560
|
+
while (1) switch (_context3.n) {
|
|
1193
561
|
case 0:
|
|
1194
562
|
processor = (_params$batchProcesso3 = params.batchProcessor) != null ? _params$batchProcesso3 : defaultProcessor;
|
|
1195
563
|
_params$contract$spli3 = params.contract.split('.', 2), deployer = _params$contract$spli3[0], contractName = _params$contract$spli3[1];
|
|
@@ -1197,12 +565,12 @@ function _readVariable() {
|
|
|
1197
565
|
return def.name === params.variableName;
|
|
1198
566
|
});
|
|
1199
567
|
if (varDef) {
|
|
1200
|
-
_context3.
|
|
568
|
+
_context3.n = 1;
|
|
1201
569
|
break;
|
|
1202
570
|
}
|
|
1203
571
|
throw new Error("failed to find variable definition for " + params.variableName);
|
|
1204
|
-
case
|
|
1205
|
-
return _context3.
|
|
572
|
+
case 1:
|
|
573
|
+
return _context3.a(2, new Promise(function (_resolve3, reject) {
|
|
1206
574
|
processor.enqueue({
|
|
1207
575
|
request: {
|
|
1208
576
|
mode: 'variable',
|
|
@@ -1222,15 +590,502 @@ function _readVariable() {
|
|
|
1222
590
|
reject: reject
|
|
1223
591
|
});
|
|
1224
592
|
}));
|
|
1225
|
-
case 6:
|
|
1226
|
-
case "end":
|
|
1227
|
-
return _context3.stop();
|
|
1228
593
|
}
|
|
1229
594
|
}, _callee3);
|
|
1230
595
|
}));
|
|
1231
596
|
return _readVariable.apply(this, arguments);
|
|
1232
597
|
}
|
|
1233
598
|
|
|
599
|
+
function setSender(tx, sender) {
|
|
600
|
+
var _c32addressDecode = c32check.c32addressDecode(sender),
|
|
601
|
+
addressVersion = _c32addressDecode[0],
|
|
602
|
+
signer = _c32addressDecode[1];
|
|
603
|
+
switch (addressVersion) {
|
|
604
|
+
case network.AddressVersion.MainnetSingleSig:
|
|
605
|
+
case network.AddressVersion.TestnetSingleSig:
|
|
606
|
+
tx.auth.spendingCondition.hashMode = transactions.AddressHashMode.P2PKH;
|
|
607
|
+
tx.auth.spendingCondition.signer = signer;
|
|
608
|
+
break;
|
|
609
|
+
case network.AddressVersion.MainnetMultiSig:
|
|
610
|
+
case network.AddressVersion.TestnetMultiSig:
|
|
611
|
+
{
|
|
612
|
+
var sc = tx.auth.spendingCondition;
|
|
613
|
+
tx.auth.spendingCondition = {
|
|
614
|
+
hashMode: transactions.AddressHashMode.P2SH,
|
|
615
|
+
signer: signer,
|
|
616
|
+
fields: [],
|
|
617
|
+
signaturesRequired: 0,
|
|
618
|
+
nonce: sc.nonce,
|
|
619
|
+
fee: sc.fee
|
|
620
|
+
};
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return tx;
|
|
625
|
+
}
|
|
626
|
+
function runTx(tx) {
|
|
627
|
+
// type 0: run transaction
|
|
628
|
+
return transactions.tupleCV({
|
|
629
|
+
type: transactions.uintCV(0),
|
|
630
|
+
data: transactions.bufferCV(tx.serializeBytes())
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
function runEval(_ref) {
|
|
634
|
+
var contract_id = _ref.contract_id,
|
|
635
|
+
code = _ref.code;
|
|
636
|
+
var _contract_id$split = contract_id.split('.'),
|
|
637
|
+
contract_address = _contract_id$split[0],
|
|
638
|
+
contract_name = _contract_id$split[1];
|
|
639
|
+
// type 1: eval arbitrary code inside a contract
|
|
640
|
+
return transactions.tupleCV({
|
|
641
|
+
type: transactions.uintCV(1),
|
|
642
|
+
data: transactions.bufferCV(transactions.serializeCVBytes(transactions.tupleCV({
|
|
643
|
+
contract: transactions.contractPrincipalCV(contract_address, contract_name),
|
|
644
|
+
code: transactions.stringAsciiCV(code)
|
|
645
|
+
})))
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
function runSimulation(_x, _x2, _x3, _x4) {
|
|
649
|
+
return _runSimulation.apply(this, arguments);
|
|
650
|
+
}
|
|
651
|
+
function _runSimulation() {
|
|
652
|
+
_runSimulation = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(apiEndpoint, block_hash, block_height, txs) {
|
|
653
|
+
var header, heightBytes, view, hashHex, matches, hashBytes, txBytes, totalLength, body, offset, _iterator3, _step4, tx, rs;
|
|
654
|
+
return _regenerator().w(function (_context7) {
|
|
655
|
+
while (1) switch (_context7.n) {
|
|
656
|
+
case 0:
|
|
657
|
+
// Convert 'sim-v1' to Uint8Array
|
|
658
|
+
header = new TextEncoder().encode('sim-v1'); // Create 8 bytes for block height
|
|
659
|
+
heightBytes = new Uint8Array(8); // Convert block height to bytes
|
|
660
|
+
view = new DataView(heightBytes.buffer);
|
|
661
|
+
view.setBigUint64(0, BigInt(block_height), false); // false for big-endian
|
|
662
|
+
// Convert block hash to bytes
|
|
663
|
+
hashHex = block_hash.startsWith('0x') ? block_hash.substring(2) : block_hash; // Replace non-null assertion with null check
|
|
664
|
+
matches = hashHex.match(/.{1,2}/g);
|
|
665
|
+
if (matches) {
|
|
666
|
+
_context7.n = 1;
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
throw new Error('Invalid block hash format');
|
|
670
|
+
case 1:
|
|
671
|
+
hashBytes = new Uint8Array(matches.map(function (_byte) {
|
|
672
|
+
return Number.parseInt(_byte, 16);
|
|
673
|
+
})); // Convert transactions to bytes
|
|
674
|
+
txBytes = txs.map(function (t) {
|
|
675
|
+
return 'contract_id' in t && 'code' in t ? runEval(t) : runTx(t);
|
|
676
|
+
}).map(function (t) {
|
|
677
|
+
return transactions.serializeCVBytes(t);
|
|
678
|
+
}); // Combine all byte arrays
|
|
679
|
+
totalLength = header.length + heightBytes.length + hashBytes.length + txBytes.reduce(function (acc, curr) {
|
|
680
|
+
return acc + curr.length;
|
|
681
|
+
}, 0);
|
|
682
|
+
body = new Uint8Array(totalLength);
|
|
683
|
+
offset = 0;
|
|
684
|
+
body.set(header, offset);
|
|
685
|
+
offset += header.length;
|
|
686
|
+
body.set(heightBytes, offset);
|
|
687
|
+
offset += heightBytes.length;
|
|
688
|
+
body.set(hashBytes, offset);
|
|
689
|
+
offset += hashBytes.length;
|
|
690
|
+
for (_iterator3 = _createForOfIteratorHelperLoose(txBytes); !(_step4 = _iterator3()).done;) {
|
|
691
|
+
tx = _step4.value;
|
|
692
|
+
body.set(tx, offset);
|
|
693
|
+
offset += tx.length;
|
|
694
|
+
}
|
|
695
|
+
_context7.n = 2;
|
|
696
|
+
return fetch(apiEndpoint, {
|
|
697
|
+
method: 'POST',
|
|
698
|
+
body: body
|
|
699
|
+
}).then(/*#__PURE__*/function () {
|
|
700
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(rs) {
|
|
701
|
+
var response;
|
|
702
|
+
return _regenerator().w(function (_context6) {
|
|
703
|
+
while (1) switch (_context6.n) {
|
|
704
|
+
case 0:
|
|
705
|
+
_context6.n = 1;
|
|
706
|
+
return rs.text();
|
|
707
|
+
case 1:
|
|
708
|
+
response = _context6.v;
|
|
709
|
+
if (response.startsWith('{')) {
|
|
710
|
+
_context6.n = 2;
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
throw new Error("failed to submit simulation: " + response);
|
|
714
|
+
case 2:
|
|
715
|
+
return _context6.a(2, JSON.parse(response));
|
|
716
|
+
}
|
|
717
|
+
}, _callee5);
|
|
718
|
+
}));
|
|
719
|
+
return function (_x7) {
|
|
720
|
+
return _ref4.apply(this, arguments);
|
|
721
|
+
};
|
|
722
|
+
}());
|
|
723
|
+
case 2:
|
|
724
|
+
rs = _context7.v;
|
|
725
|
+
return _context7.a(2, rs.id);
|
|
726
|
+
}
|
|
727
|
+
}, _callee6);
|
|
728
|
+
}));
|
|
729
|
+
return _runSimulation.apply(this, arguments);
|
|
730
|
+
}
|
|
731
|
+
var SimulationBuilder = /*#__PURE__*/function () {
|
|
732
|
+
function SimulationBuilder(options) {
|
|
733
|
+
var _options$network, _options$apiEndpoint, _options$stacksNodeAP;
|
|
734
|
+
if (options === void 0) {
|
|
735
|
+
options = {};
|
|
736
|
+
}
|
|
737
|
+
this.apiEndpoint = void 0;
|
|
738
|
+
this.stacksNodeAPI = void 0;
|
|
739
|
+
this.network = void 0;
|
|
740
|
+
// biome-ignore lint/style/useNumberNamespace: ignore this
|
|
741
|
+
this.block = NaN;
|
|
742
|
+
this.sender = '';
|
|
743
|
+
this.steps = [];
|
|
744
|
+
this.network = (_options$network = options.network) != null ? _options$network : 'mainnet';
|
|
745
|
+
var isTestnet = this.network === 'testnet';
|
|
746
|
+
this.apiEndpoint = (_options$apiEndpoint = options.apiEndpoint) != null ? _options$apiEndpoint : isTestnet ? 'https://testnet-api.stxer.xyz' : 'https://api.stxer.xyz';
|
|
747
|
+
this.stacksNodeAPI = (_options$stacksNodeAP = options.stacksNodeAPI) != null ? _options$stacksNodeAP : isTestnet ? 'https://api.testnet.hiro.so' : 'https://api.hiro.so';
|
|
748
|
+
}
|
|
749
|
+
SimulationBuilder["new"] = function _new(options) {
|
|
750
|
+
return new SimulationBuilder(options);
|
|
751
|
+
};
|
|
752
|
+
var _proto = SimulationBuilder.prototype;
|
|
753
|
+
_proto.useBlockHeight = function useBlockHeight(block) {
|
|
754
|
+
this.block = block;
|
|
755
|
+
return this;
|
|
756
|
+
};
|
|
757
|
+
_proto.withSender = function withSender(address) {
|
|
758
|
+
this.sender = address;
|
|
759
|
+
return this;
|
|
760
|
+
};
|
|
761
|
+
_proto.inlineSimulation = function inlineSimulation(simulationId) {
|
|
762
|
+
this.steps.push({
|
|
763
|
+
simulationId: simulationId
|
|
764
|
+
});
|
|
765
|
+
return this;
|
|
766
|
+
};
|
|
767
|
+
_proto.addSTXTransfer = function addSTXTransfer(params) {
|
|
768
|
+
var _params$sender, _params$fee;
|
|
769
|
+
if (params.sender == null && this.sender === '') {
|
|
770
|
+
throw new Error('Please specify a sender with useSender or adding a sender paramenter');
|
|
771
|
+
}
|
|
772
|
+
this.steps.push(_extends({}, params, {
|
|
773
|
+
sender: (_params$sender = params.sender) != null ? _params$sender : this.sender,
|
|
774
|
+
fee: (_params$fee = params.fee) != null ? _params$fee : 0
|
|
775
|
+
}));
|
|
776
|
+
return this;
|
|
777
|
+
};
|
|
778
|
+
_proto.addContractCall = function addContractCall(params) {
|
|
779
|
+
var _params$sender2, _params$fee2;
|
|
780
|
+
if (params.sender == null && this.sender === '') {
|
|
781
|
+
throw new Error('Please specify a sender with useSender or adding a sender paramenter');
|
|
782
|
+
}
|
|
783
|
+
this.steps.push(_extends({}, params, {
|
|
784
|
+
sender: (_params$sender2 = params.sender) != null ? _params$sender2 : this.sender,
|
|
785
|
+
fee: (_params$fee2 = params.fee) != null ? _params$fee2 : 0
|
|
786
|
+
}));
|
|
787
|
+
return this;
|
|
788
|
+
};
|
|
789
|
+
_proto.addContractDeploy = function addContractDeploy(params) {
|
|
790
|
+
var _params$deployer, _params$fee3, _params$clarity_versi;
|
|
791
|
+
if (params.deployer == null && this.sender === '') {
|
|
792
|
+
throw new Error('Please specify a deployer with useSender or adding a deployer paramenter');
|
|
793
|
+
}
|
|
794
|
+
this.steps.push(_extends({}, params, {
|
|
795
|
+
deployer: (_params$deployer = params.deployer) != null ? _params$deployer : this.sender,
|
|
796
|
+
fee: (_params$fee3 = params.fee) != null ? _params$fee3 : 0,
|
|
797
|
+
clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : transactions.ClarityVersion.Clarity4
|
|
798
|
+
}));
|
|
799
|
+
return this;
|
|
800
|
+
};
|
|
801
|
+
_proto.addEvalCode = function addEvalCode(inside_contract_id, code) {
|
|
802
|
+
this.steps.push({
|
|
803
|
+
contract_id: inside_contract_id,
|
|
804
|
+
code: code
|
|
805
|
+
});
|
|
806
|
+
return this;
|
|
807
|
+
};
|
|
808
|
+
_proto.addMapRead = function addMapRead(contract_id, map, key) {
|
|
809
|
+
this.steps.push({
|
|
810
|
+
contract_id: contract_id,
|
|
811
|
+
code: "(map-get " + map + " " + key + ")"
|
|
812
|
+
});
|
|
813
|
+
return this;
|
|
814
|
+
};
|
|
815
|
+
_proto.addVarRead = function addVarRead(contract_id, variable) {
|
|
816
|
+
this.steps.push({
|
|
817
|
+
contract_id: contract_id,
|
|
818
|
+
code: "(var-get " + variable + ")"
|
|
819
|
+
});
|
|
820
|
+
return this;
|
|
821
|
+
};
|
|
822
|
+
_proto.getBlockInfo = /*#__PURE__*/function () {
|
|
823
|
+
var _getBlockInfo = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
824
|
+
var _yield$getNodeInfo, stacks_tip_height, info;
|
|
825
|
+
return _regenerator().w(function (_context) {
|
|
826
|
+
while (1) switch (_context.n) {
|
|
827
|
+
case 0:
|
|
828
|
+
if (!Number.isNaN(this.block)) {
|
|
829
|
+
_context.n = 2;
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
_context.n = 1;
|
|
833
|
+
return tsClarity.getNodeInfo({
|
|
834
|
+
stacksEndpoint: this.stacksNodeAPI
|
|
835
|
+
});
|
|
836
|
+
case 1:
|
|
837
|
+
_yield$getNodeInfo = _context.v;
|
|
838
|
+
stacks_tip_height = _yield$getNodeInfo.stacks_tip_height;
|
|
839
|
+
this.block = stacks_tip_height;
|
|
840
|
+
case 2:
|
|
841
|
+
_context.n = 3;
|
|
842
|
+
return tsClarity.richFetch(this.stacksNodeAPI + "/extended/v1/block/by_height/" + this.block + "?unanchored=true").then(function (r) {
|
|
843
|
+
return r.json();
|
|
844
|
+
});
|
|
845
|
+
case 3:
|
|
846
|
+
info = _context.v;
|
|
847
|
+
if (!(info.height !== this.block || typeof info.hash !== 'string' || !info.hash.startsWith('0x'))) {
|
|
848
|
+
_context.n = 4;
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
throw new Error("failed to get block info for block height " + this.block);
|
|
852
|
+
case 4:
|
|
853
|
+
return _context.a(2, {
|
|
854
|
+
block_height: this.block,
|
|
855
|
+
block_hash: info.hash.substring(2),
|
|
856
|
+
index_block_hash: info.index_block_hash.substring(2)
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
}, _callee, this);
|
|
860
|
+
}));
|
|
861
|
+
function getBlockInfo() {
|
|
862
|
+
return _getBlockInfo.apply(this, arguments);
|
|
863
|
+
}
|
|
864
|
+
return getBlockInfo;
|
|
865
|
+
}();
|
|
866
|
+
_proto.run = /*#__PURE__*/function () {
|
|
867
|
+
var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
868
|
+
var _this = this;
|
|
869
|
+
var block, txs, nonce_by_address, nextNonce, network$1, _loop, _iterator, _step, id;
|
|
870
|
+
return _regenerator().w(function (_context5) {
|
|
871
|
+
while (1) switch (_context5.n) {
|
|
872
|
+
case 0:
|
|
873
|
+
console.log("--------------------------------\nThis product can never exist without your support!\n\nWe receive sponsorship funds with:\nSP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER\n\nFeedbacks and feature requests are welcome.\nTo get in touch: contact@stxer.xyz\n--------------------------------");
|
|
874
|
+
_context5.n = 1;
|
|
875
|
+
return this.getBlockInfo();
|
|
876
|
+
case 1:
|
|
877
|
+
block = _context5.v;
|
|
878
|
+
console.log("Using block height " + block.block_height + " hash 0x" + block.block_hash + " to run simulation.");
|
|
879
|
+
txs = [];
|
|
880
|
+
nonce_by_address = new Map();
|
|
881
|
+
nextNonce = /*#__PURE__*/function () {
|
|
882
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(sender) {
|
|
883
|
+
var nonce, url, account;
|
|
884
|
+
return _regenerator().w(function (_context2) {
|
|
885
|
+
while (1) switch (_context2.n) {
|
|
886
|
+
case 0:
|
|
887
|
+
nonce = nonce_by_address.get(sender);
|
|
888
|
+
if (!(nonce == null)) {
|
|
889
|
+
_context2.n = 2;
|
|
890
|
+
break;
|
|
891
|
+
}
|
|
892
|
+
url = _this.stacksNodeAPI + "/v2/accounts/" + sender + "?proof=" + false + "&tip=" + block.index_block_hash;
|
|
893
|
+
_context2.n = 1;
|
|
894
|
+
return tsClarity.richFetch(url).then(function (r) {
|
|
895
|
+
return r.json();
|
|
896
|
+
});
|
|
897
|
+
case 1:
|
|
898
|
+
account = _context2.v;
|
|
899
|
+
nonce_by_address.set(sender, account.nonce + 1);
|
|
900
|
+
return _context2.a(2, account.nonce);
|
|
901
|
+
case 2:
|
|
902
|
+
nonce_by_address.set(sender, nonce + 1);
|
|
903
|
+
return _context2.a(2, nonce);
|
|
904
|
+
}
|
|
905
|
+
}, _callee2);
|
|
906
|
+
}));
|
|
907
|
+
return function nextNonce(_x5) {
|
|
908
|
+
return _ref2.apply(this, arguments);
|
|
909
|
+
};
|
|
910
|
+
}();
|
|
911
|
+
network$1 = this.network === 'mainnet' ? network.STACKS_MAINNET : network.STACKS_TESTNET;
|
|
912
|
+
if (this.stacksNodeAPI) {
|
|
913
|
+
network$1 = _extends({}, network$1, {
|
|
914
|
+
client: _extends({}, network$1.client, {
|
|
915
|
+
baseUrl: this.stacksNodeAPI
|
|
916
|
+
})
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
_loop = /*#__PURE__*/_regenerator().m(function _loop() {
|
|
920
|
+
var step, previousSimulation, _iterator2, _step2, _step3, _step$function_args, nonce, _step$contract_id$spl, contractAddress, contractName, tx, _nonce, _tx, _nonce2, _tx2;
|
|
921
|
+
return _regenerator().w(function (_context4) {
|
|
922
|
+
while (1) switch (_context4.n) {
|
|
923
|
+
case 0:
|
|
924
|
+
step = _step.value;
|
|
925
|
+
if (!('simulationId' in step)) {
|
|
926
|
+
_context4.n = 2;
|
|
927
|
+
break;
|
|
928
|
+
}
|
|
929
|
+
_context4.n = 1;
|
|
930
|
+
return fetch("https://api.stxer.xyz/simulations/" + step.simulationId + "/request").then(/*#__PURE__*/function () {
|
|
931
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(rs) {
|
|
932
|
+
var body;
|
|
933
|
+
return _regenerator().w(function (_context3) {
|
|
934
|
+
while (1) switch (_context3.n) {
|
|
935
|
+
case 0:
|
|
936
|
+
_context3.n = 1;
|
|
937
|
+
return rs.text();
|
|
938
|
+
case 1:
|
|
939
|
+
body = _context3.v;
|
|
940
|
+
if (body.startsWith('{')) {
|
|
941
|
+
_context3.n = 2;
|
|
942
|
+
break;
|
|
943
|
+
}
|
|
944
|
+
throw new Error("failed to get simulation " + step.simulationId + ": " + body);
|
|
945
|
+
case 2:
|
|
946
|
+
return _context3.a(2, JSON.parse(body));
|
|
947
|
+
}
|
|
948
|
+
}, _callee3);
|
|
949
|
+
}));
|
|
950
|
+
return function (_x6) {
|
|
951
|
+
return _ref3.apply(this, arguments);
|
|
952
|
+
};
|
|
953
|
+
}());
|
|
954
|
+
case 1:
|
|
955
|
+
previousSimulation = _context4.v;
|
|
956
|
+
for (_iterator2 = _createForOfIteratorHelperLoose(previousSimulation.steps); !(_step2 = _iterator2()).done;) {
|
|
957
|
+
_step3 = _step2.value;
|
|
958
|
+
if ('tx' in _step3) {
|
|
959
|
+
txs.push(transactions.deserializeTransaction(_step3.tx));
|
|
960
|
+
} else if ('code' in _step3 && 'contract' in _step3) {
|
|
961
|
+
txs.push({
|
|
962
|
+
contract_id: _step3.contract,
|
|
963
|
+
code: _step3.code
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
_context4.n = 12;
|
|
968
|
+
break;
|
|
969
|
+
case 2:
|
|
970
|
+
if (!('sender' in step && 'function_name' in step)) {
|
|
971
|
+
_context4.n = 5;
|
|
972
|
+
break;
|
|
973
|
+
}
|
|
974
|
+
_context4.n = 3;
|
|
975
|
+
return nextNonce(step.sender);
|
|
976
|
+
case 3:
|
|
977
|
+
nonce = _context4.v;
|
|
978
|
+
_step$contract_id$spl = step.contract_id.split('.'), contractAddress = _step$contract_id$spl[0], contractName = _step$contract_id$spl[1];
|
|
979
|
+
_context4.n = 4;
|
|
980
|
+
return transactions.makeUnsignedContractCall({
|
|
981
|
+
contractAddress: contractAddress,
|
|
982
|
+
contractName: contractName,
|
|
983
|
+
functionName: step.function_name,
|
|
984
|
+
functionArgs: (_step$function_args = step.function_args) != null ? _step$function_args : [],
|
|
985
|
+
nonce: nonce,
|
|
986
|
+
network: network$1,
|
|
987
|
+
publicKey: '',
|
|
988
|
+
postConditionMode: transactions.PostConditionMode.Allow,
|
|
989
|
+
fee: step.fee
|
|
990
|
+
});
|
|
991
|
+
case 4:
|
|
992
|
+
tx = _context4.v;
|
|
993
|
+
setSender(tx, step.sender);
|
|
994
|
+
txs.push(tx);
|
|
995
|
+
_context4.n = 12;
|
|
996
|
+
break;
|
|
997
|
+
case 5:
|
|
998
|
+
if (!('sender' in step && 'recipient' in step)) {
|
|
999
|
+
_context4.n = 8;
|
|
1000
|
+
break;
|
|
1001
|
+
}
|
|
1002
|
+
_context4.n = 6;
|
|
1003
|
+
return nextNonce(step.sender);
|
|
1004
|
+
case 6:
|
|
1005
|
+
_nonce = _context4.v;
|
|
1006
|
+
_context4.n = 7;
|
|
1007
|
+
return transactions.makeUnsignedSTXTokenTransfer({
|
|
1008
|
+
recipient: step.recipient,
|
|
1009
|
+
amount: step.amount,
|
|
1010
|
+
nonce: _nonce,
|
|
1011
|
+
network: network$1,
|
|
1012
|
+
publicKey: '',
|
|
1013
|
+
fee: step.fee
|
|
1014
|
+
});
|
|
1015
|
+
case 7:
|
|
1016
|
+
_tx = _context4.v;
|
|
1017
|
+
setSender(_tx, step.sender);
|
|
1018
|
+
txs.push(_tx);
|
|
1019
|
+
_context4.n = 12;
|
|
1020
|
+
break;
|
|
1021
|
+
case 8:
|
|
1022
|
+
if (!('deployer' in step)) {
|
|
1023
|
+
_context4.n = 11;
|
|
1024
|
+
break;
|
|
1025
|
+
}
|
|
1026
|
+
_context4.n = 9;
|
|
1027
|
+
return nextNonce(step.deployer);
|
|
1028
|
+
case 9:
|
|
1029
|
+
_nonce2 = _context4.v;
|
|
1030
|
+
_context4.n = 10;
|
|
1031
|
+
return transactions.makeUnsignedContractDeploy({
|
|
1032
|
+
contractName: step.contract_name,
|
|
1033
|
+
codeBody: step.source_code,
|
|
1034
|
+
nonce: _nonce2,
|
|
1035
|
+
network: network$1,
|
|
1036
|
+
publicKey: '',
|
|
1037
|
+
postConditionMode: transactions.PostConditionMode.Allow,
|
|
1038
|
+
fee: step.fee,
|
|
1039
|
+
clarityVersion: step.clarity_version
|
|
1040
|
+
});
|
|
1041
|
+
case 10:
|
|
1042
|
+
_tx2 = _context4.v;
|
|
1043
|
+
setSender(_tx2, step.deployer);
|
|
1044
|
+
txs.push(_tx2);
|
|
1045
|
+
_context4.n = 12;
|
|
1046
|
+
break;
|
|
1047
|
+
case 11:
|
|
1048
|
+
if ('code' in step) {
|
|
1049
|
+
txs.push(step);
|
|
1050
|
+
} else {
|
|
1051
|
+
console.log("Invalid simulation step: " + step);
|
|
1052
|
+
}
|
|
1053
|
+
case 12:
|
|
1054
|
+
return _context4.a(2);
|
|
1055
|
+
}
|
|
1056
|
+
}, _loop);
|
|
1057
|
+
});
|
|
1058
|
+
_iterator = _createForOfIteratorHelperLoose(this.steps);
|
|
1059
|
+
case 2:
|
|
1060
|
+
if ((_step = _iterator()).done) {
|
|
1061
|
+
_context5.n = 4;
|
|
1062
|
+
break;
|
|
1063
|
+
}
|
|
1064
|
+
return _context5.d(_regeneratorValues(_loop()), 3);
|
|
1065
|
+
case 3:
|
|
1066
|
+
_context5.n = 2;
|
|
1067
|
+
break;
|
|
1068
|
+
case 4:
|
|
1069
|
+
_context5.n = 5;
|
|
1070
|
+
return runSimulation(this.apiEndpoint + "/simulations", block.block_hash, block.block_height, txs);
|
|
1071
|
+
case 5:
|
|
1072
|
+
id = _context5.v;
|
|
1073
|
+
console.log("Simulation will be available at: https://stxer.xyz/simulations/" + this.network + "/" + id);
|
|
1074
|
+
return _context5.a(2, id);
|
|
1075
|
+
}
|
|
1076
|
+
}, _callee4, this);
|
|
1077
|
+
}));
|
|
1078
|
+
function run() {
|
|
1079
|
+
return _run.apply(this, arguments);
|
|
1080
|
+
}
|
|
1081
|
+
return run;
|
|
1082
|
+
}();
|
|
1083
|
+
_proto.pipe = function pipe(transform) {
|
|
1084
|
+
return transform(this);
|
|
1085
|
+
};
|
|
1086
|
+
return SimulationBuilder;
|
|
1087
|
+
}();
|
|
1088
|
+
|
|
1234
1089
|
exports.SimulationBuilder = SimulationBuilder;
|
|
1235
1090
|
exports.batchRead = batchRead;
|
|
1236
1091
|
exports.callReadonly = callReadonly;
|