stxer 0.4.5 → 0.7.0
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/README.md +388 -18
- package/dist/ast.d.ts +32 -0
- package/dist/{BatchAPI.d.ts → batch-api.d.ts} +2 -1
- package/dist/clarity-api.d.ts +1 -1
- package/dist/constants.d.ts +9 -0
- package/dist/index.d.ts +6 -1
- package/dist/simulation-api.d.ts +138 -0
- package/dist/simulation.d.ts +12 -4
- package/dist/stxer.cjs.development.js +705 -287
- 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 +696 -288
- package/dist/stxer.esm.js.map +1 -1
- package/dist/tip.d.ts +16 -0
- package/dist/types.d.ts +598 -0
- package/package.json +19 -12
- package/src/ast.ts +120 -0
- package/src/{BatchAPI.ts → batch-api.ts} +9 -8
- package/src/{BatchProcessor.ts → batch-processor.ts} +1 -1
- package/src/clarity-api.ts +1 -1
- package/src/constants.ts +12 -0
- package/src/index.ts +10 -1
- package/src/simulation-api.ts +273 -0
- package/src/simulation.ts +169 -138
- package/src/tip.ts +42 -0
- package/src/types.ts +700 -0
- package/dist/sample/counter.d.ts +0 -1
- package/dist/sample/read.d.ts +0 -1
- package/src/sample/counter.ts +0 -42
- package/src/sample/read.ts +0 -139
- /package/dist/{BatchProcessor.d.ts → batch-processor.d.ts} +0 -0
|
@@ -171,23 +171,6 @@ function _regeneratorDefine(e, r, n, t) {
|
|
|
171
171
|
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
172
172
|
}, _regeneratorDefine(e, r, n, t);
|
|
173
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
|
-
};
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
190
|
-
}
|
|
191
174
|
function _unsupportedIterableToArray(r, a) {
|
|
192
175
|
if (r) {
|
|
193
176
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -196,10 +179,127 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
196
179
|
}
|
|
197
180
|
}
|
|
198
181
|
|
|
182
|
+
/**
|
|
183
|
+
* API endpoint constants
|
|
184
|
+
*/
|
|
185
|
+
/** Default stxer API endpoint for mainnet */
|
|
186
|
+
var STXER_API_MAINNET = 'https://api.stxer.xyz';
|
|
187
|
+
/** stxer API endpoint for testnet */
|
|
188
|
+
var STXER_API_TESTNET = 'https://testnet-api.stxer.xyz';
|
|
189
|
+
/** Default stxer API endpoint (mainnet) */
|
|
190
|
+
var DEFAULT_STXER_API$1 = STXER_API_MAINNET;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Fetch the AST for an on-chain contract.
|
|
194
|
+
* @param options - Contract ID and optional API endpoint
|
|
195
|
+
* @returns The contract AST with metadata
|
|
196
|
+
*/
|
|
197
|
+
function getContractAST(_x) {
|
|
198
|
+
return _getContractAST.apply(this, arguments);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Parse contract source code into an AST.
|
|
202
|
+
* @param options - Source code, contract ID, and optional configuration
|
|
203
|
+
* @returns The parsed contract AST
|
|
204
|
+
*/
|
|
205
|
+
function _getContractAST() {
|
|
206
|
+
_getContractAST = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
207
|
+
var _options$stxerApi;
|
|
208
|
+
var url, response, text;
|
|
209
|
+
return _regenerator().w(function (_context) {
|
|
210
|
+
while (1) switch (_context.n) {
|
|
211
|
+
case 0:
|
|
212
|
+
url = ((_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API$1) + "/contracts/" + options.contractId;
|
|
213
|
+
_context.n = 1;
|
|
214
|
+
return fetch(url, {
|
|
215
|
+
method: 'GET',
|
|
216
|
+
headers: {
|
|
217
|
+
Accept: 'application/json'
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
case 1:
|
|
221
|
+
response = _context.v;
|
|
222
|
+
if (response.ok) {
|
|
223
|
+
_context.n = 2;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
throw new Error("Failed to fetch contract AST: " + response.status + " " + response.statusText);
|
|
227
|
+
case 2:
|
|
228
|
+
_context.n = 3;
|
|
229
|
+
return response.text();
|
|
230
|
+
case 3:
|
|
231
|
+
text = _context.v;
|
|
232
|
+
if (text.startsWith('{')) {
|
|
233
|
+
_context.n = 4;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
throw new Error("Invalid response from contracts endpoint: " + text);
|
|
237
|
+
case 4:
|
|
238
|
+
return _context.a(2, JSON.parse(text));
|
|
239
|
+
}
|
|
240
|
+
}, _callee);
|
|
241
|
+
}));
|
|
242
|
+
return _getContractAST.apply(this, arguments);
|
|
243
|
+
}
|
|
244
|
+
function parseContract(_x2) {
|
|
245
|
+
return _parseContract.apply(this, arguments);
|
|
246
|
+
}
|
|
247
|
+
function _parseContract() {
|
|
248
|
+
_parseContract = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
249
|
+
var _options$stxerApi2;
|
|
250
|
+
var url, payload, response, text;
|
|
251
|
+
return _regenerator().w(function (_context2) {
|
|
252
|
+
while (1) switch (_context2.n) {
|
|
253
|
+
case 0:
|
|
254
|
+
url = ((_options$stxerApi2 = options.stxerApi) != null ? _options$stxerApi2 : DEFAULT_STXER_API$1) + "/contracts:parse";
|
|
255
|
+
payload = {
|
|
256
|
+
contract_id: options.contractId,
|
|
257
|
+
source_code: options.sourceCode
|
|
258
|
+
};
|
|
259
|
+
if (options.clarityVersion !== undefined) {
|
|
260
|
+
payload.clarity_version = options.clarityVersion;
|
|
261
|
+
}
|
|
262
|
+
if (options.epoch !== undefined) {
|
|
263
|
+
payload.epoch = options.epoch;
|
|
264
|
+
}
|
|
265
|
+
_context2.n = 1;
|
|
266
|
+
return fetch(url, {
|
|
267
|
+
method: 'POST',
|
|
268
|
+
body: JSON.stringify(payload),
|
|
269
|
+
headers: {
|
|
270
|
+
'Content-Type': 'application/json',
|
|
271
|
+
Accept: 'application/json'
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
case 1:
|
|
275
|
+
response = _context2.v;
|
|
276
|
+
if (response.ok) {
|
|
277
|
+
_context2.n = 2;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
throw new Error("Failed to parse contract: " + response.status + " " + response.statusText);
|
|
281
|
+
case 2:
|
|
282
|
+
_context2.n = 3;
|
|
283
|
+
return response.text();
|
|
284
|
+
case 3:
|
|
285
|
+
text = _context2.v;
|
|
286
|
+
if (text.startsWith('{')) {
|
|
287
|
+
_context2.n = 4;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
throw new Error("Invalid response from contract parse endpoint: " + text);
|
|
291
|
+
case 4:
|
|
292
|
+
return _context2.a(2, JSON.parse(text));
|
|
293
|
+
}
|
|
294
|
+
}, _callee2);
|
|
295
|
+
}));
|
|
296
|
+
return _parseContract.apply(this, arguments);
|
|
297
|
+
}
|
|
298
|
+
|
|
199
299
|
var DEFAULT_STXER_API = 'https://api.stxer.xyz';
|
|
200
300
|
function convertResults(rs) {
|
|
201
301
|
var results = [];
|
|
202
|
-
for (var _iterator = _createForOfIteratorHelperLoose(rs), _step; !(_step = _iterator()).done;) {
|
|
302
|
+
for (var _iterator = _createForOfIteratorHelperLoose(rs != null ? rs : []), _step; !(_step = _iterator()).done;) {
|
|
203
303
|
var v = _step.value;
|
|
204
304
|
if ('Ok' in v) {
|
|
205
305
|
results.push(transactions.deserializeCV(v.Ok));
|
|
@@ -272,7 +372,7 @@ function _batchRead() {
|
|
|
272
372
|
case 3:
|
|
273
373
|
rs = JSON.parse(text);
|
|
274
374
|
return _context.a(2, {
|
|
275
|
-
|
|
375
|
+
index_block_hash: rs.index_block_hash,
|
|
276
376
|
vars: convertResults(rs.vars),
|
|
277
377
|
maps: convertResults(rs.maps),
|
|
278
378
|
readonly: convertResults(rs.readonly)
|
|
@@ -596,6 +696,325 @@ function _readVariable() {
|
|
|
596
696
|
return _readVariable.apply(this, arguments);
|
|
597
697
|
}
|
|
598
698
|
|
|
699
|
+
/**
|
|
700
|
+
* Instantly simulate a transaction
|
|
701
|
+
*
|
|
702
|
+
* This is useful for apps/wallets to get the result of a transaction before sending it.
|
|
703
|
+
* Lightweight - no debug tracing information.
|
|
704
|
+
*
|
|
705
|
+
* @param request - Instant simulation request
|
|
706
|
+
* @param options - API options
|
|
707
|
+
* @returns Instant simulation response with receipt and optional reads
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* import { instantSimulation } from 'stxer';
|
|
712
|
+
*
|
|
713
|
+
* const result = await instantSimulation({
|
|
714
|
+
* transaction: '0x...',
|
|
715
|
+
* block_height: 130818,
|
|
716
|
+
* block_hash: '0x...',
|
|
717
|
+
* reads: [
|
|
718
|
+
* { DataVar: ['SP...contract', 'my-var'] },
|
|
719
|
+
* { StxBalance: 'SP...' }
|
|
720
|
+
* ]
|
|
721
|
+
* });
|
|
722
|
+
* console.log(result.receipt.result);
|
|
723
|
+
* ```
|
|
724
|
+
*/
|
|
725
|
+
function instantSimulation(_x, _x2) {
|
|
726
|
+
return _instantSimulation.apply(this, arguments);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Create a new simulation session
|
|
730
|
+
*
|
|
731
|
+
* A session allows you to run multiple steps in a forked chain state.
|
|
732
|
+
*
|
|
733
|
+
* @param options - Create session options
|
|
734
|
+
* @param apiOptions - API options
|
|
735
|
+
* @returns Session ID
|
|
736
|
+
*
|
|
737
|
+
* @example
|
|
738
|
+
* ```typescript
|
|
739
|
+
* import { createSimulationSession } from 'stxer';
|
|
740
|
+
*
|
|
741
|
+
* const sessionId = await createSimulationSession({
|
|
742
|
+
* block_height: 130818,
|
|
743
|
+
* skip_tracing: false
|
|
744
|
+
* });
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
747
|
+
function _instantSimulation() {
|
|
748
|
+
_instantSimulation = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(request, options) {
|
|
749
|
+
var _options$stxerApi;
|
|
750
|
+
var apiEndpoint, response, text;
|
|
751
|
+
return _regenerator().w(function (_context) {
|
|
752
|
+
while (1) switch (_context.n) {
|
|
753
|
+
case 0:
|
|
754
|
+
if (options === void 0) {
|
|
755
|
+
options = {};
|
|
756
|
+
}
|
|
757
|
+
apiEndpoint = (_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API$1;
|
|
758
|
+
_context.n = 1;
|
|
759
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations:instant", {
|
|
760
|
+
method: 'POST',
|
|
761
|
+
body: JSON.stringify(request),
|
|
762
|
+
headers: {
|
|
763
|
+
'Content-Type': 'application/json',
|
|
764
|
+
Accept: 'application/json'
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
case 1:
|
|
768
|
+
response = _context.v;
|
|
769
|
+
if (response.ok) {
|
|
770
|
+
_context.n = 3;
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
_context.n = 2;
|
|
774
|
+
return response.text();
|
|
775
|
+
case 2:
|
|
776
|
+
text = _context.v;
|
|
777
|
+
throw new Error("Instant simulation failed: " + text);
|
|
778
|
+
case 3:
|
|
779
|
+
return _context.a(2, response.json());
|
|
780
|
+
}
|
|
781
|
+
}, _callee);
|
|
782
|
+
}));
|
|
783
|
+
return _instantSimulation.apply(this, arguments);
|
|
784
|
+
}
|
|
785
|
+
function createSimulationSession(_x3, _x4) {
|
|
786
|
+
return _createSimulationSession.apply(this, arguments);
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Submit steps to a simulation session
|
|
790
|
+
*
|
|
791
|
+
* Steps are executed sequentially in the session's forked chain state.
|
|
792
|
+
*
|
|
793
|
+
* @param sessionId - Simulation session ID
|
|
794
|
+
* @param request - Steps to submit
|
|
795
|
+
* @param options - API options
|
|
796
|
+
* @returns Array of step results
|
|
797
|
+
*
|
|
798
|
+
* @example
|
|
799
|
+
* ```typescript
|
|
800
|
+
* import { submitSimulationSteps } from 'stxer';
|
|
801
|
+
*
|
|
802
|
+
* const results = await submitSimulationSteps(sessionId, {
|
|
803
|
+
* steps: [
|
|
804
|
+
* { Transaction: '0x...' },
|
|
805
|
+
* { Eval: ['SP...', '', 'SP...contract', '(var-get my-var)'] },
|
|
806
|
+
* { Reads: [{ DataVar: ['SP...contract', 'my-var'] }] }
|
|
807
|
+
* ]
|
|
808
|
+
* });
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
function _createSimulationSession() {
|
|
812
|
+
_createSimulationSession = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options, apiOptions) {
|
|
813
|
+
var _apiOptions$stxerApi;
|
|
814
|
+
var apiEndpoint, response, text, result;
|
|
815
|
+
return _regenerator().w(function (_context2) {
|
|
816
|
+
while (1) switch (_context2.n) {
|
|
817
|
+
case 0:
|
|
818
|
+
if (options === void 0) {
|
|
819
|
+
options = {};
|
|
820
|
+
}
|
|
821
|
+
if (apiOptions === void 0) {
|
|
822
|
+
apiOptions = {};
|
|
823
|
+
}
|
|
824
|
+
apiEndpoint = (_apiOptions$stxerApi = apiOptions.stxerApi) != null ? _apiOptions$stxerApi : DEFAULT_STXER_API$1;
|
|
825
|
+
_context2.n = 1;
|
|
826
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations", {
|
|
827
|
+
method: 'POST',
|
|
828
|
+
body: JSON.stringify(options),
|
|
829
|
+
headers: {
|
|
830
|
+
'Content-Type': 'application/json',
|
|
831
|
+
Accept: 'application/json'
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
case 1:
|
|
835
|
+
response = _context2.v;
|
|
836
|
+
if (response.ok) {
|
|
837
|
+
_context2.n = 3;
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
_context2.n = 2;
|
|
841
|
+
return response.text();
|
|
842
|
+
case 2:
|
|
843
|
+
text = _context2.v;
|
|
844
|
+
throw new Error("Failed to create simulation session: " + text);
|
|
845
|
+
case 3:
|
|
846
|
+
_context2.n = 4;
|
|
847
|
+
return response.json();
|
|
848
|
+
case 4:
|
|
849
|
+
result = _context2.v;
|
|
850
|
+
return _context2.a(2, result.id);
|
|
851
|
+
}
|
|
852
|
+
}, _callee2);
|
|
853
|
+
}));
|
|
854
|
+
return _createSimulationSession.apply(this, arguments);
|
|
855
|
+
}
|
|
856
|
+
function submitSimulationSteps(_x5, _x6, _x7) {
|
|
857
|
+
return _submitSimulationSteps.apply(this, arguments);
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Get simulation session results
|
|
861
|
+
*
|
|
862
|
+
* Returns the full simulation result including metadata and all step results.
|
|
863
|
+
*
|
|
864
|
+
* @param sessionId - Simulation session ID
|
|
865
|
+
* @param options - API options
|
|
866
|
+
* @returns Complete simulation result
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
869
|
+
* ```typescript
|
|
870
|
+
* import { getSimulationResult } from 'stxer';
|
|
871
|
+
*
|
|
872
|
+
* const result = await getSimulationResult(sessionId);
|
|
873
|
+
* console.log(result.metadata);
|
|
874
|
+
* console.log(result.steps);
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
function _submitSimulationSteps() {
|
|
878
|
+
_submitSimulationSteps = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(sessionId, request, options) {
|
|
879
|
+
var _options$stxerApi2;
|
|
880
|
+
var apiEndpoint, response, text;
|
|
881
|
+
return _regenerator().w(function (_context3) {
|
|
882
|
+
while (1) switch (_context3.n) {
|
|
883
|
+
case 0:
|
|
884
|
+
if (options === void 0) {
|
|
885
|
+
options = {};
|
|
886
|
+
}
|
|
887
|
+
apiEndpoint = (_options$stxerApi2 = options.stxerApi) != null ? _options$stxerApi2 : DEFAULT_STXER_API$1;
|
|
888
|
+
_context3.n = 1;
|
|
889
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
|
|
890
|
+
method: 'POST',
|
|
891
|
+
body: JSON.stringify(request),
|
|
892
|
+
headers: {
|
|
893
|
+
'Content-Type': 'application/json',
|
|
894
|
+
Accept: 'application/json'
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
case 1:
|
|
898
|
+
response = _context3.v;
|
|
899
|
+
if (response.ok) {
|
|
900
|
+
_context3.n = 3;
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
_context3.n = 2;
|
|
904
|
+
return response.text();
|
|
905
|
+
case 2:
|
|
906
|
+
text = _context3.v;
|
|
907
|
+
throw new Error("Failed to submit simulation steps: " + text);
|
|
908
|
+
case 3:
|
|
909
|
+
return _context3.a(2, response.json());
|
|
910
|
+
}
|
|
911
|
+
}, _callee3);
|
|
912
|
+
}));
|
|
913
|
+
return _submitSimulationSteps.apply(this, arguments);
|
|
914
|
+
}
|
|
915
|
+
function getSimulationResult(_x8, _x9) {
|
|
916
|
+
return _getSimulationResult.apply(this, arguments);
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Batch reads from a simulation session
|
|
920
|
+
*
|
|
921
|
+
* Similar to sidecar batch reads, but reads from the simulation's forked state.
|
|
922
|
+
*
|
|
923
|
+
* @param sessionId - Simulation session ID
|
|
924
|
+
* @param request - Batch reads request
|
|
925
|
+
* @param options - API options
|
|
926
|
+
* @returns Batch read results
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```typescript
|
|
930
|
+
* import { simulationBatchReads } from 'stxer';
|
|
931
|
+
*
|
|
932
|
+
* const results = await simulationBatchReads(sessionId, {
|
|
933
|
+
* vars: [['SP...contract', 'my-var']],
|
|
934
|
+
* maps: [['SP...contract', 'my-map', '0x...']],
|
|
935
|
+
* stx: ['SP...']
|
|
936
|
+
* });
|
|
937
|
+
* console.log(results.vars);
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
940
|
+
function _getSimulationResult() {
|
|
941
|
+
_getSimulationResult = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(sessionId, options) {
|
|
942
|
+
var _options$stxerApi3;
|
|
943
|
+
var apiEndpoint, response, text;
|
|
944
|
+
return _regenerator().w(function (_context4) {
|
|
945
|
+
while (1) switch (_context4.n) {
|
|
946
|
+
case 0:
|
|
947
|
+
if (options === void 0) {
|
|
948
|
+
options = {};
|
|
949
|
+
}
|
|
950
|
+
apiEndpoint = (_options$stxerApi3 = options.stxerApi) != null ? _options$stxerApi3 : DEFAULT_STXER_API$1;
|
|
951
|
+
_context4.n = 1;
|
|
952
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
|
|
953
|
+
method: 'GET',
|
|
954
|
+
headers: {
|
|
955
|
+
Accept: 'application/json'
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
case 1:
|
|
959
|
+
response = _context4.v;
|
|
960
|
+
if (response.ok) {
|
|
961
|
+
_context4.n = 3;
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
964
|
+
_context4.n = 2;
|
|
965
|
+
return response.text();
|
|
966
|
+
case 2:
|
|
967
|
+
text = _context4.v;
|
|
968
|
+
throw new Error("Failed to get simulation result: " + text);
|
|
969
|
+
case 3:
|
|
970
|
+
return _context4.a(2, response.json());
|
|
971
|
+
}
|
|
972
|
+
}, _callee4);
|
|
973
|
+
}));
|
|
974
|
+
return _getSimulationResult.apply(this, arguments);
|
|
975
|
+
}
|
|
976
|
+
function simulationBatchReads(_x0, _x1, _x10) {
|
|
977
|
+
return _simulationBatchReads.apply(this, arguments);
|
|
978
|
+
}
|
|
979
|
+
function _simulationBatchReads() {
|
|
980
|
+
_simulationBatchReads = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(sessionId, request, options) {
|
|
981
|
+
var _options$stxerApi4;
|
|
982
|
+
var apiEndpoint, response, text;
|
|
983
|
+
return _regenerator().w(function (_context5) {
|
|
984
|
+
while (1) switch (_context5.n) {
|
|
985
|
+
case 0:
|
|
986
|
+
if (options === void 0) {
|
|
987
|
+
options = {};
|
|
988
|
+
}
|
|
989
|
+
apiEndpoint = (_options$stxerApi4 = options.stxerApi) != null ? _options$stxerApi4 : DEFAULT_STXER_API$1;
|
|
990
|
+
_context5.n = 1;
|
|
991
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId + "/reads", {
|
|
992
|
+
method: 'POST',
|
|
993
|
+
body: JSON.stringify(request),
|
|
994
|
+
headers: {
|
|
995
|
+
'Content-Type': 'application/json',
|
|
996
|
+
Accept: 'application/json'
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
case 1:
|
|
1000
|
+
response = _context5.v;
|
|
1001
|
+
if (response.ok) {
|
|
1002
|
+
_context5.n = 3;
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
_context5.n = 2;
|
|
1006
|
+
return response.text();
|
|
1007
|
+
case 2:
|
|
1008
|
+
text = _context5.v;
|
|
1009
|
+
throw new Error("Failed to batch reads from simulation: " + text);
|
|
1010
|
+
case 3:
|
|
1011
|
+
return _context5.a(2, response.json());
|
|
1012
|
+
}
|
|
1013
|
+
}, _callee5);
|
|
1014
|
+
}));
|
|
1015
|
+
return _simulationBatchReads.apply(this, arguments);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
599
1018
|
function setSender(tx, sender) {
|
|
600
1019
|
var _c32addressDecode = c32check.c32addressDecode(sender),
|
|
601
1020
|
addressVersion = _c32addressDecode[0],
|
|
@@ -623,128 +1042,25 @@ function setSender(tx, sender) {
|
|
|
623
1042
|
}
|
|
624
1043
|
return tx;
|
|
625
1044
|
}
|
|
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
1045
|
var SimulationBuilder = /*#__PURE__*/function () {
|
|
732
1046
|
function SimulationBuilder(options) {
|
|
733
|
-
var _options$network, _options$apiEndpoint, _options$stacksNodeAP;
|
|
1047
|
+
var _options$network, _options$apiEndpoint, _options$stacksNodeAP, _options$skipTracing;
|
|
734
1048
|
if (options === void 0) {
|
|
735
1049
|
options = {};
|
|
736
1050
|
}
|
|
737
1051
|
this.apiEndpoint = void 0;
|
|
738
1052
|
this.stacksNodeAPI = void 0;
|
|
739
1053
|
this.network = void 0;
|
|
1054
|
+
this.skipTracing = void 0;
|
|
740
1055
|
// biome-ignore lint/style/useNumberNamespace: ignore this
|
|
741
1056
|
this.block = NaN;
|
|
742
1057
|
this.sender = '';
|
|
743
1058
|
this.steps = [];
|
|
744
1059
|
this.network = (_options$network = options.network) != null ? _options$network : 'mainnet';
|
|
745
1060
|
var isTestnet = this.network === 'testnet';
|
|
746
|
-
this.apiEndpoint = (_options$apiEndpoint = options.apiEndpoint) != null ? _options$apiEndpoint : isTestnet ?
|
|
1061
|
+
this.apiEndpoint = (_options$apiEndpoint = options.apiEndpoint) != null ? _options$apiEndpoint : isTestnet ? STXER_API_TESTNET : STXER_API_MAINNET;
|
|
747
1062
|
this.stacksNodeAPI = (_options$stacksNodeAP = options.stacksNodeAPI) != null ? _options$stacksNodeAP : isTestnet ? 'https://api.testnet.hiro.so' : 'https://api.hiro.so';
|
|
1063
|
+
this.skipTracing = (_options$skipTracing = options.skipTracing) != null ? _options$skipTracing : false;
|
|
748
1064
|
}
|
|
749
1065
|
SimulationBuilder["new"] = function _new(options) {
|
|
750
1066
|
return new SimulationBuilder(options);
|
|
@@ -819,6 +1135,29 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
819
1135
|
});
|
|
820
1136
|
return this;
|
|
821
1137
|
};
|
|
1138
|
+
_proto.addSetContractCode = function addSetContractCode(params) {
|
|
1139
|
+
var _params$clarity_versi2;
|
|
1140
|
+
this.steps.push({
|
|
1141
|
+
type: 'SetContractCode',
|
|
1142
|
+
contract_id: params.contract_id,
|
|
1143
|
+
source_code: params.source_code,
|
|
1144
|
+
clarity_version: (_params$clarity_versi2 = params.clarity_version) != null ? _params$clarity_versi2 : transactions.ClarityVersion.Clarity4
|
|
1145
|
+
});
|
|
1146
|
+
return this;
|
|
1147
|
+
};
|
|
1148
|
+
_proto.addReads = function addReads(reads) {
|
|
1149
|
+
this.steps.push({
|
|
1150
|
+
type: 'Reads',
|
|
1151
|
+
reads: reads
|
|
1152
|
+
});
|
|
1153
|
+
return this;
|
|
1154
|
+
};
|
|
1155
|
+
_proto.addTenureExtend = function addTenureExtend() {
|
|
1156
|
+
this.steps.push({
|
|
1157
|
+
type: 'TenureExtend'
|
|
1158
|
+
});
|
|
1159
|
+
return this;
|
|
1160
|
+
};
|
|
822
1161
|
_proto.getBlockInfo = /*#__PURE__*/function () {
|
|
823
1162
|
var _getBlockInfo = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
824
1163
|
var _yield$getNodeInfo, stacks_tip_height, info;
|
|
@@ -864,22 +1203,22 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
864
1203
|
return getBlockInfo;
|
|
865
1204
|
}();
|
|
866
1205
|
_proto.run = /*#__PURE__*/function () {
|
|
867
|
-
var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1206
|
+
var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
868
1207
|
var _this = this;
|
|
869
|
-
var block,
|
|
870
|
-
return _regenerator().w(function (
|
|
871
|
-
while (1) switch (
|
|
1208
|
+
var block, v2Steps, nonce_by_address, nextNonce, network$1, _iterator, _step, step, _step$function_args, nonce, tx, _nonce, _tx, _nonce2, _tx2, _step$contract_id$spl, contractAddress, contractName, simulationId;
|
|
1209
|
+
return _regenerator().w(function (_context3) {
|
|
1210
|
+
while (1) switch (_context3.n) {
|
|
872
1211
|
case 0:
|
|
873
1212
|
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
|
-
|
|
1213
|
+
_context3.n = 1;
|
|
875
1214
|
return this.getBlockInfo();
|
|
876
1215
|
case 1:
|
|
877
|
-
block =
|
|
1216
|
+
block = _context3.v;
|
|
878
1217
|
console.log("Using block height " + block.block_height + " hash 0x" + block.block_hash + " to run simulation.");
|
|
879
|
-
|
|
1218
|
+
v2Steps = [];
|
|
880
1219
|
nonce_by_address = new Map();
|
|
881
1220
|
nextNonce = /*#__PURE__*/function () {
|
|
882
|
-
var
|
|
1221
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(sender) {
|
|
883
1222
|
var nonce, url, account;
|
|
884
1223
|
return _regenerator().w(function (_context2) {
|
|
885
1224
|
while (1) switch (_context2.n) {
|
|
@@ -904,8 +1243,8 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
904
1243
|
}
|
|
905
1244
|
}, _callee2);
|
|
906
1245
|
}));
|
|
907
|
-
return function nextNonce(
|
|
908
|
-
return
|
|
1246
|
+
return function nextNonce(_x) {
|
|
1247
|
+
return _ref.apply(this, arguments);
|
|
909
1248
|
};
|
|
910
1249
|
}();
|
|
911
1250
|
network$1 = this.network === 'mainnet' ? network.STACKS_MAINNET : network.STACKS_TESTNET;
|
|
@@ -916,164 +1255,152 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
916
1255
|
})
|
|
917
1256
|
});
|
|
918
1257
|
}
|
|
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
1258
|
_iterator = _createForOfIteratorHelperLoose(this.steps);
|
|
1059
1259
|
case 2:
|
|
1060
1260
|
if ((_step = _iterator()).done) {
|
|
1061
|
-
|
|
1261
|
+
_context3.n = 14;
|
|
1262
|
+
break;
|
|
1263
|
+
}
|
|
1264
|
+
step = _step.value;
|
|
1265
|
+
if (!('simulationId' in step)) {
|
|
1266
|
+
_context3.n = 3;
|
|
1062
1267
|
break;
|
|
1063
1268
|
}
|
|
1064
|
-
|
|
1269
|
+
throw new Error('inlineSimulation is not yet supported in V2 API. Please run simulations from scratch.');
|
|
1065
1270
|
case 3:
|
|
1066
|
-
|
|
1067
|
-
|
|
1271
|
+
if (!('sender' in step && 'function_name' in step)) {
|
|
1272
|
+
_context3.n = 6;
|
|
1273
|
+
break;
|
|
1274
|
+
}
|
|
1275
|
+
_context3.n = 4;
|
|
1276
|
+
return nextNonce(step.sender);
|
|
1068
1277
|
case 4:
|
|
1069
|
-
|
|
1070
|
-
|
|
1278
|
+
nonce = _context3.v;
|
|
1279
|
+
_context3.n = 5;
|
|
1280
|
+
return transactions.makeUnsignedContractCall({
|
|
1281
|
+
contractAddress: step.contract_id.split('.')[0],
|
|
1282
|
+
contractName: step.contract_id.split('.')[1],
|
|
1283
|
+
functionName: step.function_name,
|
|
1284
|
+
functionArgs: (_step$function_args = step.function_args) != null ? _step$function_args : [],
|
|
1285
|
+
nonce: nonce,
|
|
1286
|
+
network: network$1,
|
|
1287
|
+
publicKey: '',
|
|
1288
|
+
postConditionMode: transactions.PostConditionMode.Allow,
|
|
1289
|
+
fee: step.fee
|
|
1290
|
+
});
|
|
1071
1291
|
case 5:
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1292
|
+
tx = _context3.v;
|
|
1293
|
+
setSender(tx, step.sender);
|
|
1294
|
+
v2Steps.push({
|
|
1295
|
+
Transaction: bytesToHex(tx.serializeBytes())
|
|
1296
|
+
});
|
|
1297
|
+
_context3.n = 13;
|
|
1298
|
+
break;
|
|
1299
|
+
case 6:
|
|
1300
|
+
if (!('sender' in step && 'recipient' in step)) {
|
|
1301
|
+
_context3.n = 9;
|
|
1302
|
+
break;
|
|
1303
|
+
}
|
|
1304
|
+
_context3.n = 7;
|
|
1305
|
+
return nextNonce(step.sender);
|
|
1306
|
+
case 7:
|
|
1307
|
+
_nonce = _context3.v;
|
|
1308
|
+
_context3.n = 8;
|
|
1309
|
+
return transactions.makeUnsignedSTXTokenTransfer({
|
|
1310
|
+
recipient: step.recipient,
|
|
1311
|
+
amount: step.amount,
|
|
1312
|
+
nonce: _nonce,
|
|
1313
|
+
network: network$1,
|
|
1314
|
+
publicKey: '',
|
|
1315
|
+
fee: step.fee
|
|
1316
|
+
});
|
|
1317
|
+
case 8:
|
|
1318
|
+
_tx = _context3.v;
|
|
1319
|
+
setSender(_tx, step.sender);
|
|
1320
|
+
v2Steps.push({
|
|
1321
|
+
Transaction: bytesToHex(_tx.serializeBytes())
|
|
1322
|
+
});
|
|
1323
|
+
_context3.n = 13;
|
|
1324
|
+
break;
|
|
1325
|
+
case 9:
|
|
1326
|
+
if (!('deployer' in step)) {
|
|
1327
|
+
_context3.n = 12;
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
_context3.n = 10;
|
|
1331
|
+
return nextNonce(step.deployer);
|
|
1332
|
+
case 10:
|
|
1333
|
+
_nonce2 = _context3.v;
|
|
1334
|
+
_context3.n = 11;
|
|
1335
|
+
return transactions.makeUnsignedContractDeploy({
|
|
1336
|
+
contractName: step.contract_name,
|
|
1337
|
+
codeBody: step.source_code,
|
|
1338
|
+
nonce: _nonce2,
|
|
1339
|
+
network: network$1,
|
|
1340
|
+
publicKey: '',
|
|
1341
|
+
postConditionMode: transactions.PostConditionMode.Allow,
|
|
1342
|
+
fee: step.fee,
|
|
1343
|
+
clarityVersion: step.clarity_version
|
|
1344
|
+
});
|
|
1345
|
+
case 11:
|
|
1346
|
+
_tx2 = _context3.v;
|
|
1347
|
+
setSender(_tx2, step.deployer);
|
|
1348
|
+
v2Steps.push({
|
|
1349
|
+
Transaction: bytesToHex(_tx2.serializeBytes())
|
|
1350
|
+
});
|
|
1351
|
+
_context3.n = 13;
|
|
1352
|
+
break;
|
|
1353
|
+
case 12:
|
|
1354
|
+
if ('code' in step) {
|
|
1355
|
+
// Eval step - format: [sender, sponsor, contract_id, code]
|
|
1356
|
+
// For eval without a sender, we use empty string for sponsor
|
|
1357
|
+
_step$contract_id$spl = step.contract_id.split('.'), contractAddress = _step$contract_id$spl[0], contractName = _step$contract_id$spl[1];
|
|
1358
|
+
v2Steps.push({
|
|
1359
|
+
Eval: [this.sender || contractAddress, '', contractAddress + "." + contractName, step.code]
|
|
1360
|
+
});
|
|
1361
|
+
} else if (step.type === 'SetContractCode') {
|
|
1362
|
+
// SetContractCode - format: [contract_id, code, clarity_version]
|
|
1363
|
+
v2Steps.push({
|
|
1364
|
+
SetContractCode: [step.contract_id, step.source_code, clarityVersionToNumber(step.clarity_version)]
|
|
1365
|
+
});
|
|
1366
|
+
} else if (step.type === 'Reads') {
|
|
1367
|
+
// Reads - batch read operations
|
|
1368
|
+
v2Steps.push({
|
|
1369
|
+
Reads: step.reads
|
|
1370
|
+
});
|
|
1371
|
+
} else if (step.type === 'TenureExtend') {
|
|
1372
|
+
// TenureExtend - format: []
|
|
1373
|
+
v2Steps.push({
|
|
1374
|
+
TenureExtend: []
|
|
1375
|
+
});
|
|
1376
|
+
} else {
|
|
1377
|
+
console.log("Invalid simulation step: " + step);
|
|
1378
|
+
}
|
|
1379
|
+
case 13:
|
|
1380
|
+
_context3.n = 2;
|
|
1381
|
+
break;
|
|
1382
|
+
case 14:
|
|
1383
|
+
_context3.n = 15;
|
|
1384
|
+
return createSimulationSession({
|
|
1385
|
+
block_height: block.block_height,
|
|
1386
|
+
block_hash: block.block_hash,
|
|
1387
|
+
skip_tracing: this.skipTracing
|
|
1388
|
+
}, {
|
|
1389
|
+
stxerApi: this.apiEndpoint
|
|
1390
|
+
});
|
|
1391
|
+
case 15:
|
|
1392
|
+
simulationId = _context3.v;
|
|
1393
|
+
_context3.n = 16;
|
|
1394
|
+
return submitSimulationSteps(simulationId, {
|
|
1395
|
+
steps: v2Steps
|
|
1396
|
+
}, {
|
|
1397
|
+
stxerApi: this.apiEndpoint
|
|
1398
|
+
});
|
|
1399
|
+
case 16:
|
|
1400
|
+
console.log("Simulation will be available at: https://stxer.xyz/simulations/" + this.network + "/" + simulationId);
|
|
1401
|
+
return _context3.a(2, simulationId);
|
|
1075
1402
|
}
|
|
1076
|
-
},
|
|
1403
|
+
}, _callee3, this);
|
|
1077
1404
|
}));
|
|
1078
1405
|
function run() {
|
|
1079
1406
|
return _run.apply(this, arguments);
|
|
@@ -1085,12 +1412,103 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
1085
1412
|
};
|
|
1086
1413
|
return SimulationBuilder;
|
|
1087
1414
|
}();
|
|
1415
|
+
// Helper function to convert Uint8Array to hex string
|
|
1416
|
+
function bytesToHex(bytes) {
|
|
1417
|
+
return Array.from(bytes).map(function (b) {
|
|
1418
|
+
return b.toString(16).padStart(2, '0');
|
|
1419
|
+
}).join('');
|
|
1420
|
+
}
|
|
1421
|
+
// Helper function to convert ClarityVersion to number
|
|
1422
|
+
function clarityVersionToNumber(version) {
|
|
1423
|
+
switch (version) {
|
|
1424
|
+
case transactions.ClarityVersion.Clarity1:
|
|
1425
|
+
return 1;
|
|
1426
|
+
case transactions.ClarityVersion.Clarity2:
|
|
1427
|
+
return 2;
|
|
1428
|
+
case transactions.ClarityVersion.Clarity3:
|
|
1429
|
+
return 3;
|
|
1430
|
+
case transactions.ClarityVersion.Clarity4:
|
|
1431
|
+
return 4;
|
|
1432
|
+
default:
|
|
1433
|
+
return 4;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
/**
|
|
1438
|
+
* Fetch the current tip information from the sidecar.
|
|
1439
|
+
* @param options - Optional API endpoint configuration
|
|
1440
|
+
* @returns The current chain tip information
|
|
1441
|
+
*/
|
|
1442
|
+
function getTip(_x) {
|
|
1443
|
+
return _getTip.apply(this, arguments);
|
|
1444
|
+
}
|
|
1445
|
+
function _getTip() {
|
|
1446
|
+
_getTip = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
1447
|
+
var _options$stxerApi;
|
|
1448
|
+
var url, response, text;
|
|
1449
|
+
return _regenerator().w(function (_context) {
|
|
1450
|
+
while (1) switch (_context.n) {
|
|
1451
|
+
case 0:
|
|
1452
|
+
if (options === void 0) {
|
|
1453
|
+
options = {};
|
|
1454
|
+
}
|
|
1455
|
+
url = ((_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API$1) + "/sidecar/tip";
|
|
1456
|
+
_context.n = 1;
|
|
1457
|
+
return fetch(url, {
|
|
1458
|
+
method: 'GET',
|
|
1459
|
+
headers: {
|
|
1460
|
+
Accept: 'application/json'
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
case 1:
|
|
1464
|
+
response = _context.v;
|
|
1465
|
+
if (response.ok) {
|
|
1466
|
+
_context.n = 2;
|
|
1467
|
+
break;
|
|
1468
|
+
}
|
|
1469
|
+
throw new Error("Failed to fetch tip: " + response.status + " " + response.statusText);
|
|
1470
|
+
case 2:
|
|
1471
|
+
_context.n = 3;
|
|
1472
|
+
return response.text();
|
|
1473
|
+
case 3:
|
|
1474
|
+
text = _context.v;
|
|
1475
|
+
if (text.startsWith('{')) {
|
|
1476
|
+
_context.n = 4;
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
throw new Error("Invalid response from tip endpoint: " + text);
|
|
1480
|
+
case 4:
|
|
1481
|
+
return _context.a(2, JSON.parse(text));
|
|
1482
|
+
}
|
|
1483
|
+
}, _callee);
|
|
1484
|
+
}));
|
|
1485
|
+
return _getTip.apply(this, arguments);
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* Type definitions for stxer-api V2 endpoints
|
|
1490
|
+
* Hand-written types based on OpenAPI spec at https://api.stxer.xyz/openapi.json
|
|
1491
|
+
*/
|
|
1492
|
+
/** Convenience parser for `TransactionReceipt.events[i]`. */
|
|
1493
|
+
function parseSimulationEvent(raw) {
|
|
1494
|
+
return JSON.parse(raw);
|
|
1495
|
+
}
|
|
1088
1496
|
|
|
1497
|
+
exports.DEFAULT_STXER_API = DEFAULT_STXER_API$1;
|
|
1498
|
+
exports.STXER_API_MAINNET = STXER_API_MAINNET;
|
|
1499
|
+
exports.STXER_API_TESTNET = STXER_API_TESTNET;
|
|
1089
1500
|
exports.SimulationBuilder = SimulationBuilder;
|
|
1090
1501
|
exports.batchRead = batchRead;
|
|
1091
1502
|
exports.callReadonly = callReadonly;
|
|
1503
|
+
exports.createSimulationSession = createSimulationSession;
|
|
1504
|
+
exports.getContractAST = getContractAST;
|
|
1505
|
+
exports.getSimulationResult = getSimulationResult;
|
|
1506
|
+
exports.getTip = getTip;
|
|
1507
|
+
exports.instantSimulation = instantSimulation;
|
|
1508
|
+
exports.parseContract = parseContract;
|
|
1509
|
+
exports.parseSimulationEvent = parseSimulationEvent;
|
|
1092
1510
|
exports.readMap = readMap;
|
|
1093
1511
|
exports.readVariable = readVariable;
|
|
1094
|
-
exports.
|
|
1095
|
-
exports.
|
|
1512
|
+
exports.simulationBatchReads = simulationBatchReads;
|
|
1513
|
+
exports.submitSimulationSteps = submitSimulationSteps;
|
|
1096
1514
|
//# sourceMappingURL=stxer.cjs.development.js.map
|