stxer 0.4.3 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +322 -16
- package/dist/ast.d.ts +32 -0
- 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 +694 -285
- 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 -286
- package/dist/stxer.esm.js.map +1 -1
- package/dist/tip.d.ts +16 -0
- package/dist/types.d.ts +327 -0
- package/package.json +14 -12
- package/src/ast.ts +120 -0
- 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 +15 -1
- package/src/simulation-api.ts +273 -0
- package/src/simulation.ts +170 -138
- package/src/tip.ts +42 -0
- package/src/types.ts +392 -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/{BatchAPI.d.ts → batch-api.d.ts} +0 -0
- /package/dist/{BatchProcessor.d.ts → batch-processor.d.ts} +0 -0
- /package/src/{BatchAPI.ts → batch-api.ts} +0 -0
package/dist/stxer.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { serializeCV, deserializeCV, contractPrincipalCV, ClarityType,
|
|
1
|
+
import { serializeCV, deserializeCV, contractPrincipalCV, ClarityType, ClarityVersion, makeUnsignedContractDeploy, PostConditionMode, makeUnsignedSTXTokenTransfer, makeUnsignedContractCall, AddressHashMode } from '@stacks/transactions';
|
|
2
2
|
import { encodeAbi, decodeAbi, richFetch, getNodeInfo } from 'ts-clarity';
|
|
3
|
-
import {
|
|
3
|
+
import { STACKS_MAINNET, STACKS_TESTNET, AddressVersion } from '@stacks/network';
|
|
4
4
|
import { c32addressDecode } from 'c32check';
|
|
5
5
|
|
|
6
6
|
function _arrayLikeToArray(r, a) {
|
|
@@ -167,23 +167,6 @@ function _regeneratorDefine(e, r, n, t) {
|
|
|
167
167
|
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
168
168
|
}, _regeneratorDefine(e, r, n, t);
|
|
169
169
|
}
|
|
170
|
-
function _regeneratorValues(e) {
|
|
171
|
-
if (null != e) {
|
|
172
|
-
var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"],
|
|
173
|
-
r = 0;
|
|
174
|
-
if (t) return t.call(e);
|
|
175
|
-
if ("function" == typeof e.next) return e;
|
|
176
|
-
if (!isNaN(e.length)) return {
|
|
177
|
-
next: function () {
|
|
178
|
-
return e && r >= e.length && (e = void 0), {
|
|
179
|
-
value: e && e[r++],
|
|
180
|
-
done: !e
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
186
|
-
}
|
|
187
170
|
function _unsupportedIterableToArray(r, a) {
|
|
188
171
|
if (r) {
|
|
189
172
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -192,6 +175,123 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
192
175
|
}
|
|
193
176
|
}
|
|
194
177
|
|
|
178
|
+
/**
|
|
179
|
+
* API endpoint constants
|
|
180
|
+
*/
|
|
181
|
+
/** Default stxer API endpoint for mainnet */
|
|
182
|
+
var STXER_API_MAINNET = 'https://api.stxer.xyz';
|
|
183
|
+
/** stxer API endpoint for testnet */
|
|
184
|
+
var STXER_API_TESTNET = 'https://testnet-api.stxer.xyz';
|
|
185
|
+
/** Default stxer API endpoint (mainnet) */
|
|
186
|
+
var DEFAULT_STXER_API$1 = STXER_API_MAINNET;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Fetch the AST for an on-chain contract.
|
|
190
|
+
* @param options - Contract ID and optional API endpoint
|
|
191
|
+
* @returns The contract AST with metadata
|
|
192
|
+
*/
|
|
193
|
+
function getContractAST(_x) {
|
|
194
|
+
return _getContractAST.apply(this, arguments);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Parse contract source code into an AST.
|
|
198
|
+
* @param options - Source code, contract ID, and optional configuration
|
|
199
|
+
* @returns The parsed contract AST
|
|
200
|
+
*/
|
|
201
|
+
function _getContractAST() {
|
|
202
|
+
_getContractAST = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
203
|
+
var _options$stxerApi;
|
|
204
|
+
var url, response, text;
|
|
205
|
+
return _regenerator().w(function (_context) {
|
|
206
|
+
while (1) switch (_context.n) {
|
|
207
|
+
case 0:
|
|
208
|
+
url = ((_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API$1) + "/contracts/" + options.contractId;
|
|
209
|
+
_context.n = 1;
|
|
210
|
+
return fetch(url, {
|
|
211
|
+
method: 'GET',
|
|
212
|
+
headers: {
|
|
213
|
+
Accept: 'application/json'
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
case 1:
|
|
217
|
+
response = _context.v;
|
|
218
|
+
if (response.ok) {
|
|
219
|
+
_context.n = 2;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
throw new Error("Failed to fetch contract AST: " + response.status + " " + response.statusText);
|
|
223
|
+
case 2:
|
|
224
|
+
_context.n = 3;
|
|
225
|
+
return response.text();
|
|
226
|
+
case 3:
|
|
227
|
+
text = _context.v;
|
|
228
|
+
if (text.startsWith('{')) {
|
|
229
|
+
_context.n = 4;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
throw new Error("Invalid response from contracts endpoint: " + text);
|
|
233
|
+
case 4:
|
|
234
|
+
return _context.a(2, JSON.parse(text));
|
|
235
|
+
}
|
|
236
|
+
}, _callee);
|
|
237
|
+
}));
|
|
238
|
+
return _getContractAST.apply(this, arguments);
|
|
239
|
+
}
|
|
240
|
+
function parseContract(_x2) {
|
|
241
|
+
return _parseContract.apply(this, arguments);
|
|
242
|
+
}
|
|
243
|
+
function _parseContract() {
|
|
244
|
+
_parseContract = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
245
|
+
var _options$stxerApi2;
|
|
246
|
+
var url, payload, response, text;
|
|
247
|
+
return _regenerator().w(function (_context2) {
|
|
248
|
+
while (1) switch (_context2.n) {
|
|
249
|
+
case 0:
|
|
250
|
+
url = ((_options$stxerApi2 = options.stxerApi) != null ? _options$stxerApi2 : DEFAULT_STXER_API$1) + "/contracts:parse";
|
|
251
|
+
payload = {
|
|
252
|
+
contract_id: options.contractId,
|
|
253
|
+
source_code: options.sourceCode
|
|
254
|
+
};
|
|
255
|
+
if (options.clarityVersion !== undefined) {
|
|
256
|
+
payload.clarity_version = options.clarityVersion;
|
|
257
|
+
}
|
|
258
|
+
if (options.epoch !== undefined) {
|
|
259
|
+
payload.epoch = options.epoch;
|
|
260
|
+
}
|
|
261
|
+
_context2.n = 1;
|
|
262
|
+
return fetch(url, {
|
|
263
|
+
method: 'POST',
|
|
264
|
+
body: JSON.stringify(payload),
|
|
265
|
+
headers: {
|
|
266
|
+
'Content-Type': 'application/json',
|
|
267
|
+
Accept: 'application/json'
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
case 1:
|
|
271
|
+
response = _context2.v;
|
|
272
|
+
if (response.ok) {
|
|
273
|
+
_context2.n = 2;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
throw new Error("Failed to parse contract: " + response.status + " " + response.statusText);
|
|
277
|
+
case 2:
|
|
278
|
+
_context2.n = 3;
|
|
279
|
+
return response.text();
|
|
280
|
+
case 3:
|
|
281
|
+
text = _context2.v;
|
|
282
|
+
if (text.startsWith('{')) {
|
|
283
|
+
_context2.n = 4;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
throw new Error("Invalid response from contract parse endpoint: " + text);
|
|
287
|
+
case 4:
|
|
288
|
+
return _context2.a(2, JSON.parse(text));
|
|
289
|
+
}
|
|
290
|
+
}, _callee2);
|
|
291
|
+
}));
|
|
292
|
+
return _parseContract.apply(this, arguments);
|
|
293
|
+
}
|
|
294
|
+
|
|
195
295
|
var DEFAULT_STXER_API = 'https://api.stxer.xyz';
|
|
196
296
|
function convertResults(rs) {
|
|
197
297
|
var results = [];
|
|
@@ -592,6 +692,325 @@ function _readVariable() {
|
|
|
592
692
|
return _readVariable.apply(this, arguments);
|
|
593
693
|
}
|
|
594
694
|
|
|
695
|
+
/**
|
|
696
|
+
* Instantly simulate a transaction
|
|
697
|
+
*
|
|
698
|
+
* This is useful for apps/wallets to get the result of a transaction before sending it.
|
|
699
|
+
* Lightweight - no debug tracing information.
|
|
700
|
+
*
|
|
701
|
+
* @param request - Instant simulation request
|
|
702
|
+
* @param options - API options
|
|
703
|
+
* @returns Instant simulation response with receipt and optional reads
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```typescript
|
|
707
|
+
* import { instantSimulation } from 'stxer';
|
|
708
|
+
*
|
|
709
|
+
* const result = await instantSimulation({
|
|
710
|
+
* transaction: '0x...',
|
|
711
|
+
* block_height: 130818,
|
|
712
|
+
* block_hash: '0x...',
|
|
713
|
+
* reads: [
|
|
714
|
+
* { DataVar: ['SP...contract', 'my-var'] },
|
|
715
|
+
* { StxBalance: 'SP...' }
|
|
716
|
+
* ]
|
|
717
|
+
* });
|
|
718
|
+
* console.log(result.receipt.result);
|
|
719
|
+
* ```
|
|
720
|
+
*/
|
|
721
|
+
function instantSimulation(_x, _x2) {
|
|
722
|
+
return _instantSimulation.apply(this, arguments);
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Create a new simulation session
|
|
726
|
+
*
|
|
727
|
+
* A session allows you to run multiple steps in a forked chain state.
|
|
728
|
+
*
|
|
729
|
+
* @param options - Create session options
|
|
730
|
+
* @param apiOptions - API options
|
|
731
|
+
* @returns Session ID
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* ```typescript
|
|
735
|
+
* import { createSimulationSession } from 'stxer';
|
|
736
|
+
*
|
|
737
|
+
* const sessionId = await createSimulationSession({
|
|
738
|
+
* block_height: 130818,
|
|
739
|
+
* skip_tracing: false
|
|
740
|
+
* });
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
function _instantSimulation() {
|
|
744
|
+
_instantSimulation = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(request, options) {
|
|
745
|
+
var _options$stxerApi;
|
|
746
|
+
var apiEndpoint, response, text;
|
|
747
|
+
return _regenerator().w(function (_context) {
|
|
748
|
+
while (1) switch (_context.n) {
|
|
749
|
+
case 0:
|
|
750
|
+
if (options === void 0) {
|
|
751
|
+
options = {};
|
|
752
|
+
}
|
|
753
|
+
apiEndpoint = (_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API$1;
|
|
754
|
+
_context.n = 1;
|
|
755
|
+
return fetch(apiEndpoint + "/devtools/v2/simulation:instant", {
|
|
756
|
+
method: 'POST',
|
|
757
|
+
body: JSON.stringify(request),
|
|
758
|
+
headers: {
|
|
759
|
+
'Content-Type': 'application/json',
|
|
760
|
+
Accept: 'application/json'
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
case 1:
|
|
764
|
+
response = _context.v;
|
|
765
|
+
if (response.ok) {
|
|
766
|
+
_context.n = 3;
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
_context.n = 2;
|
|
770
|
+
return response.text();
|
|
771
|
+
case 2:
|
|
772
|
+
text = _context.v;
|
|
773
|
+
throw new Error("Instant simulation failed: " + text);
|
|
774
|
+
case 3:
|
|
775
|
+
return _context.a(2, response.json());
|
|
776
|
+
}
|
|
777
|
+
}, _callee);
|
|
778
|
+
}));
|
|
779
|
+
return _instantSimulation.apply(this, arguments);
|
|
780
|
+
}
|
|
781
|
+
function createSimulationSession(_x3, _x4) {
|
|
782
|
+
return _createSimulationSession.apply(this, arguments);
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Submit steps to a simulation session
|
|
786
|
+
*
|
|
787
|
+
* Steps are executed sequentially in the session's forked chain state.
|
|
788
|
+
*
|
|
789
|
+
* @param sessionId - Simulation session ID
|
|
790
|
+
* @param request - Steps to submit
|
|
791
|
+
* @param options - API options
|
|
792
|
+
* @returns Array of step results
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```typescript
|
|
796
|
+
* import { submitSimulationSteps } from 'stxer';
|
|
797
|
+
*
|
|
798
|
+
* const results = await submitSimulationSteps(sessionId, {
|
|
799
|
+
* steps: [
|
|
800
|
+
* { Transaction: '0x...' },
|
|
801
|
+
* { Eval: ['SP...', '', 'SP...contract', '(var-get my-var)'] },
|
|
802
|
+
* { Reads: [{ DataVar: ['SP...contract', 'my-var'] }] }
|
|
803
|
+
* ]
|
|
804
|
+
* });
|
|
805
|
+
* ```
|
|
806
|
+
*/
|
|
807
|
+
function _createSimulationSession() {
|
|
808
|
+
_createSimulationSession = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options, apiOptions) {
|
|
809
|
+
var _apiOptions$stxerApi;
|
|
810
|
+
var apiEndpoint, response, text, result;
|
|
811
|
+
return _regenerator().w(function (_context2) {
|
|
812
|
+
while (1) switch (_context2.n) {
|
|
813
|
+
case 0:
|
|
814
|
+
if (options === void 0) {
|
|
815
|
+
options = {};
|
|
816
|
+
}
|
|
817
|
+
if (apiOptions === void 0) {
|
|
818
|
+
apiOptions = {};
|
|
819
|
+
}
|
|
820
|
+
apiEndpoint = (_apiOptions$stxerApi = apiOptions.stxerApi) != null ? _apiOptions$stxerApi : DEFAULT_STXER_API$1;
|
|
821
|
+
_context2.n = 1;
|
|
822
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations", {
|
|
823
|
+
method: 'POST',
|
|
824
|
+
body: JSON.stringify(options),
|
|
825
|
+
headers: {
|
|
826
|
+
'Content-Type': 'application/json',
|
|
827
|
+
Accept: 'application/json'
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
case 1:
|
|
831
|
+
response = _context2.v;
|
|
832
|
+
if (response.ok) {
|
|
833
|
+
_context2.n = 3;
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
_context2.n = 2;
|
|
837
|
+
return response.text();
|
|
838
|
+
case 2:
|
|
839
|
+
text = _context2.v;
|
|
840
|
+
throw new Error("Failed to create simulation session: " + text);
|
|
841
|
+
case 3:
|
|
842
|
+
_context2.n = 4;
|
|
843
|
+
return response.json();
|
|
844
|
+
case 4:
|
|
845
|
+
result = _context2.v;
|
|
846
|
+
return _context2.a(2, result.id);
|
|
847
|
+
}
|
|
848
|
+
}, _callee2);
|
|
849
|
+
}));
|
|
850
|
+
return _createSimulationSession.apply(this, arguments);
|
|
851
|
+
}
|
|
852
|
+
function submitSimulationSteps(_x5, _x6, _x7) {
|
|
853
|
+
return _submitSimulationSteps.apply(this, arguments);
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Get simulation session results
|
|
857
|
+
*
|
|
858
|
+
* Returns the full simulation result including metadata and all step results.
|
|
859
|
+
*
|
|
860
|
+
* @param sessionId - Simulation session ID
|
|
861
|
+
* @param options - API options
|
|
862
|
+
* @returns Complete simulation result
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```typescript
|
|
866
|
+
* import { getSimulationResult } from 'stxer';
|
|
867
|
+
*
|
|
868
|
+
* const result = await getSimulationResult(sessionId);
|
|
869
|
+
* console.log(result.metadata);
|
|
870
|
+
* console.log(result.steps);
|
|
871
|
+
* ```
|
|
872
|
+
*/
|
|
873
|
+
function _submitSimulationSteps() {
|
|
874
|
+
_submitSimulationSteps = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(sessionId, request, options) {
|
|
875
|
+
var _options$stxerApi2;
|
|
876
|
+
var apiEndpoint, response, text;
|
|
877
|
+
return _regenerator().w(function (_context3) {
|
|
878
|
+
while (1) switch (_context3.n) {
|
|
879
|
+
case 0:
|
|
880
|
+
if (options === void 0) {
|
|
881
|
+
options = {};
|
|
882
|
+
}
|
|
883
|
+
apiEndpoint = (_options$stxerApi2 = options.stxerApi) != null ? _options$stxerApi2 : DEFAULT_STXER_API$1;
|
|
884
|
+
_context3.n = 1;
|
|
885
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
|
|
886
|
+
method: 'POST',
|
|
887
|
+
body: JSON.stringify(request),
|
|
888
|
+
headers: {
|
|
889
|
+
'Content-Type': 'application/json',
|
|
890
|
+
Accept: 'application/json'
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
case 1:
|
|
894
|
+
response = _context3.v;
|
|
895
|
+
if (response.ok) {
|
|
896
|
+
_context3.n = 3;
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
_context3.n = 2;
|
|
900
|
+
return response.text();
|
|
901
|
+
case 2:
|
|
902
|
+
text = _context3.v;
|
|
903
|
+
throw new Error("Failed to submit simulation steps: " + text);
|
|
904
|
+
case 3:
|
|
905
|
+
return _context3.a(2, response.json());
|
|
906
|
+
}
|
|
907
|
+
}, _callee3);
|
|
908
|
+
}));
|
|
909
|
+
return _submitSimulationSteps.apply(this, arguments);
|
|
910
|
+
}
|
|
911
|
+
function getSimulationResult(_x8, _x9) {
|
|
912
|
+
return _getSimulationResult.apply(this, arguments);
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Batch reads from a simulation session
|
|
916
|
+
*
|
|
917
|
+
* Similar to sidecar batch reads, but reads from the simulation's forked state.
|
|
918
|
+
*
|
|
919
|
+
* @param sessionId - Simulation session ID
|
|
920
|
+
* @param request - Batch reads request
|
|
921
|
+
* @param options - API options
|
|
922
|
+
* @returns Batch read results
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
* ```typescript
|
|
926
|
+
* import { simulationBatchReads } from 'stxer';
|
|
927
|
+
*
|
|
928
|
+
* const results = await simulationBatchReads(sessionId, {
|
|
929
|
+
* vars: [['SP...contract', 'my-var']],
|
|
930
|
+
* maps: [['SP...contract', 'my-map', '0x...']],
|
|
931
|
+
* stx: ['SP...']
|
|
932
|
+
* });
|
|
933
|
+
* console.log(results.vars);
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
function _getSimulationResult() {
|
|
937
|
+
_getSimulationResult = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(sessionId, options) {
|
|
938
|
+
var _options$stxerApi3;
|
|
939
|
+
var apiEndpoint, response, text;
|
|
940
|
+
return _regenerator().w(function (_context4) {
|
|
941
|
+
while (1) switch (_context4.n) {
|
|
942
|
+
case 0:
|
|
943
|
+
if (options === void 0) {
|
|
944
|
+
options = {};
|
|
945
|
+
}
|
|
946
|
+
apiEndpoint = (_options$stxerApi3 = options.stxerApi) != null ? _options$stxerApi3 : DEFAULT_STXER_API$1;
|
|
947
|
+
_context4.n = 1;
|
|
948
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
|
|
949
|
+
method: 'GET',
|
|
950
|
+
headers: {
|
|
951
|
+
Accept: 'application/json'
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
case 1:
|
|
955
|
+
response = _context4.v;
|
|
956
|
+
if (response.ok) {
|
|
957
|
+
_context4.n = 3;
|
|
958
|
+
break;
|
|
959
|
+
}
|
|
960
|
+
_context4.n = 2;
|
|
961
|
+
return response.text();
|
|
962
|
+
case 2:
|
|
963
|
+
text = _context4.v;
|
|
964
|
+
throw new Error("Failed to get simulation result: " + text);
|
|
965
|
+
case 3:
|
|
966
|
+
return _context4.a(2, response.json());
|
|
967
|
+
}
|
|
968
|
+
}, _callee4);
|
|
969
|
+
}));
|
|
970
|
+
return _getSimulationResult.apply(this, arguments);
|
|
971
|
+
}
|
|
972
|
+
function simulationBatchReads(_x0, _x1, _x10) {
|
|
973
|
+
return _simulationBatchReads.apply(this, arguments);
|
|
974
|
+
}
|
|
975
|
+
function _simulationBatchReads() {
|
|
976
|
+
_simulationBatchReads = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(sessionId, request, options) {
|
|
977
|
+
var _options$stxerApi4;
|
|
978
|
+
var apiEndpoint, response, text;
|
|
979
|
+
return _regenerator().w(function (_context5) {
|
|
980
|
+
while (1) switch (_context5.n) {
|
|
981
|
+
case 0:
|
|
982
|
+
if (options === void 0) {
|
|
983
|
+
options = {};
|
|
984
|
+
}
|
|
985
|
+
apiEndpoint = (_options$stxerApi4 = options.stxerApi) != null ? _options$stxerApi4 : DEFAULT_STXER_API$1;
|
|
986
|
+
_context5.n = 1;
|
|
987
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId + "/reads", {
|
|
988
|
+
method: 'POST',
|
|
989
|
+
body: JSON.stringify(request),
|
|
990
|
+
headers: {
|
|
991
|
+
'Content-Type': 'application/json',
|
|
992
|
+
Accept: 'application/json'
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
case 1:
|
|
996
|
+
response = _context5.v;
|
|
997
|
+
if (response.ok) {
|
|
998
|
+
_context5.n = 3;
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
_context5.n = 2;
|
|
1002
|
+
return response.text();
|
|
1003
|
+
case 2:
|
|
1004
|
+
text = _context5.v;
|
|
1005
|
+
throw new Error("Failed to batch reads from simulation: " + text);
|
|
1006
|
+
case 3:
|
|
1007
|
+
return _context5.a(2, response.json());
|
|
1008
|
+
}
|
|
1009
|
+
}, _callee5);
|
|
1010
|
+
}));
|
|
1011
|
+
return _simulationBatchReads.apply(this, arguments);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
595
1014
|
function setSender(tx, sender) {
|
|
596
1015
|
var _c32addressDecode = c32addressDecode(sender),
|
|
597
1016
|
addressVersion = _c32addressDecode[0],
|
|
@@ -619,128 +1038,25 @@ function setSender(tx, sender) {
|
|
|
619
1038
|
}
|
|
620
1039
|
return tx;
|
|
621
1040
|
}
|
|
622
|
-
function runTx(tx) {
|
|
623
|
-
// type 0: run transaction
|
|
624
|
-
return tupleCV({
|
|
625
|
-
type: uintCV(0),
|
|
626
|
-
data: bufferCV(tx.serializeBytes())
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
function runEval(_ref) {
|
|
630
|
-
var contract_id = _ref.contract_id,
|
|
631
|
-
code = _ref.code;
|
|
632
|
-
var _contract_id$split = contract_id.split('.'),
|
|
633
|
-
contract_address = _contract_id$split[0],
|
|
634
|
-
contract_name = _contract_id$split[1];
|
|
635
|
-
// type 1: eval arbitrary code inside a contract
|
|
636
|
-
return tupleCV({
|
|
637
|
-
type: uintCV(1),
|
|
638
|
-
data: bufferCV(serializeCVBytes(tupleCV({
|
|
639
|
-
contract: contractPrincipalCV(contract_address, contract_name),
|
|
640
|
-
code: stringAsciiCV(code)
|
|
641
|
-
})))
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
function runSimulation(_x, _x2, _x3, _x4) {
|
|
645
|
-
return _runSimulation.apply(this, arguments);
|
|
646
|
-
}
|
|
647
|
-
function _runSimulation() {
|
|
648
|
-
_runSimulation = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(apiEndpoint, block_hash, block_height, txs) {
|
|
649
|
-
var header, heightBytes, view, hashHex, matches, hashBytes, txBytes, totalLength, body, offset, _iterator3, _step4, tx, rs;
|
|
650
|
-
return _regenerator().w(function (_context7) {
|
|
651
|
-
while (1) switch (_context7.n) {
|
|
652
|
-
case 0:
|
|
653
|
-
// Convert 'sim-v1' to Uint8Array
|
|
654
|
-
header = new TextEncoder().encode('sim-v1'); // Create 8 bytes for block height
|
|
655
|
-
heightBytes = new Uint8Array(8); // Convert block height to bytes
|
|
656
|
-
view = new DataView(heightBytes.buffer);
|
|
657
|
-
view.setBigUint64(0, BigInt(block_height), false); // false for big-endian
|
|
658
|
-
// Convert block hash to bytes
|
|
659
|
-
hashHex = block_hash.startsWith('0x') ? block_hash.substring(2) : block_hash; // Replace non-null assertion with null check
|
|
660
|
-
matches = hashHex.match(/.{1,2}/g);
|
|
661
|
-
if (matches) {
|
|
662
|
-
_context7.n = 1;
|
|
663
|
-
break;
|
|
664
|
-
}
|
|
665
|
-
throw new Error('Invalid block hash format');
|
|
666
|
-
case 1:
|
|
667
|
-
hashBytes = new Uint8Array(matches.map(function (_byte) {
|
|
668
|
-
return Number.parseInt(_byte, 16);
|
|
669
|
-
})); // Convert transactions to bytes
|
|
670
|
-
txBytes = txs.map(function (t) {
|
|
671
|
-
return 'contract_id' in t && 'code' in t ? runEval(t) : runTx(t);
|
|
672
|
-
}).map(function (t) {
|
|
673
|
-
return serializeCVBytes(t);
|
|
674
|
-
}); // Combine all byte arrays
|
|
675
|
-
totalLength = header.length + heightBytes.length + hashBytes.length + txBytes.reduce(function (acc, curr) {
|
|
676
|
-
return acc + curr.length;
|
|
677
|
-
}, 0);
|
|
678
|
-
body = new Uint8Array(totalLength);
|
|
679
|
-
offset = 0;
|
|
680
|
-
body.set(header, offset);
|
|
681
|
-
offset += header.length;
|
|
682
|
-
body.set(heightBytes, offset);
|
|
683
|
-
offset += heightBytes.length;
|
|
684
|
-
body.set(hashBytes, offset);
|
|
685
|
-
offset += hashBytes.length;
|
|
686
|
-
for (_iterator3 = _createForOfIteratorHelperLoose(txBytes); !(_step4 = _iterator3()).done;) {
|
|
687
|
-
tx = _step4.value;
|
|
688
|
-
body.set(tx, offset);
|
|
689
|
-
offset += tx.length;
|
|
690
|
-
}
|
|
691
|
-
_context7.n = 2;
|
|
692
|
-
return fetch(apiEndpoint, {
|
|
693
|
-
method: 'POST',
|
|
694
|
-
body: body
|
|
695
|
-
}).then(/*#__PURE__*/function () {
|
|
696
|
-
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(rs) {
|
|
697
|
-
var response;
|
|
698
|
-
return _regenerator().w(function (_context6) {
|
|
699
|
-
while (1) switch (_context6.n) {
|
|
700
|
-
case 0:
|
|
701
|
-
_context6.n = 1;
|
|
702
|
-
return rs.text();
|
|
703
|
-
case 1:
|
|
704
|
-
response = _context6.v;
|
|
705
|
-
if (response.startsWith('{')) {
|
|
706
|
-
_context6.n = 2;
|
|
707
|
-
break;
|
|
708
|
-
}
|
|
709
|
-
throw new Error("failed to submit simulation: " + response);
|
|
710
|
-
case 2:
|
|
711
|
-
return _context6.a(2, JSON.parse(response));
|
|
712
|
-
}
|
|
713
|
-
}, _callee5);
|
|
714
|
-
}));
|
|
715
|
-
return function (_x7) {
|
|
716
|
-
return _ref4.apply(this, arguments);
|
|
717
|
-
};
|
|
718
|
-
}());
|
|
719
|
-
case 2:
|
|
720
|
-
rs = _context7.v;
|
|
721
|
-
return _context7.a(2, rs.id);
|
|
722
|
-
}
|
|
723
|
-
}, _callee6);
|
|
724
|
-
}));
|
|
725
|
-
return _runSimulation.apply(this, arguments);
|
|
726
|
-
}
|
|
727
1041
|
var SimulationBuilder = /*#__PURE__*/function () {
|
|
728
1042
|
function SimulationBuilder(options) {
|
|
729
|
-
var _options$network, _options$apiEndpoint, _options$stacksNodeAP;
|
|
1043
|
+
var _options$network, _options$apiEndpoint, _options$stacksNodeAP, _options$skipTracing;
|
|
730
1044
|
if (options === void 0) {
|
|
731
1045
|
options = {};
|
|
732
1046
|
}
|
|
733
1047
|
this.apiEndpoint = void 0;
|
|
734
1048
|
this.stacksNodeAPI = void 0;
|
|
735
1049
|
this.network = void 0;
|
|
1050
|
+
this.skipTracing = void 0;
|
|
736
1051
|
// biome-ignore lint/style/useNumberNamespace: ignore this
|
|
737
1052
|
this.block = NaN;
|
|
738
1053
|
this.sender = '';
|
|
739
1054
|
this.steps = [];
|
|
740
1055
|
this.network = (_options$network = options.network) != null ? _options$network : 'mainnet';
|
|
741
1056
|
var isTestnet = this.network === 'testnet';
|
|
742
|
-
this.apiEndpoint = (_options$apiEndpoint = options.apiEndpoint) != null ? _options$apiEndpoint : isTestnet ?
|
|
1057
|
+
this.apiEndpoint = (_options$apiEndpoint = options.apiEndpoint) != null ? _options$apiEndpoint : isTestnet ? STXER_API_TESTNET : STXER_API_MAINNET;
|
|
743
1058
|
this.stacksNodeAPI = (_options$stacksNodeAP = options.stacksNodeAPI) != null ? _options$stacksNodeAP : isTestnet ? 'https://api.testnet.hiro.so' : 'https://api.hiro.so';
|
|
1059
|
+
this.skipTracing = (_options$skipTracing = options.skipTracing) != null ? _options$skipTracing : false;
|
|
744
1060
|
}
|
|
745
1061
|
SimulationBuilder["new"] = function _new(options) {
|
|
746
1062
|
return new SimulationBuilder(options);
|
|
@@ -790,7 +1106,7 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
790
1106
|
this.steps.push(_extends({}, params, {
|
|
791
1107
|
deployer: (_params$deployer = params.deployer) != null ? _params$deployer : this.sender,
|
|
792
1108
|
fee: (_params$fee3 = params.fee) != null ? _params$fee3 : 0,
|
|
793
|
-
clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : ClarityVersion.
|
|
1109
|
+
clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : ClarityVersion.Clarity4
|
|
794
1110
|
}));
|
|
795
1111
|
return this;
|
|
796
1112
|
};
|
|
@@ -815,6 +1131,29 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
815
1131
|
});
|
|
816
1132
|
return this;
|
|
817
1133
|
};
|
|
1134
|
+
_proto.addSetContractCode = function addSetContractCode(params) {
|
|
1135
|
+
var _params$clarity_versi2;
|
|
1136
|
+
this.steps.push({
|
|
1137
|
+
type: 'SetContractCode',
|
|
1138
|
+
contract_id: params.contract_id,
|
|
1139
|
+
source_code: params.source_code,
|
|
1140
|
+
clarity_version: (_params$clarity_versi2 = params.clarity_version) != null ? _params$clarity_versi2 : ClarityVersion.Clarity4
|
|
1141
|
+
});
|
|
1142
|
+
return this;
|
|
1143
|
+
};
|
|
1144
|
+
_proto.addReads = function addReads(reads) {
|
|
1145
|
+
this.steps.push({
|
|
1146
|
+
type: 'Reads',
|
|
1147
|
+
reads: reads
|
|
1148
|
+
});
|
|
1149
|
+
return this;
|
|
1150
|
+
};
|
|
1151
|
+
_proto.addTenureExtend = function addTenureExtend() {
|
|
1152
|
+
this.steps.push({
|
|
1153
|
+
type: 'TenureExtend'
|
|
1154
|
+
});
|
|
1155
|
+
return this;
|
|
1156
|
+
};
|
|
818
1157
|
_proto.getBlockInfo = /*#__PURE__*/function () {
|
|
819
1158
|
var _getBlockInfo = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
820
1159
|
var _yield$getNodeInfo, stacks_tip_height, info;
|
|
@@ -860,22 +1199,22 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
860
1199
|
return getBlockInfo;
|
|
861
1200
|
}();
|
|
862
1201
|
_proto.run = /*#__PURE__*/function () {
|
|
863
|
-
var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1202
|
+
var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
864
1203
|
var _this = this;
|
|
865
|
-
var block,
|
|
866
|
-
return _regenerator().w(function (
|
|
867
|
-
while (1) switch (
|
|
1204
|
+
var block, v2Steps, nonce_by_address, nextNonce, network, _iterator, _step, step, _step$function_args, nonce, tx, _nonce, _tx, _nonce2, _tx2, _step$contract_id$spl, contractAddress, contractName, simulationId;
|
|
1205
|
+
return _regenerator().w(function (_context3) {
|
|
1206
|
+
while (1) switch (_context3.n) {
|
|
868
1207
|
case 0:
|
|
869
1208
|
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--------------------------------");
|
|
870
|
-
|
|
1209
|
+
_context3.n = 1;
|
|
871
1210
|
return this.getBlockInfo();
|
|
872
1211
|
case 1:
|
|
873
|
-
block =
|
|
1212
|
+
block = _context3.v;
|
|
874
1213
|
console.log("Using block height " + block.block_height + " hash 0x" + block.block_hash + " to run simulation.");
|
|
875
|
-
|
|
1214
|
+
v2Steps = [];
|
|
876
1215
|
nonce_by_address = new Map();
|
|
877
1216
|
nextNonce = /*#__PURE__*/function () {
|
|
878
|
-
var
|
|
1217
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(sender) {
|
|
879
1218
|
var nonce, url, account;
|
|
880
1219
|
return _regenerator().w(function (_context2) {
|
|
881
1220
|
while (1) switch (_context2.n) {
|
|
@@ -900,8 +1239,8 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
900
1239
|
}
|
|
901
1240
|
}, _callee2);
|
|
902
1241
|
}));
|
|
903
|
-
return function nextNonce(
|
|
904
|
-
return
|
|
1242
|
+
return function nextNonce(_x) {
|
|
1243
|
+
return _ref.apply(this, arguments);
|
|
905
1244
|
};
|
|
906
1245
|
}();
|
|
907
1246
|
network = this.network === 'mainnet' ? STACKS_MAINNET : STACKS_TESTNET;
|
|
@@ -912,163 +1251,152 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
912
1251
|
})
|
|
913
1252
|
});
|
|
914
1253
|
}
|
|
915
|
-
_loop = /*#__PURE__*/_regenerator().m(function _loop() {
|
|
916
|
-
var step, previousSimulation, _iterator2, _step2, _step3, _step$function_args, nonce, _step$contract_id$spl, contractAddress, contractName, tx, _nonce, _tx, _nonce2, _tx2;
|
|
917
|
-
return _regenerator().w(function (_context4) {
|
|
918
|
-
while (1) switch (_context4.n) {
|
|
919
|
-
case 0:
|
|
920
|
-
step = _step.value;
|
|
921
|
-
if (!('simulationId' in step)) {
|
|
922
|
-
_context4.n = 2;
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
925
|
-
_context4.n = 1;
|
|
926
|
-
return fetch("https://api.stxer.xyz/simulations/" + step.simulationId + "/request").then(/*#__PURE__*/function () {
|
|
927
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(rs) {
|
|
928
|
-
var body;
|
|
929
|
-
return _regenerator().w(function (_context3) {
|
|
930
|
-
while (1) switch (_context3.n) {
|
|
931
|
-
case 0:
|
|
932
|
-
_context3.n = 1;
|
|
933
|
-
return rs.text();
|
|
934
|
-
case 1:
|
|
935
|
-
body = _context3.v;
|
|
936
|
-
if (body.startsWith('{')) {
|
|
937
|
-
_context3.n = 2;
|
|
938
|
-
break;
|
|
939
|
-
}
|
|
940
|
-
throw new Error("failed to get simulation " + step.simulationId + ": " + body);
|
|
941
|
-
case 2:
|
|
942
|
-
return _context3.a(2, JSON.parse(body));
|
|
943
|
-
}
|
|
944
|
-
}, _callee3);
|
|
945
|
-
}));
|
|
946
|
-
return function (_x6) {
|
|
947
|
-
return _ref3.apply(this, arguments);
|
|
948
|
-
};
|
|
949
|
-
}());
|
|
950
|
-
case 1:
|
|
951
|
-
previousSimulation = _context4.v;
|
|
952
|
-
for (_iterator2 = _createForOfIteratorHelperLoose(previousSimulation.steps); !(_step2 = _iterator2()).done;) {
|
|
953
|
-
_step3 = _step2.value;
|
|
954
|
-
if ('tx' in _step3) {
|
|
955
|
-
txs.push(deserializeTransaction(_step3.tx));
|
|
956
|
-
} else if ('code' in _step3 && 'contract' in _step3) {
|
|
957
|
-
txs.push({
|
|
958
|
-
contract_id: _step3.contract,
|
|
959
|
-
code: _step3.code
|
|
960
|
-
});
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
_context4.n = 12;
|
|
964
|
-
break;
|
|
965
|
-
case 2:
|
|
966
|
-
if (!('sender' in step && 'function_name' in step)) {
|
|
967
|
-
_context4.n = 5;
|
|
968
|
-
break;
|
|
969
|
-
}
|
|
970
|
-
_context4.n = 3;
|
|
971
|
-
return nextNonce(step.sender);
|
|
972
|
-
case 3:
|
|
973
|
-
nonce = _context4.v;
|
|
974
|
-
_step$contract_id$spl = step.contract_id.split('.'), contractAddress = _step$contract_id$spl[0], contractName = _step$contract_id$spl[1];
|
|
975
|
-
_context4.n = 4;
|
|
976
|
-
return makeUnsignedContractCall({
|
|
977
|
-
contractAddress: contractAddress,
|
|
978
|
-
contractName: contractName,
|
|
979
|
-
functionName: step.function_name,
|
|
980
|
-
functionArgs: (_step$function_args = step.function_args) != null ? _step$function_args : [],
|
|
981
|
-
nonce: nonce,
|
|
982
|
-
network: network,
|
|
983
|
-
publicKey: '',
|
|
984
|
-
postConditionMode: PostConditionMode.Allow,
|
|
985
|
-
fee: step.fee
|
|
986
|
-
});
|
|
987
|
-
case 4:
|
|
988
|
-
tx = _context4.v;
|
|
989
|
-
setSender(tx, step.sender);
|
|
990
|
-
txs.push(tx);
|
|
991
|
-
_context4.n = 12;
|
|
992
|
-
break;
|
|
993
|
-
case 5:
|
|
994
|
-
if (!('sender' in step && 'recipient' in step)) {
|
|
995
|
-
_context4.n = 8;
|
|
996
|
-
break;
|
|
997
|
-
}
|
|
998
|
-
_context4.n = 6;
|
|
999
|
-
return nextNonce(step.sender);
|
|
1000
|
-
case 6:
|
|
1001
|
-
_nonce = _context4.v;
|
|
1002
|
-
_context4.n = 7;
|
|
1003
|
-
return makeUnsignedSTXTokenTransfer({
|
|
1004
|
-
recipient: step.recipient,
|
|
1005
|
-
amount: step.amount,
|
|
1006
|
-
nonce: _nonce,
|
|
1007
|
-
network: network,
|
|
1008
|
-
publicKey: '',
|
|
1009
|
-
fee: step.fee
|
|
1010
|
-
});
|
|
1011
|
-
case 7:
|
|
1012
|
-
_tx = _context4.v;
|
|
1013
|
-
setSender(_tx, step.sender);
|
|
1014
|
-
txs.push(_tx);
|
|
1015
|
-
_context4.n = 12;
|
|
1016
|
-
break;
|
|
1017
|
-
case 8:
|
|
1018
|
-
if (!('deployer' in step)) {
|
|
1019
|
-
_context4.n = 11;
|
|
1020
|
-
break;
|
|
1021
|
-
}
|
|
1022
|
-
_context4.n = 9;
|
|
1023
|
-
return nextNonce(step.deployer);
|
|
1024
|
-
case 9:
|
|
1025
|
-
_nonce2 = _context4.v;
|
|
1026
|
-
_context4.n = 10;
|
|
1027
|
-
return makeUnsignedContractDeploy({
|
|
1028
|
-
contractName: step.contract_name,
|
|
1029
|
-
codeBody: step.source_code,
|
|
1030
|
-
nonce: _nonce2,
|
|
1031
|
-
network: network,
|
|
1032
|
-
publicKey: '',
|
|
1033
|
-
postConditionMode: PostConditionMode.Allow,
|
|
1034
|
-
fee: step.fee
|
|
1035
|
-
});
|
|
1036
|
-
case 10:
|
|
1037
|
-
_tx2 = _context4.v;
|
|
1038
|
-
setSender(_tx2, step.deployer);
|
|
1039
|
-
txs.push(_tx2);
|
|
1040
|
-
_context4.n = 12;
|
|
1041
|
-
break;
|
|
1042
|
-
case 11:
|
|
1043
|
-
if ('code' in step) {
|
|
1044
|
-
txs.push(step);
|
|
1045
|
-
} else {
|
|
1046
|
-
console.log("Invalid simulation step: " + step);
|
|
1047
|
-
}
|
|
1048
|
-
case 12:
|
|
1049
|
-
return _context4.a(2);
|
|
1050
|
-
}
|
|
1051
|
-
}, _loop);
|
|
1052
|
-
});
|
|
1053
1254
|
_iterator = _createForOfIteratorHelperLoose(this.steps);
|
|
1054
1255
|
case 2:
|
|
1055
1256
|
if ((_step = _iterator()).done) {
|
|
1056
|
-
|
|
1257
|
+
_context3.n = 14;
|
|
1057
1258
|
break;
|
|
1058
1259
|
}
|
|
1059
|
-
|
|
1260
|
+
step = _step.value;
|
|
1261
|
+
if (!('simulationId' in step)) {
|
|
1262
|
+
_context3.n = 3;
|
|
1263
|
+
break;
|
|
1264
|
+
}
|
|
1265
|
+
throw new Error('inlineSimulation is not yet supported in V2 API. Please run simulations from scratch.');
|
|
1060
1266
|
case 3:
|
|
1061
|
-
|
|
1062
|
-
|
|
1267
|
+
if (!('sender' in step && 'function_name' in step)) {
|
|
1268
|
+
_context3.n = 6;
|
|
1269
|
+
break;
|
|
1270
|
+
}
|
|
1271
|
+
_context3.n = 4;
|
|
1272
|
+
return nextNonce(step.sender);
|
|
1063
1273
|
case 4:
|
|
1064
|
-
|
|
1065
|
-
|
|
1274
|
+
nonce = _context3.v;
|
|
1275
|
+
_context3.n = 5;
|
|
1276
|
+
return makeUnsignedContractCall({
|
|
1277
|
+
contractAddress: step.contract_id.split('.')[0],
|
|
1278
|
+
contractName: step.contract_id.split('.')[1],
|
|
1279
|
+
functionName: step.function_name,
|
|
1280
|
+
functionArgs: (_step$function_args = step.function_args) != null ? _step$function_args : [],
|
|
1281
|
+
nonce: nonce,
|
|
1282
|
+
network: network,
|
|
1283
|
+
publicKey: '',
|
|
1284
|
+
postConditionMode: PostConditionMode.Allow,
|
|
1285
|
+
fee: step.fee
|
|
1286
|
+
});
|
|
1066
1287
|
case 5:
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1288
|
+
tx = _context3.v;
|
|
1289
|
+
setSender(tx, step.sender);
|
|
1290
|
+
v2Steps.push({
|
|
1291
|
+
Transaction: bytesToHex(tx.serializeBytes())
|
|
1292
|
+
});
|
|
1293
|
+
_context3.n = 13;
|
|
1294
|
+
break;
|
|
1295
|
+
case 6:
|
|
1296
|
+
if (!('sender' in step && 'recipient' in step)) {
|
|
1297
|
+
_context3.n = 9;
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
_context3.n = 7;
|
|
1301
|
+
return nextNonce(step.sender);
|
|
1302
|
+
case 7:
|
|
1303
|
+
_nonce = _context3.v;
|
|
1304
|
+
_context3.n = 8;
|
|
1305
|
+
return makeUnsignedSTXTokenTransfer({
|
|
1306
|
+
recipient: step.recipient,
|
|
1307
|
+
amount: step.amount,
|
|
1308
|
+
nonce: _nonce,
|
|
1309
|
+
network: network,
|
|
1310
|
+
publicKey: '',
|
|
1311
|
+
fee: step.fee
|
|
1312
|
+
});
|
|
1313
|
+
case 8:
|
|
1314
|
+
_tx = _context3.v;
|
|
1315
|
+
setSender(_tx, step.sender);
|
|
1316
|
+
v2Steps.push({
|
|
1317
|
+
Transaction: bytesToHex(_tx.serializeBytes())
|
|
1318
|
+
});
|
|
1319
|
+
_context3.n = 13;
|
|
1320
|
+
break;
|
|
1321
|
+
case 9:
|
|
1322
|
+
if (!('deployer' in step)) {
|
|
1323
|
+
_context3.n = 12;
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
_context3.n = 10;
|
|
1327
|
+
return nextNonce(step.deployer);
|
|
1328
|
+
case 10:
|
|
1329
|
+
_nonce2 = _context3.v;
|
|
1330
|
+
_context3.n = 11;
|
|
1331
|
+
return makeUnsignedContractDeploy({
|
|
1332
|
+
contractName: step.contract_name,
|
|
1333
|
+
codeBody: step.source_code,
|
|
1334
|
+
nonce: _nonce2,
|
|
1335
|
+
network: network,
|
|
1336
|
+
publicKey: '',
|
|
1337
|
+
postConditionMode: PostConditionMode.Allow,
|
|
1338
|
+
fee: step.fee,
|
|
1339
|
+
clarityVersion: step.clarity_version
|
|
1340
|
+
});
|
|
1341
|
+
case 11:
|
|
1342
|
+
_tx2 = _context3.v;
|
|
1343
|
+
setSender(_tx2, step.deployer);
|
|
1344
|
+
v2Steps.push({
|
|
1345
|
+
Transaction: bytesToHex(_tx2.serializeBytes())
|
|
1346
|
+
});
|
|
1347
|
+
_context3.n = 13;
|
|
1348
|
+
break;
|
|
1349
|
+
case 12:
|
|
1350
|
+
if ('code' in step) {
|
|
1351
|
+
// Eval step - format: [sender, sponsor, contract_id, code]
|
|
1352
|
+
// For eval without a sender, we use empty string for sponsor
|
|
1353
|
+
_step$contract_id$spl = step.contract_id.split('.'), contractAddress = _step$contract_id$spl[0], contractName = _step$contract_id$spl[1];
|
|
1354
|
+
v2Steps.push({
|
|
1355
|
+
Eval: [this.sender || contractAddress, '', contractAddress + "." + contractName, step.code]
|
|
1356
|
+
});
|
|
1357
|
+
} else if (step.type === 'SetContractCode') {
|
|
1358
|
+
// SetContractCode - format: [contract_id, code, clarity_version]
|
|
1359
|
+
v2Steps.push({
|
|
1360
|
+
SetContractCode: [step.contract_id, step.source_code, clarityVersionToNumber(step.clarity_version)]
|
|
1361
|
+
});
|
|
1362
|
+
} else if (step.type === 'Reads') {
|
|
1363
|
+
// Reads - batch read operations
|
|
1364
|
+
v2Steps.push({
|
|
1365
|
+
Reads: step.reads
|
|
1366
|
+
});
|
|
1367
|
+
} else if (step.type === 'TenureExtend') {
|
|
1368
|
+
// TenureExtend - format: []
|
|
1369
|
+
v2Steps.push({
|
|
1370
|
+
TenureExtend: []
|
|
1371
|
+
});
|
|
1372
|
+
} else {
|
|
1373
|
+
console.log("Invalid simulation step: " + step);
|
|
1374
|
+
}
|
|
1375
|
+
case 13:
|
|
1376
|
+
_context3.n = 2;
|
|
1377
|
+
break;
|
|
1378
|
+
case 14:
|
|
1379
|
+
_context3.n = 15;
|
|
1380
|
+
return createSimulationSession({
|
|
1381
|
+
block_height: block.block_height,
|
|
1382
|
+
block_hash: block.block_hash,
|
|
1383
|
+
skip_tracing: this.skipTracing
|
|
1384
|
+
}, {
|
|
1385
|
+
stxerApi: this.apiEndpoint
|
|
1386
|
+
});
|
|
1387
|
+
case 15:
|
|
1388
|
+
simulationId = _context3.v;
|
|
1389
|
+
_context3.n = 16;
|
|
1390
|
+
return submitSimulationSteps(simulationId, {
|
|
1391
|
+
steps: v2Steps
|
|
1392
|
+
}, {
|
|
1393
|
+
stxerApi: this.apiEndpoint
|
|
1394
|
+
});
|
|
1395
|
+
case 16:
|
|
1396
|
+
console.log("Simulation will be available at: https://stxer.xyz/simulations/" + this.network + "/" + simulationId);
|
|
1397
|
+
return _context3.a(2, simulationId);
|
|
1070
1398
|
}
|
|
1071
|
-
},
|
|
1399
|
+
}, _callee3, this);
|
|
1072
1400
|
}));
|
|
1073
1401
|
function run() {
|
|
1074
1402
|
return _run.apply(this, arguments);
|
|
@@ -1080,6 +1408,78 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
1080
1408
|
};
|
|
1081
1409
|
return SimulationBuilder;
|
|
1082
1410
|
}();
|
|
1411
|
+
// Helper function to convert Uint8Array to hex string
|
|
1412
|
+
function bytesToHex(bytes) {
|
|
1413
|
+
return Array.from(bytes).map(function (b) {
|
|
1414
|
+
return b.toString(16).padStart(2, '0');
|
|
1415
|
+
}).join('');
|
|
1416
|
+
}
|
|
1417
|
+
// Helper function to convert ClarityVersion to number
|
|
1418
|
+
function clarityVersionToNumber(version) {
|
|
1419
|
+
switch (version) {
|
|
1420
|
+
case ClarityVersion.Clarity1:
|
|
1421
|
+
return 1;
|
|
1422
|
+
case ClarityVersion.Clarity2:
|
|
1423
|
+
return 2;
|
|
1424
|
+
case ClarityVersion.Clarity3:
|
|
1425
|
+
return 3;
|
|
1426
|
+
case ClarityVersion.Clarity4:
|
|
1427
|
+
return 4;
|
|
1428
|
+
default:
|
|
1429
|
+
return 4;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
/**
|
|
1434
|
+
* Fetch the current tip information from the sidecar.
|
|
1435
|
+
* @param options - Optional API endpoint configuration
|
|
1436
|
+
* @returns The current chain tip information
|
|
1437
|
+
*/
|
|
1438
|
+
function getTip(_x) {
|
|
1439
|
+
return _getTip.apply(this, arguments);
|
|
1440
|
+
}
|
|
1441
|
+
function _getTip() {
|
|
1442
|
+
_getTip = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
1443
|
+
var _options$stxerApi;
|
|
1444
|
+
var url, response, text;
|
|
1445
|
+
return _regenerator().w(function (_context) {
|
|
1446
|
+
while (1) switch (_context.n) {
|
|
1447
|
+
case 0:
|
|
1448
|
+
if (options === void 0) {
|
|
1449
|
+
options = {};
|
|
1450
|
+
}
|
|
1451
|
+
url = ((_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API$1) + "/sidecar/tip";
|
|
1452
|
+
_context.n = 1;
|
|
1453
|
+
return fetch(url, {
|
|
1454
|
+
method: 'GET',
|
|
1455
|
+
headers: {
|
|
1456
|
+
Accept: 'application/json'
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
case 1:
|
|
1460
|
+
response = _context.v;
|
|
1461
|
+
if (response.ok) {
|
|
1462
|
+
_context.n = 2;
|
|
1463
|
+
break;
|
|
1464
|
+
}
|
|
1465
|
+
throw new Error("Failed to fetch tip: " + response.status + " " + response.statusText);
|
|
1466
|
+
case 2:
|
|
1467
|
+
_context.n = 3;
|
|
1468
|
+
return response.text();
|
|
1469
|
+
case 3:
|
|
1470
|
+
text = _context.v;
|
|
1471
|
+
if (text.startsWith('{')) {
|
|
1472
|
+
_context.n = 4;
|
|
1473
|
+
break;
|
|
1474
|
+
}
|
|
1475
|
+
throw new Error("Invalid response from tip endpoint: " + text);
|
|
1476
|
+
case 4:
|
|
1477
|
+
return _context.a(2, JSON.parse(text));
|
|
1478
|
+
}
|
|
1479
|
+
}, _callee);
|
|
1480
|
+
}));
|
|
1481
|
+
return _getTip.apply(this, arguments);
|
|
1482
|
+
}
|
|
1083
1483
|
|
|
1084
|
-
export { SimulationBuilder, batchRead, callReadonly, readMap, readVariable,
|
|
1484
|
+
export { DEFAULT_STXER_API$1 as DEFAULT_STXER_API, STXER_API_MAINNET, STXER_API_TESTNET, SimulationBuilder, batchRead, callReadonly, createSimulationSession, getContractAST, getSimulationResult, getTip, instantSimulation, parseContract, readMap, readVariable, simulationBatchReads, submitSimulationSteps };
|
|
1085
1485
|
//# sourceMappingURL=stxer.esm.js.map
|