stxer 0.4.1 → 0.4.3
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 +683 -828
- 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 +686 -831
- 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 +105 -55
|
@@ -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,525 +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$apiEndpoint, _options$stacksNodeAP, _options$network;
|
|
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.apiEndpoint = (_options$apiEndpoint = options.apiEndpoint) != null ? _options$apiEndpoint : 'https://api.stxer.xyz';
|
|
590
|
-
this.stacksNodeAPI = (_options$stacksNodeAP = options.stacksNodeAPI) != null ? _options$stacksNodeAP : 'https://api.hiro.so';
|
|
591
|
-
this.network = (_options$network = options.network) != null ? _options$network : 'mainnet';
|
|
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;
|
|
592
295
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
var _proto = SimulationBuilder.prototype;
|
|
597
|
-
_proto.useBlockHeight = function useBlockHeight(block) {
|
|
598
|
-
this.block = block;
|
|
599
|
-
return this;
|
|
600
|
-
};
|
|
601
|
-
_proto.withSender = function withSender(address) {
|
|
602
|
-
this.sender = address;
|
|
603
|
-
return this;
|
|
296
|
+
var _proto = BatchProcessor.prototype;
|
|
297
|
+
_proto.getQueueKey = function getQueueKey(tip) {
|
|
298
|
+
return tip != null ? tip : '_undefined';
|
|
604
299
|
};
|
|
605
|
-
_proto.
|
|
606
|
-
this
|
|
607
|
-
|
|
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
|
+
});
|
|
608
308
|
});
|
|
609
|
-
return this;
|
|
610
|
-
};
|
|
611
|
-
_proto.addSTXTransfer = function addSTXTransfer(params) {
|
|
612
|
-
var _params$sender, _params$fee;
|
|
613
|
-
if (params.sender == null && this.sender === '') {
|
|
614
|
-
throw new Error('Please specify a sender with useSender or adding a sender paramenter');
|
|
615
|
-
}
|
|
616
|
-
this.steps.push(_extends({}, params, {
|
|
617
|
-
sender: (_params$sender = params.sender) != null ? _params$sender : this.sender,
|
|
618
|
-
fee: (_params$fee = params.fee) != null ? _params$fee : 0
|
|
619
|
-
}));
|
|
620
|
-
return this;
|
|
621
309
|
};
|
|
622
|
-
_proto.
|
|
623
|
-
var
|
|
624
|
-
|
|
625
|
-
|
|
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);
|
|
626
317
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
_proto.addContractDeploy = function addContractDeploy(params) {
|
|
634
|
-
var _params$deployer, _params$fee3, _params$clarity_versi;
|
|
635
|
-
if (params.deployer == null && this.sender === '') {
|
|
636
|
-
throw new Error('Please specify a deployer with useSender or adding a deployer paramenter');
|
|
637
|
-
}
|
|
638
|
-
this.steps.push(_extends({}, params, {
|
|
639
|
-
deployer: (_params$deployer = params.deployer) != null ? _params$deployer : this.sender,
|
|
640
|
-
fee: (_params$fee3 = params.fee) != null ? _params$fee3 : 0,
|
|
641
|
-
clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : transactions.ClarityVersion.Clarity3
|
|
642
|
-
}));
|
|
643
|
-
return this;
|
|
644
|
-
};
|
|
645
|
-
_proto.addEvalCode = function addEvalCode(inside_contract_id, code) {
|
|
646
|
-
this.steps.push({
|
|
647
|
-
contract_id: inside_contract_id,
|
|
648
|
-
code: code
|
|
649
|
-
});
|
|
650
|
-
return this;
|
|
651
|
-
};
|
|
652
|
-
_proto.addMapRead = function addMapRead(contract_id, map, key) {
|
|
653
|
-
this.steps.push({
|
|
654
|
-
contract_id: contract_id,
|
|
655
|
-
code: "(map-get " + map + " " + key + ")"
|
|
656
|
-
});
|
|
657
|
-
return this;
|
|
658
|
-
};
|
|
659
|
-
_proto.addVarRead = function addVarRead(contract_id, variable) {
|
|
660
|
-
this.steps.push({
|
|
661
|
-
contract_id: contract_id,
|
|
662
|
-
code: "(var-get " + variable + ")"
|
|
663
|
-
});
|
|
664
|
-
return this;
|
|
665
|
-
};
|
|
666
|
-
_proto.getBlockInfo = /*#__PURE__*/function () {
|
|
667
|
-
var _getBlockInfo = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
668
|
-
var _yield$getNodeInfo, stacks_tip_height, info;
|
|
669
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
670
|
-
while (1) switch (_context.prev = _context.next) {
|
|
671
|
-
case 0:
|
|
672
|
-
if (!Number.isNaN(this.block)) {
|
|
673
|
-
_context.next = 6;
|
|
674
|
-
break;
|
|
675
|
-
}
|
|
676
|
-
_context.next = 3;
|
|
677
|
-
return tsClarity.getNodeInfo({
|
|
678
|
-
stacksEndpoint: this.stacksNodeAPI
|
|
679
|
-
});
|
|
680
|
-
case 3:
|
|
681
|
-
_yield$getNodeInfo = _context.sent;
|
|
682
|
-
stacks_tip_height = _yield$getNodeInfo.stacks_tip_height;
|
|
683
|
-
this.block = stacks_tip_height;
|
|
684
|
-
case 6:
|
|
685
|
-
_context.next = 8;
|
|
686
|
-
return tsClarity.richFetch(this.stacksNodeAPI + "/extended/v1/block/by_height/" + this.block + "?unanchored=true").then(function (r) {
|
|
687
|
-
return r.json();
|
|
688
|
-
});
|
|
689
|
-
case 8:
|
|
690
|
-
info = _context.sent;
|
|
691
|
-
if (!(info.height !== this.block || typeof info.hash !== 'string' || !info.hash.startsWith('0x'))) {
|
|
692
|
-
_context.next = 11;
|
|
693
|
-
break;
|
|
694
|
-
}
|
|
695
|
-
throw new Error("failed to get block info for block height " + this.block);
|
|
696
|
-
case 11:
|
|
697
|
-
return _context.abrupt("return", {
|
|
698
|
-
block_height: this.block,
|
|
699
|
-
block_hash: info.hash.substring(2),
|
|
700
|
-
index_block_hash: info.index_block_hash.substring(2)
|
|
701
|
-
});
|
|
702
|
-
case 12:
|
|
703
|
-
case "end":
|
|
704
|
-
return _context.stop();
|
|
705
|
-
}
|
|
706
|
-
}, _callee, this);
|
|
707
|
-
}));
|
|
708
|
-
function getBlockInfo() {
|
|
709
|
-
return _getBlockInfo.apply(this, arguments);
|
|
710
|
-
}
|
|
711
|
-
return getBlockInfo;
|
|
712
|
-
}();
|
|
713
|
-
_proto.run = /*#__PURE__*/function () {
|
|
714
|
-
var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
715
|
-
var _this = this;
|
|
716
|
-
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;
|
|
717
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
718
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
719
|
-
case 0:
|
|
720
|
-
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--------------------------------");
|
|
721
|
-
_context3.next = 3;
|
|
722
|
-
return this.getBlockInfo();
|
|
723
|
-
case 3:
|
|
724
|
-
block = _context3.sent;
|
|
725
|
-
console.log("Using block height " + block.block_height + " hash 0x" + block.block_hash + " to run simulation.");
|
|
726
|
-
txs = [];
|
|
727
|
-
nonce_by_address = new Map();
|
|
728
|
-
nextNonce = /*#__PURE__*/function () {
|
|
729
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(sender) {
|
|
730
|
-
var nonce, url, account;
|
|
731
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
732
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
733
|
-
case 0:
|
|
734
|
-
nonce = nonce_by_address.get(sender);
|
|
735
|
-
if (!(nonce == null)) {
|
|
736
|
-
_context2.next = 8;
|
|
737
|
-
break;
|
|
738
|
-
}
|
|
739
|
-
url = _this.stacksNodeAPI + "/v2/accounts/" + sender + "?proof=" + false + "&tip=" + block.index_block_hash;
|
|
740
|
-
_context2.next = 5;
|
|
741
|
-
return tsClarity.richFetch(url).then(function (r) {
|
|
742
|
-
return r.json();
|
|
743
|
-
});
|
|
744
|
-
case 5:
|
|
745
|
-
account = _context2.sent;
|
|
746
|
-
nonce_by_address.set(sender, account.nonce + 1);
|
|
747
|
-
return _context2.abrupt("return", account.nonce);
|
|
748
|
-
case 8:
|
|
749
|
-
nonce_by_address.set(sender, nonce + 1);
|
|
750
|
-
return _context2.abrupt("return", nonce);
|
|
751
|
-
case 10:
|
|
752
|
-
case "end":
|
|
753
|
-
return _context2.stop();
|
|
754
|
-
}
|
|
755
|
-
}, _callee2);
|
|
756
|
-
}));
|
|
757
|
-
return function nextNonce(_x5) {
|
|
758
|
-
return _ref2.apply(this, arguments);
|
|
759
|
-
};
|
|
760
|
-
}();
|
|
761
|
-
network$1 = this.network === 'mainnet' ? network.STACKS_MAINNET : network.STACKS_TESTNET;
|
|
762
|
-
if (this.stacksNodeAPI) {
|
|
763
|
-
network$1 = _extends({}, network$1, {
|
|
764
|
-
client: _extends({}, network$1.client, {
|
|
765
|
-
baseUrl: this.stacksNodeAPI
|
|
766
|
-
})
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
_iterator = _createForOfIteratorHelperLoose(this.steps);
|
|
770
|
-
case 11:
|
|
771
|
-
if ((_step = _iterator()).done) {
|
|
772
|
-
_context3.next = 57;
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
step = _step.value;
|
|
776
|
-
if (!('simulationId' in step)) {
|
|
777
|
-
_context3.next = 20;
|
|
778
|
-
break;
|
|
779
|
-
}
|
|
780
|
-
_context3.next = 16;
|
|
781
|
-
return fetch("https://api.stxer.xyz/simulations/" + step.simulationId + "/request").then(function (x) {
|
|
782
|
-
return x.json();
|
|
783
|
-
});
|
|
784
|
-
case 16:
|
|
785
|
-
previousSimulation = _context3.sent;
|
|
786
|
-
for (_iterator2 = _createForOfIteratorHelperLoose(previousSimulation.steps); !(_step2 = _iterator2()).done;) {
|
|
787
|
-
_step3 = _step2.value;
|
|
788
|
-
if ('tx' in _step3) {
|
|
789
|
-
txs.push(transactions.deserializeTransaction(_step3.tx));
|
|
790
|
-
} else if ('code' in _step3 && 'contract' in _step3) {
|
|
791
|
-
txs.push({
|
|
792
|
-
contract_id: _step3.contract,
|
|
793
|
-
code: _step3.code
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
_context3.next = 55;
|
|
798
|
-
break;
|
|
799
|
-
case 20:
|
|
800
|
-
if (!('sender' in step && 'function_name' in step)) {
|
|
801
|
-
_context3.next = 32;
|
|
802
|
-
break;
|
|
803
|
-
}
|
|
804
|
-
_context3.next = 23;
|
|
805
|
-
return nextNonce(step.sender);
|
|
806
|
-
case 23:
|
|
807
|
-
nonce = _context3.sent;
|
|
808
|
-
_step$contract_id$spl = step.contract_id.split('.'), contractAddress = _step$contract_id$spl[0], contractName = _step$contract_id$spl[1];
|
|
809
|
-
_context3.next = 27;
|
|
810
|
-
return transactions.makeUnsignedContractCall({
|
|
811
|
-
contractAddress: contractAddress,
|
|
812
|
-
contractName: contractName,
|
|
813
|
-
functionName: step.function_name,
|
|
814
|
-
functionArgs: (_step$function_args = step.function_args) != null ? _step$function_args : [],
|
|
815
|
-
nonce: nonce,
|
|
816
|
-
network: network$1,
|
|
817
|
-
publicKey: '',
|
|
818
|
-
postConditionMode: transactions.PostConditionMode.Allow,
|
|
819
|
-
fee: step.fee
|
|
820
|
-
});
|
|
821
|
-
case 27:
|
|
822
|
-
tx = _context3.sent;
|
|
823
|
-
tx.auth.spendingCondition.signer = c32check.c32addressDecode(step.sender)[1];
|
|
824
|
-
txs.push(tx);
|
|
825
|
-
_context3.next = 55;
|
|
826
|
-
break;
|
|
827
|
-
case 32:
|
|
828
|
-
if (!('sender' in step && 'recipient' in step)) {
|
|
829
|
-
_context3.next = 43;
|
|
830
|
-
break;
|
|
831
|
-
}
|
|
832
|
-
_context3.next = 35;
|
|
833
|
-
return nextNonce(step.sender);
|
|
834
|
-
case 35:
|
|
835
|
-
_nonce = _context3.sent;
|
|
836
|
-
_context3.next = 38;
|
|
837
|
-
return transactions.makeUnsignedSTXTokenTransfer({
|
|
838
|
-
recipient: step.recipient,
|
|
839
|
-
amount: step.amount,
|
|
840
|
-
nonce: _nonce,
|
|
841
|
-
network: network$1,
|
|
842
|
-
publicKey: '',
|
|
843
|
-
fee: step.fee
|
|
844
|
-
});
|
|
845
|
-
case 38:
|
|
846
|
-
_tx = _context3.sent;
|
|
847
|
-
_tx.auth.spendingCondition.signer = c32check.c32addressDecode(step.sender)[1];
|
|
848
|
-
txs.push(_tx);
|
|
849
|
-
_context3.next = 55;
|
|
850
|
-
break;
|
|
851
|
-
case 43:
|
|
852
|
-
if (!('deployer' in step)) {
|
|
853
|
-
_context3.next = 54;
|
|
854
|
-
break;
|
|
855
|
-
}
|
|
856
|
-
_context3.next = 46;
|
|
857
|
-
return nextNonce(step.deployer);
|
|
858
|
-
case 46:
|
|
859
|
-
_nonce2 = _context3.sent;
|
|
860
|
-
_context3.next = 49;
|
|
861
|
-
return transactions.makeUnsignedContractDeploy({
|
|
862
|
-
contractName: step.contract_name,
|
|
863
|
-
codeBody: step.source_code,
|
|
864
|
-
nonce: _nonce2,
|
|
865
|
-
network: network$1,
|
|
866
|
-
publicKey: '',
|
|
867
|
-
postConditionMode: transactions.PostConditionMode.Allow,
|
|
868
|
-
fee: step.fee
|
|
869
|
-
});
|
|
870
|
-
case 49:
|
|
871
|
-
_tx2 = _context3.sent;
|
|
872
|
-
_tx2.auth.spendingCondition.signer = c32check.c32addressDecode(step.deployer)[1];
|
|
873
|
-
txs.push(_tx2);
|
|
874
|
-
_context3.next = 55;
|
|
875
|
-
break;
|
|
876
|
-
case 54:
|
|
877
|
-
if ('code' in step) {
|
|
878
|
-
txs.push(step);
|
|
879
|
-
} else {
|
|
880
|
-
// biome-ignore lint/style/noUnusedTemplateLiteral: <explanation>
|
|
881
|
-
console.log("Invalid simulation step:", step);
|
|
882
|
-
}
|
|
883
|
-
case 55:
|
|
884
|
-
_context3.next = 11;
|
|
885
|
-
break;
|
|
886
|
-
case 57:
|
|
887
|
-
_context3.next = 59;
|
|
888
|
-
return runSimulation(this.apiEndpoint + "/simulations", block.block_hash, block.block_height, txs);
|
|
889
|
-
case 59:
|
|
890
|
-
id = _context3.sent;
|
|
891
|
-
console.log("Simulation will be available at: https://stxer.xyz/simulations/" + this.network + "/" + id);
|
|
892
|
-
return _context3.abrupt("return", id);
|
|
893
|
-
case 62:
|
|
894
|
-
case "end":
|
|
895
|
-
return _context3.stop();
|
|
896
|
-
}
|
|
897
|
-
}, _callee3, this);
|
|
898
|
-
}));
|
|
899
|
-
function run() {
|
|
900
|
-
return _run.apply(this, arguments);
|
|
901
|
-
}
|
|
902
|
-
return run;
|
|
903
|
-
}();
|
|
904
|
-
_proto.pipe = function pipe(transform) {
|
|
905
|
-
return transform(this);
|
|
906
|
-
};
|
|
907
|
-
return SimulationBuilder;
|
|
908
|
-
}();
|
|
909
|
-
|
|
910
|
-
var BatchProcessor = /*#__PURE__*/function () {
|
|
911
|
-
function BatchProcessor(options) {
|
|
912
|
-
var _options$stxerAPIEndp;
|
|
913
|
-
this.queues = new Map();
|
|
914
|
-
this.timeoutIds = new Map();
|
|
915
|
-
this.stxerAPIEndpoint = void 0;
|
|
916
|
-
this.batchDelayMs = void 0;
|
|
917
|
-
this.stxerAPIEndpoint = (_options$stxerAPIEndp = options.stxerAPIEndpoint) != null ? _options$stxerAPIEndp : 'https://api.stxer.xyz';
|
|
918
|
-
this.batchDelayMs = options.batchDelayMs;
|
|
919
|
-
}
|
|
920
|
-
var _proto = BatchProcessor.prototype;
|
|
921
|
-
_proto.getQueueKey = function getQueueKey(tip) {
|
|
922
|
-
return tip != null ? tip : '_undefined';
|
|
923
|
-
};
|
|
924
|
-
_proto.read = function read(request) {
|
|
925
|
-
var _this = this;
|
|
926
|
-
return new Promise(function (resolve, reject) {
|
|
927
|
-
_this.enqueue({
|
|
928
|
-
request: request,
|
|
929
|
-
resolve: resolve,
|
|
930
|
-
reject: reject
|
|
931
|
-
});
|
|
932
|
-
});
|
|
933
|
-
};
|
|
934
|
-
_proto.enqueue = function enqueue(request) {
|
|
935
|
-
var _this$queues$get,
|
|
936
|
-
_this2 = this;
|
|
937
|
-
var queueKey = this.getQueueKey(request.tip);
|
|
938
|
-
var queue = (_this$queues$get = this.queues.get(queueKey)) != null ? _this$queues$get : [];
|
|
939
|
-
if (!this.queues.has(queueKey)) {
|
|
940
|
-
this.queues.set(queueKey, queue);
|
|
941
|
-
}
|
|
942
|
-
queue.push(request);
|
|
943
|
-
if (!this.timeoutIds.has(queueKey)) {
|
|
944
|
-
var timeoutId = setTimeout(function () {
|
|
945
|
-
return _this2.processBatch(queueKey);
|
|
946
|
-
}, this.batchDelayMs);
|
|
947
|
-
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);
|
|
948
324
|
}
|
|
949
325
|
};
|
|
950
326
|
_proto.processBatch = /*#__PURE__*/function () {
|
|
951
|
-
var _processBatch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/
|
|
327
|
+
var _processBatch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(queueKey) {
|
|
952
328
|
var _this$queues$get2;
|
|
953
|
-
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;
|
|
954
|
-
return
|
|
955
|
-
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) {
|
|
956
332
|
case 0:
|
|
957
333
|
currentQueue = (_this$queues$get2 = this.queues.get(queueKey)) != null ? _this$queues$get2 : [];
|
|
958
334
|
this.queues["delete"](queueKey);
|
|
@@ -962,12 +338,12 @@ var BatchProcessor = /*#__PURE__*/function () {
|
|
|
962
338
|
this.timeoutIds["delete"](queueKey);
|
|
963
339
|
}
|
|
964
340
|
if (!(currentQueue.length === 0)) {
|
|
965
|
-
_context.
|
|
341
|
+
_context.n = 1;
|
|
966
342
|
break;
|
|
967
343
|
}
|
|
968
|
-
return _context.
|
|
969
|
-
case
|
|
970
|
-
_context.
|
|
344
|
+
return _context.a(2);
|
|
345
|
+
case 1:
|
|
346
|
+
_context.p = 1;
|
|
971
347
|
readonlyRequests = currentQueue.filter(function (q) {
|
|
972
348
|
return q.request.mode === 'readonly';
|
|
973
349
|
});
|
|
@@ -1004,12 +380,12 @@ var BatchProcessor = /*#__PURE__*/function () {
|
|
|
1004
380
|
}),
|
|
1005
381
|
index_block_hash: tip
|
|
1006
382
|
};
|
|
1007
|
-
_context.
|
|
383
|
+
_context.n = 2;
|
|
1008
384
|
return batchRead(batchRequest, {
|
|
1009
385
|
stxerApi: this.stxerAPIEndpoint
|
|
1010
386
|
});
|
|
1011
|
-
case
|
|
1012
|
-
results = _context.
|
|
387
|
+
case 2:
|
|
388
|
+
results = _context.v;
|
|
1013
389
|
// Handle readonly results
|
|
1014
390
|
for (_iterator = _createForOfIteratorHelperLoose(results.readonly.entries()); !(_step = _iterator()).done;) {
|
|
1015
391
|
_step$value = _step.value, index = _step$value[0], result = _step$value[1];
|
|
@@ -1037,20 +413,19 @@ var BatchProcessor = /*#__PURE__*/function () {
|
|
|
1037
413
|
mapRequests[_index2].resolve(_result2);
|
|
1038
414
|
}
|
|
1039
415
|
}
|
|
1040
|
-
_context.
|
|
416
|
+
_context.n = 4;
|
|
1041
417
|
break;
|
|
1042
|
-
case
|
|
1043
|
-
_context.
|
|
1044
|
-
|
|
418
|
+
case 3:
|
|
419
|
+
_context.p = 3;
|
|
420
|
+
_t = _context.v;
|
|
1045
421
|
for (_iterator4 = _createForOfIteratorHelperLoose(currentQueue); !(_step4 = _iterator4()).done;) {
|
|
1046
422
|
item = _step4.value;
|
|
1047
|
-
item.reject(
|
|
423
|
+
item.reject(_t);
|
|
1048
424
|
}
|
|
1049
|
-
case
|
|
1050
|
-
|
|
1051
|
-
return _context.stop();
|
|
425
|
+
case 4:
|
|
426
|
+
return _context.a(2);
|
|
1052
427
|
}
|
|
1053
|
-
}, _callee, this, [[
|
|
428
|
+
}, _callee, this, [[1, 3]]);
|
|
1054
429
|
}));
|
|
1055
430
|
function processBatch(_x) {
|
|
1056
431
|
return _processBatch.apply(this, arguments);
|
|
@@ -1068,11 +443,11 @@ function callReadonly(_x) {
|
|
|
1068
443
|
return _callReadonly.apply(this, arguments);
|
|
1069
444
|
}
|
|
1070
445
|
function _callReadonly() {
|
|
1071
|
-
_callReadonly = _asyncToGenerator(/*#__PURE__*/
|
|
446
|
+
_callReadonly = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
1072
447
|
var _params$batchProcesso;
|
|
1073
448
|
var processor, _params$contract$spli, deployer, contractName, fn, functionDef, argsKV, args, _iterator, _step, argDef;
|
|
1074
|
-
return
|
|
1075
|
-
while (1) switch (_context.
|
|
449
|
+
return _regenerator().w(function (_context) {
|
|
450
|
+
while (1) switch (_context.n) {
|
|
1076
451
|
case 0:
|
|
1077
452
|
processor = (_params$batchProcesso = params.batchProcessor) != null ? _params$batchProcesso : defaultProcessor;
|
|
1078
453
|
_params$contract$spli = params.contract.split('.', 2), deployer = _params$contract$spli[0], contractName = _params$contract$spli[1];
|
|
@@ -1081,18 +456,18 @@ function _callReadonly() {
|
|
|
1081
456
|
return def.name === params.functionName;
|
|
1082
457
|
});
|
|
1083
458
|
if (functionDef) {
|
|
1084
|
-
_context.
|
|
459
|
+
_context.n = 1;
|
|
1085
460
|
break;
|
|
1086
461
|
}
|
|
1087
462
|
throw new Error("failed to find function definition for " + params.functionName);
|
|
1088
|
-
case
|
|
463
|
+
case 1:
|
|
1089
464
|
argsKV = params.args;
|
|
1090
465
|
args = [];
|
|
1091
466
|
for (_iterator = _createForOfIteratorHelperLoose(functionDef.args); !(_step = _iterator()).done;) {
|
|
1092
467
|
argDef = _step.value;
|
|
1093
468
|
args.push(tsClarity.encodeAbi(argDef.type, argsKV[argDef.name]));
|
|
1094
469
|
}
|
|
1095
|
-
return _context.
|
|
470
|
+
return _context.a(2, new Promise(function (_resolve, reject) {
|
|
1096
471
|
processor.enqueue({
|
|
1097
472
|
request: {
|
|
1098
473
|
mode: 'readonly',
|
|
@@ -1113,9 +488,6 @@ function _callReadonly() {
|
|
|
1113
488
|
reject: reject
|
|
1114
489
|
});
|
|
1115
490
|
}));
|
|
1116
|
-
case 10:
|
|
1117
|
-
case "end":
|
|
1118
|
-
return _context.stop();
|
|
1119
491
|
}
|
|
1120
492
|
}, _callee);
|
|
1121
493
|
}));
|
|
@@ -1125,11 +497,11 @@ function readMap(_x2) {
|
|
|
1125
497
|
return _readMap.apply(this, arguments);
|
|
1126
498
|
}
|
|
1127
499
|
function _readMap() {
|
|
1128
|
-
_readMap = _asyncToGenerator(/*#__PURE__*/
|
|
500
|
+
_readMap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(params) {
|
|
1129
501
|
var _params$batchProcesso2;
|
|
1130
502
|
var processor, _params$contract$spli2, deployer, contractName, mapDef, key;
|
|
1131
|
-
return
|
|
1132
|
-
while (1) switch (_context2.
|
|
503
|
+
return _regenerator().w(function (_context2) {
|
|
504
|
+
while (1) switch (_context2.n) {
|
|
1133
505
|
case 0:
|
|
1134
506
|
processor = (_params$batchProcesso2 = params.batchProcessor) != null ? _params$batchProcesso2 : defaultProcessor;
|
|
1135
507
|
_params$contract$spli2 = params.contract.split('.', 2), deployer = _params$contract$spli2[0], contractName = _params$contract$spli2[1];
|
|
@@ -1137,13 +509,13 @@ function _readMap() {
|
|
|
1137
509
|
return m.name === params.mapName;
|
|
1138
510
|
});
|
|
1139
511
|
if (mapDef) {
|
|
1140
|
-
_context2.
|
|
512
|
+
_context2.n = 1;
|
|
1141
513
|
break;
|
|
1142
514
|
}
|
|
1143
515
|
throw new Error("failed to find map definition for " + params.mapName);
|
|
1144
|
-
case
|
|
516
|
+
case 1:
|
|
1145
517
|
key = tsClarity.encodeAbi(mapDef.key, params.key);
|
|
1146
|
-
return _context2.
|
|
518
|
+
return _context2.a(2, new Promise(function (_resolve2, reject) {
|
|
1147
519
|
processor.enqueue({
|
|
1148
520
|
request: {
|
|
1149
521
|
mode: 'mapEntry',
|
|
@@ -1172,9 +544,6 @@ function _readMap() {
|
|
|
1172
544
|
reject: reject
|
|
1173
545
|
});
|
|
1174
546
|
}));
|
|
1175
|
-
case 7:
|
|
1176
|
-
case "end":
|
|
1177
|
-
return _context2.stop();
|
|
1178
547
|
}
|
|
1179
548
|
}, _callee2);
|
|
1180
549
|
}));
|
|
@@ -1184,11 +553,11 @@ function readVariable(_x3) {
|
|
|
1184
553
|
return _readVariable.apply(this, arguments);
|
|
1185
554
|
}
|
|
1186
555
|
function _readVariable() {
|
|
1187
|
-
_readVariable = _asyncToGenerator(/*#__PURE__*/
|
|
556
|
+
_readVariable = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(params) {
|
|
1188
557
|
var _params$batchProcesso3;
|
|
1189
558
|
var processor, _params$contract$spli3, deployer, contractName, varDef;
|
|
1190
|
-
return
|
|
1191
|
-
while (1) switch (_context3.
|
|
559
|
+
return _regenerator().w(function (_context3) {
|
|
560
|
+
while (1) switch (_context3.n) {
|
|
1192
561
|
case 0:
|
|
1193
562
|
processor = (_params$batchProcesso3 = params.batchProcessor) != null ? _params$batchProcesso3 : defaultProcessor;
|
|
1194
563
|
_params$contract$spli3 = params.contract.split('.', 2), deployer = _params$contract$spli3[0], contractName = _params$contract$spli3[1];
|
|
@@ -1196,12 +565,12 @@ function _readVariable() {
|
|
|
1196
565
|
return def.name === params.variableName;
|
|
1197
566
|
});
|
|
1198
567
|
if (varDef) {
|
|
1199
|
-
_context3.
|
|
568
|
+
_context3.n = 1;
|
|
1200
569
|
break;
|
|
1201
570
|
}
|
|
1202
571
|
throw new Error("failed to find variable definition for " + params.variableName);
|
|
1203
|
-
case
|
|
1204
|
-
return _context3.
|
|
572
|
+
case 1:
|
|
573
|
+
return _context3.a(2, new Promise(function (_resolve3, reject) {
|
|
1205
574
|
processor.enqueue({
|
|
1206
575
|
request: {
|
|
1207
576
|
mode: 'variable',
|
|
@@ -1221,15 +590,501 @@ function _readVariable() {
|
|
|
1221
590
|
reject: reject
|
|
1222
591
|
});
|
|
1223
592
|
}));
|
|
1224
|
-
case 6:
|
|
1225
|
-
case "end":
|
|
1226
|
-
return _context3.stop();
|
|
1227
593
|
}
|
|
1228
594
|
}, _callee3);
|
|
1229
595
|
}));
|
|
1230
596
|
return _readVariable.apply(this, arguments);
|
|
1231
597
|
}
|
|
1232
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.Clarity3
|
|
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
|
+
});
|
|
1040
|
+
case 10:
|
|
1041
|
+
_tx2 = _context4.v;
|
|
1042
|
+
setSender(_tx2, step.deployer);
|
|
1043
|
+
txs.push(_tx2);
|
|
1044
|
+
_context4.n = 12;
|
|
1045
|
+
break;
|
|
1046
|
+
case 11:
|
|
1047
|
+
if ('code' in step) {
|
|
1048
|
+
txs.push(step);
|
|
1049
|
+
} else {
|
|
1050
|
+
console.log("Invalid simulation step: " + step);
|
|
1051
|
+
}
|
|
1052
|
+
case 12:
|
|
1053
|
+
return _context4.a(2);
|
|
1054
|
+
}
|
|
1055
|
+
}, _loop);
|
|
1056
|
+
});
|
|
1057
|
+
_iterator = _createForOfIteratorHelperLoose(this.steps);
|
|
1058
|
+
case 2:
|
|
1059
|
+
if ((_step = _iterator()).done) {
|
|
1060
|
+
_context5.n = 4;
|
|
1061
|
+
break;
|
|
1062
|
+
}
|
|
1063
|
+
return _context5.d(_regeneratorValues(_loop()), 3);
|
|
1064
|
+
case 3:
|
|
1065
|
+
_context5.n = 2;
|
|
1066
|
+
break;
|
|
1067
|
+
case 4:
|
|
1068
|
+
_context5.n = 5;
|
|
1069
|
+
return runSimulation(this.apiEndpoint + "/simulations", block.block_hash, block.block_height, txs);
|
|
1070
|
+
case 5:
|
|
1071
|
+
id = _context5.v;
|
|
1072
|
+
console.log("Simulation will be available at: https://stxer.xyz/simulations/" + this.network + "/" + id);
|
|
1073
|
+
return _context5.a(2, id);
|
|
1074
|
+
}
|
|
1075
|
+
}, _callee4, this);
|
|
1076
|
+
}));
|
|
1077
|
+
function run() {
|
|
1078
|
+
return _run.apply(this, arguments);
|
|
1079
|
+
}
|
|
1080
|
+
return run;
|
|
1081
|
+
}();
|
|
1082
|
+
_proto.pipe = function pipe(transform) {
|
|
1083
|
+
return transform(this);
|
|
1084
|
+
};
|
|
1085
|
+
return SimulationBuilder;
|
|
1086
|
+
}();
|
|
1087
|
+
|
|
1233
1088
|
exports.SimulationBuilder = SimulationBuilder;
|
|
1234
1089
|
exports.batchRead = batchRead;
|
|
1235
1090
|
exports.callReadonly = callReadonly;
|