stxer 0.6.1 → 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 +66 -2
- package/dist/batch-api.d.ts +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/stxer.cjs.development.js +13 -3
- 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 +13 -4
- package/dist/stxer.esm.js.map +1 -1
- package/dist/types.d.ts +303 -32
- package/package.json +14 -9
- package/src/batch-api.ts +9 -8
- package/src/index.ts +5 -10
- package/src/simulation-api.ts +1 -1
- package/src/types.ts +344 -36
package/dist/types.d.ts
CHANGED
|
@@ -163,14 +163,62 @@ export interface ExecutionCost {
|
|
|
163
163
|
write_length: number;
|
|
164
164
|
runtime: number;
|
|
165
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Receipt for a transaction that the engine executed to completion.
|
|
168
|
+
*
|
|
169
|
+
* "Successful execution" does NOT imply contract-level success. Four
|
|
170
|
+
* failure signals to check, in this order:
|
|
171
|
+
* 1. Outer `Err` on `Result.Transaction` — engine could not run the tx
|
|
172
|
+
* at all (deserialization failure etc.); no receipt is produced.
|
|
173
|
+
* 2. `post_condition_aborted: true` — execution ran, post-condition
|
|
174
|
+
* tripped, state was rolled back.
|
|
175
|
+
* 3. `vm_error: string` (without `post_condition_aborted`) — Clarity
|
|
176
|
+
* VM raised a runtime error or static analysis failed.
|
|
177
|
+
* 4. `(err uX)` inside `result` — contract returned a Clarity error
|
|
178
|
+
* response. Application-level; NOT signalled by any field above.
|
|
179
|
+
* Decode `result` to detect.
|
|
180
|
+
*
|
|
181
|
+
* `post_condition_aborted` and `vm_error` are NOT independent: when a
|
|
182
|
+
* PC trips the upstream sets `post_condition_aborted: true` AND writes
|
|
183
|
+
* the PC abort reason into `vm_error` as a side effect. The reverse is
|
|
184
|
+
* not true — `vm_error` alone (with `post_condition_aborted: false`)
|
|
185
|
+
* means a VM / analysis failure that is not a PC abort.
|
|
186
|
+
*/
|
|
166
187
|
export interface TransactionReceipt {
|
|
188
|
+
/**
|
|
189
|
+
* Clarity return value, SIP-005 hex-serialized. For contract-call txs
|
|
190
|
+
* this includes the `(ok ...)` / `(err ...)` response wrapper —
|
|
191
|
+
* Clarity-level `(err uX)` lives here, NOT on `vm_error` or the outer
|
|
192
|
+
* `Err`.
|
|
193
|
+
*/
|
|
167
194
|
result: string;
|
|
168
195
|
stx_burned: number;
|
|
169
196
|
tx_index: number;
|
|
197
|
+
/**
|
|
198
|
+
* Error message from the upstream Clarity VM. `null` when the tx had
|
|
199
|
+
* no VM-level issue. When `post_condition_aborted` is `true` this
|
|
200
|
+
* field is also populated with the PC abort reason — check
|
|
201
|
+
* `post_condition_aborted` first to disambiguate.
|
|
202
|
+
*/
|
|
170
203
|
vm_error: string | null;
|
|
204
|
+
/**
|
|
205
|
+
* `true` when one or more post-conditions failed and the tx was
|
|
206
|
+
* aborted. Implies `vm_error` is also set (to the abort reason); the
|
|
207
|
+
* reverse does not hold.
|
|
208
|
+
*/
|
|
171
209
|
post_condition_aborted: boolean;
|
|
210
|
+
/** Wall-clock simulation time in milliseconds. */
|
|
172
211
|
costs: number;
|
|
173
212
|
execution_cost: ExecutionCost;
|
|
213
|
+
/**
|
|
214
|
+
* Events emitted during execution (contract logs, STX transfers,
|
|
215
|
+
* FT/NFT events, etc.). Each entry is a JSON-encoded **string** —
|
|
216
|
+
* call `JSON.parse(events[i])` to get the event object. Items are
|
|
217
|
+
* NOT JSON objects in the array.
|
|
218
|
+
*
|
|
219
|
+
* For typed access, use {@link parseSimulationEvent} or cast:
|
|
220
|
+
* `JSON.parse(events[i]) as SimulationEvent`.
|
|
221
|
+
*/
|
|
174
222
|
events: string[];
|
|
175
223
|
}
|
|
176
224
|
export interface TransactionOkResult {
|
|
@@ -179,25 +227,175 @@ export interface TransactionOkResult {
|
|
|
179
227
|
export interface TransactionErrResult {
|
|
180
228
|
Err: string;
|
|
181
229
|
}
|
|
230
|
+
/** Common envelope present on every event variant. */
|
|
231
|
+
interface SimulationEventBase {
|
|
232
|
+
/** Hex txid with leading `0x`. */
|
|
233
|
+
txid: string;
|
|
234
|
+
event_index: number;
|
|
235
|
+
/**
|
|
236
|
+
* `true` when the event was emitted from successfully committed code.
|
|
237
|
+
* `false` when the tx was rolled back (post-condition abort, vm_error).
|
|
238
|
+
* Tracks rust `tx_receipt.vm_error.is_none() && !post_condition_aborted`.
|
|
239
|
+
*/
|
|
240
|
+
committed: boolean;
|
|
241
|
+
}
|
|
242
|
+
/** Payload for `print` events and other contract-emitted events. */
|
|
243
|
+
export interface SmartContractEventData {
|
|
244
|
+
/** `<address>.<contract_name>` of the contract that emitted the event. */
|
|
245
|
+
contract_identifier: string;
|
|
246
|
+
/** Topic key — `"print"` for `(print …)` calls. */
|
|
247
|
+
topic: string;
|
|
248
|
+
/**
|
|
249
|
+
* Structured Clarity Value JSON (the rust `Value` enum's serde output).
|
|
250
|
+
* The shape is complex and varies by Clarity type; prefer `raw_value`
|
|
251
|
+
* for typed decoding.
|
|
252
|
+
*/
|
|
253
|
+
value: unknown;
|
|
254
|
+
/**
|
|
255
|
+
* SIP-005 hex of the value, with leading `0x`. Pass to
|
|
256
|
+
* `deserializeCV()` from `@stacks/transactions` for typed decoding.
|
|
257
|
+
*/
|
|
258
|
+
raw_value: string;
|
|
259
|
+
}
|
|
260
|
+
export interface StxTransferEventData {
|
|
261
|
+
sender: string;
|
|
262
|
+
recipient: string;
|
|
263
|
+
/** uSTX amount as a decimal string (rust serializes u128 via Display). */
|
|
264
|
+
amount: string;
|
|
265
|
+
/** Hex memo, possibly empty. */
|
|
266
|
+
memo: string;
|
|
267
|
+
}
|
|
268
|
+
export interface StxMintEventData {
|
|
269
|
+
recipient: string;
|
|
270
|
+
amount: string;
|
|
271
|
+
}
|
|
272
|
+
export interface StxBurnEventData {
|
|
273
|
+
sender: string;
|
|
274
|
+
amount: string;
|
|
275
|
+
}
|
|
276
|
+
export interface StxLockEventData {
|
|
277
|
+
locked_amount: string;
|
|
278
|
+
/** Decimal string (rust serializes u64 via Display). */
|
|
279
|
+
unlock_height: string;
|
|
280
|
+
locked_address: string;
|
|
281
|
+
contract_identifier: string;
|
|
282
|
+
}
|
|
283
|
+
export interface NftTransferEventData {
|
|
284
|
+
/** `<contract_id>::<asset_name>`. */
|
|
285
|
+
asset_identifier: string;
|
|
286
|
+
sender: string;
|
|
287
|
+
recipient: string;
|
|
288
|
+
value: unknown;
|
|
289
|
+
raw_value: string;
|
|
290
|
+
}
|
|
291
|
+
export interface NftMintEventData {
|
|
292
|
+
asset_identifier: string;
|
|
293
|
+
recipient: string;
|
|
294
|
+
value: unknown;
|
|
295
|
+
raw_value: string;
|
|
296
|
+
}
|
|
297
|
+
export interface NftBurnEventData {
|
|
298
|
+
asset_identifier: string;
|
|
299
|
+
sender: string;
|
|
300
|
+
value: unknown;
|
|
301
|
+
raw_value: string;
|
|
302
|
+
}
|
|
303
|
+
export interface FtTransferEventData {
|
|
304
|
+
asset_identifier: string;
|
|
305
|
+
sender: string;
|
|
306
|
+
recipient: string;
|
|
307
|
+
amount: string;
|
|
308
|
+
}
|
|
309
|
+
export interface FtMintEventData {
|
|
310
|
+
asset_identifier: string;
|
|
311
|
+
recipient: string;
|
|
312
|
+
amount: string;
|
|
313
|
+
}
|
|
314
|
+
export interface FtBurnEventData {
|
|
315
|
+
asset_identifier: string;
|
|
316
|
+
sender: string;
|
|
317
|
+
amount: string;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Discriminated union of every event variant the simulator emits.
|
|
321
|
+
* The `type` discriminator names the per-variant payload key — e.g.
|
|
322
|
+
* `type: 'contract_event'` carries the payload at `event.contract_event`.
|
|
323
|
+
*
|
|
324
|
+
* ```ts
|
|
325
|
+
* const event = parseSimulationEvent(receipt.events[0]);
|
|
326
|
+
* if (event.type === 'contract_event') {
|
|
327
|
+
* // event.contract_event.{contract_identifier, topic, raw_value, value}
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export type SimulationEvent = (SimulationEventBase & {
|
|
332
|
+
type: 'contract_event';
|
|
333
|
+
contract_event: SmartContractEventData;
|
|
334
|
+
}) | (SimulationEventBase & {
|
|
335
|
+
type: 'stx_transfer_event';
|
|
336
|
+
stx_transfer_event: StxTransferEventData;
|
|
337
|
+
}) | (SimulationEventBase & {
|
|
338
|
+
type: 'stx_mint_event';
|
|
339
|
+
stx_mint_event: StxMintEventData;
|
|
340
|
+
}) | (SimulationEventBase & {
|
|
341
|
+
type: 'stx_burn_event';
|
|
342
|
+
stx_burn_event: StxBurnEventData;
|
|
343
|
+
}) | (SimulationEventBase & {
|
|
344
|
+
type: 'stx_lock_event';
|
|
345
|
+
stx_lock_event: StxLockEventData;
|
|
346
|
+
}) | (SimulationEventBase & {
|
|
347
|
+
type: 'nft_transfer_event';
|
|
348
|
+
nft_transfer_event: NftTransferEventData;
|
|
349
|
+
}) | (SimulationEventBase & {
|
|
350
|
+
type: 'nft_mint_event';
|
|
351
|
+
nft_mint_event: NftMintEventData;
|
|
352
|
+
}) | (SimulationEventBase & {
|
|
353
|
+
type: 'nft_burn_event';
|
|
354
|
+
nft_burn_event: NftBurnEventData;
|
|
355
|
+
}) | (SimulationEventBase & {
|
|
356
|
+
type: 'ft_transfer_event';
|
|
357
|
+
ft_transfer_event: FtTransferEventData;
|
|
358
|
+
}) | (SimulationEventBase & {
|
|
359
|
+
type: 'ft_mint_event';
|
|
360
|
+
ft_mint_event: FtMintEventData;
|
|
361
|
+
}) | (SimulationEventBase & {
|
|
362
|
+
type: 'ft_burn_event';
|
|
363
|
+
ft_burn_event: FtBurnEventData;
|
|
364
|
+
});
|
|
365
|
+
/** Convenience parser for `TransactionReceipt.events[i]`. */
|
|
366
|
+
export declare function parseSimulationEvent(raw: string): SimulationEvent;
|
|
182
367
|
export interface MapEntryStep {
|
|
183
|
-
MapEntry: [string, string, string];
|
|
368
|
+
MapEntry: [contract_id: string, map_name: string, key_hex: string];
|
|
184
369
|
}
|
|
185
370
|
export interface DataVarStep {
|
|
186
|
-
DataVar: [string, string];
|
|
371
|
+
DataVar: [contract_id: string, variable_name: string];
|
|
187
372
|
}
|
|
188
373
|
export interface EvalReadonlyStep {
|
|
189
|
-
|
|
374
|
+
/** `sponsor` is `""` (empty string) when there is no sponsor. */
|
|
375
|
+
EvalReadonly: [
|
|
376
|
+
sender: string,
|
|
377
|
+
sponsor: string,
|
|
378
|
+
contract_id: string,
|
|
379
|
+
code: string
|
|
380
|
+
];
|
|
190
381
|
}
|
|
191
382
|
export interface StxBalanceStep {
|
|
383
|
+
/** Principal whose STX balance to read. */
|
|
192
384
|
StxBalance: string;
|
|
193
385
|
}
|
|
194
386
|
export interface FtBalanceStep {
|
|
195
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Reads the FT balance via three separate parameters. Note: the batch
|
|
389
|
+
* `ft_balance` field on `SimulationBatchReadsRequest` uses a different
|
|
390
|
+
* `<contract_id>::<token_name>` combined identifier shape.
|
|
391
|
+
*/
|
|
392
|
+
FtBalance: [contract_id: string, token_name: string, principal: string];
|
|
196
393
|
}
|
|
197
394
|
export interface FtSupplyStep {
|
|
198
|
-
FtSupply: [string, string];
|
|
395
|
+
FtSupply: [contract_id: string, token_name: string];
|
|
199
396
|
}
|
|
200
397
|
export interface NonceStep {
|
|
398
|
+
/** Principal whose nonce to read. */
|
|
201
399
|
Nonce: string;
|
|
202
400
|
}
|
|
203
401
|
export type ReadStep = MapEntryStep | DataVarStep | EvalReadonlyStep | StxBalanceStep | FtBalanceStep | FtSupplyStep | NonceStep;
|
|
@@ -208,8 +406,38 @@ export interface ReadErrResult {
|
|
|
208
406
|
Err: string;
|
|
209
407
|
}
|
|
210
408
|
export type ReadResult = ReadOkResult | ReadErrResult;
|
|
409
|
+
/**
|
|
410
|
+
* Per-step result returned by `POST /devtools/v2/simulations/{id}` (the
|
|
411
|
+
* "submit steps" endpoint). Mirrors the rust `RunSimulationStepResult`
|
|
412
|
+
* enum — externally tagged, exactly one variant key present.
|
|
413
|
+
*
|
|
414
|
+
* Distinct from `SimulationStepSummary`, which is what
|
|
415
|
+
* `GET /devtools/v2/simulations/{id}` returns and includes the original
|
|
416
|
+
* step input alongside the result.
|
|
417
|
+
*/
|
|
418
|
+
export type SimulationStepResult = {
|
|
419
|
+
Transaction: TransactionOkResult | TransactionErrResult;
|
|
420
|
+
} | {
|
|
421
|
+
Eval: {
|
|
422
|
+
Ok: string;
|
|
423
|
+
} | {
|
|
424
|
+
Err: string;
|
|
425
|
+
};
|
|
426
|
+
} | {
|
|
427
|
+
SetContractCode: {
|
|
428
|
+
Ok: null;
|
|
429
|
+
} | {
|
|
430
|
+
Err: string;
|
|
431
|
+
};
|
|
432
|
+
} | {
|
|
433
|
+
Reads: ReadResult[];
|
|
434
|
+
} | {
|
|
435
|
+
TenureExtend: ExecutionCost;
|
|
436
|
+
};
|
|
211
437
|
export interface TransactionStepSummary {
|
|
438
|
+
/** Transaction serialized to hex. */
|
|
212
439
|
Transaction: string;
|
|
440
|
+
/** Hex-encoded txid. Empty string `""` when the tx failed engine-level. */
|
|
213
441
|
TxId: string;
|
|
214
442
|
Result: {
|
|
215
443
|
Transaction: TransactionOkResult | TransactionErrResult;
|
|
@@ -223,7 +451,7 @@ export interface ReadsStepSummary {
|
|
|
223
451
|
};
|
|
224
452
|
}
|
|
225
453
|
export interface SetContractCodeStepSummary {
|
|
226
|
-
SetContractCode: [string, string, number];
|
|
454
|
+
SetContractCode: [contract_id: string, code: string, clarity_version: number];
|
|
227
455
|
Result: {
|
|
228
456
|
SetContractCode: {
|
|
229
457
|
Ok: null;
|
|
@@ -233,7 +461,8 @@ export interface SetContractCodeStepSummary {
|
|
|
233
461
|
};
|
|
234
462
|
}
|
|
235
463
|
export interface EvalStepSummary {
|
|
236
|
-
|
|
464
|
+
/** `sponsor` is `""` (empty string) when there is no sponsor. */
|
|
465
|
+
Eval: [sender: string, sponsor: string, contract_id: string, code: string];
|
|
237
466
|
Result: {
|
|
238
467
|
Eval: {
|
|
239
468
|
Ok: string;
|
|
@@ -249,7 +478,6 @@ export interface TenureExtendStepSummary {
|
|
|
249
478
|
}
|
|
250
479
|
export type SimulationStepSummary = TransactionStepSummary | ReadsStepSummary | SetContractCodeStepSummary | EvalStepSummary | TenureExtendStepSummary;
|
|
251
480
|
export interface SimulationMetadata {
|
|
252
|
-
ast_rules: 0 | 1;
|
|
253
481
|
block_height: number;
|
|
254
482
|
block_hash: string;
|
|
255
483
|
burn_block_height: number;
|
|
@@ -275,9 +503,19 @@ export interface CreateSimulationResponse {
|
|
|
275
503
|
export type SimulationStepInput = {
|
|
276
504
|
Transaction: string;
|
|
277
505
|
} | {
|
|
278
|
-
|
|
506
|
+
/** `sponsor` is `""` when there is no sponsor. */
|
|
507
|
+
Eval: [
|
|
508
|
+
sender: string,
|
|
509
|
+
sponsor: string,
|
|
510
|
+
contract_id: string,
|
|
511
|
+
code: string
|
|
512
|
+
];
|
|
279
513
|
} | {
|
|
280
|
-
SetContractCode: [
|
|
514
|
+
SetContractCode: [
|
|
515
|
+
contract_id: string,
|
|
516
|
+
code: string,
|
|
517
|
+
clarity_version: number
|
|
518
|
+
];
|
|
281
519
|
} | {
|
|
282
520
|
Reads: ReadStep[];
|
|
283
521
|
} | {
|
|
@@ -287,41 +525,74 @@ export interface SubmitSimulationStepsRequest {
|
|
|
287
525
|
steps: SimulationStepInput[];
|
|
288
526
|
}
|
|
289
527
|
export interface SubmitSimulationStepsResponse {
|
|
290
|
-
steps:
|
|
528
|
+
steps: SimulationStepResult[];
|
|
291
529
|
}
|
|
292
530
|
export interface SimulationBatchReadsRequest {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
531
|
+
/** `[contract_id, variable_name]` per entry. */
|
|
532
|
+
vars?: [contract_id: string, variable_name: string][];
|
|
533
|
+
/** `[contract_id, map_name, key_hex]` per entry. */
|
|
534
|
+
maps?: [contract_id: string, map_name: string, key_hex: string][];
|
|
535
|
+
/**
|
|
536
|
+
* `[contract_id, function_name, ...arg_hex]` per entry. The first two
|
|
537
|
+
* positions are fixed; remaining elements are hex-encoded Clarity
|
|
538
|
+
* values, one per function argument (so the length matches the
|
|
539
|
+
* function's arity, not arbitrary).
|
|
540
|
+
*/
|
|
541
|
+
readonly?: [
|
|
542
|
+
contract_id: string,
|
|
543
|
+
function_name: string,
|
|
544
|
+
...args_hex: string[]
|
|
545
|
+
][];
|
|
546
|
+
/**
|
|
547
|
+
* `[sender, sponsor, contract_id, function_name, ...arg_hex]` per
|
|
548
|
+
* entry. The first four positions are fixed (`sponsor` is `""` when
|
|
549
|
+
* there is no sponsor); remaining elements are hex-encoded Clarity
|
|
550
|
+
* values, one per function argument.
|
|
551
|
+
*/
|
|
552
|
+
readonly_with_sender?: [
|
|
553
|
+
sender: string,
|
|
554
|
+
sponsor: string,
|
|
555
|
+
contract_id: string,
|
|
556
|
+
function_name: string,
|
|
557
|
+
...args_hex: string[]
|
|
558
|
+
][];
|
|
559
|
+
/** Principals to read STX balances for. */
|
|
303
560
|
stx?: string[];
|
|
561
|
+
/** Principals to read nonces for. */
|
|
304
562
|
nonces?: string[];
|
|
305
|
-
|
|
306
|
-
|
|
563
|
+
/** `[<contract_id>::<token_name>, principal]` per entry. */
|
|
564
|
+
ft_balance?: [token_identifier: string, principal: string][];
|
|
565
|
+
/**
|
|
566
|
+
* Flat array of FT identifiers in `<contract_id>::<token_name>` form,
|
|
567
|
+
* one entry per token to look up. Any length.
|
|
568
|
+
*/
|
|
569
|
+
ft_supply?: string[];
|
|
307
570
|
}
|
|
571
|
+
/**
|
|
572
|
+
* Each category is omitted from the JSON response when the corresponding
|
|
573
|
+
* request field was empty/absent (rust uses
|
|
574
|
+
* `serde(skip_serializing_if = "Vec::is_empty")` per field).
|
|
575
|
+
*/
|
|
308
576
|
export interface SimulationBatchReadsResponse {
|
|
309
|
-
vars
|
|
310
|
-
maps
|
|
311
|
-
readonly
|
|
312
|
-
readonly_with_sender
|
|
313
|
-
stx
|
|
314
|
-
nonces
|
|
315
|
-
ft_balance
|
|
316
|
-
ft_supply
|
|
577
|
+
vars?: ReadResult[];
|
|
578
|
+
maps?: ReadResult[];
|
|
579
|
+
readonly?: ReadResult[];
|
|
580
|
+
readonly_with_sender?: ReadResult[];
|
|
581
|
+
stx?: ReadResult[];
|
|
582
|
+
nonces?: ReadResult[];
|
|
583
|
+
ft_balance?: ReadResult[];
|
|
584
|
+
ft_supply?: ReadResult[];
|
|
317
585
|
}
|
|
318
586
|
export interface InstantSimulationRequest {
|
|
587
|
+
/** Transaction serialized to hex. */
|
|
319
588
|
transaction: string;
|
|
320
589
|
block_height?: number;
|
|
321
590
|
block_hash?: string;
|
|
322
591
|
reads?: ReadStep[];
|
|
323
592
|
}
|
|
324
593
|
export interface InstantSimulationResponse {
|
|
325
|
-
|
|
594
|
+
/** Always present (may be `[]`). Aligned positionally with the request `reads`. */
|
|
595
|
+
reads: ReadResult[];
|
|
326
596
|
receipt: TransactionReceipt;
|
|
327
597
|
}
|
|
598
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stxer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Kyle Fang",
|
|
6
6
|
"repository": {
|
|
@@ -44,21 +44,21 @@
|
|
|
44
44
|
}
|
|
45
45
|
],
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@biomejs/biome": "
|
|
48
|
-
"@size-limit/preset-small-lib": "
|
|
47
|
+
"@biomejs/biome": "2.4.13",
|
|
48
|
+
"@size-limit/preset-small-lib": "12.1.0",
|
|
49
49
|
"@tsconfig/recommended": "^1.0.13",
|
|
50
|
-
"@types/node": "
|
|
50
|
+
"@types/node": "25.6.0",
|
|
51
51
|
"dts-cli": "^2.0.5",
|
|
52
52
|
"husky": "^9.1.7",
|
|
53
|
-
"size-limit": "
|
|
54
|
-
"tslib": "^2.8.1",
|
|
53
|
+
"size-limit": "12.1.0",
|
|
55
54
|
"tsx": "^4.21.0",
|
|
56
|
-
"typescript": "
|
|
55
|
+
"typescript": "5.9.3",
|
|
56
|
+
"vitest": "^4.1.5"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@stacks/network": "^7.3.1",
|
|
60
60
|
"@stacks/stacks-blockchain-api-types": "^7.14.1",
|
|
61
|
-
"@stacks/transactions": "
|
|
61
|
+
"@stacks/transactions": "7.4.0",
|
|
62
62
|
"c32check": "^2.0.0",
|
|
63
63
|
"clarity-abi": "^0.1.0",
|
|
64
64
|
"ts-clarity": "^0.1.1"
|
|
@@ -71,6 +71,11 @@
|
|
|
71
71
|
"start": "dts watch",
|
|
72
72
|
"test": "dts test",
|
|
73
73
|
"sample:counter": "tsx src/sample/counter.ts",
|
|
74
|
-
"sample:read": "tsx src/sample/read.ts"
|
|
74
|
+
"sample:read": "tsx src/sample/read.ts",
|
|
75
|
+
"sample:instant": "tsx src/sample/instant.ts",
|
|
76
|
+
"sample:failure-modes": "tsx src/sample/failure-modes.ts",
|
|
77
|
+
"sample:batch-categories": "tsx src/sample/batch-categories.ts",
|
|
78
|
+
"sample:verify-types": "tsx src/sample/verify-types.ts",
|
|
79
|
+
"sample:vitest": "vitest run src/sample/contract-vitest.test.ts"
|
|
75
80
|
}
|
|
76
81
|
}
|
package/src/batch-api.ts
CHANGED
|
@@ -31,7 +31,8 @@ export interface BatchReads {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface BatchReadsResult {
|
|
34
|
-
|
|
34
|
+
/** Index block hash the batch ran against. Matches the wire field name. */
|
|
35
|
+
index_block_hash: string;
|
|
35
36
|
vars: (ClarityValue | Error)[];
|
|
36
37
|
maps: (ClarityValue | Error)[];
|
|
37
38
|
readonly: (ClarityValue | Error)[];
|
|
@@ -44,10 +45,10 @@ export interface BatchApiOptions {
|
|
|
44
45
|
const DEFAULT_STXER_API = 'https://api.stxer.xyz';
|
|
45
46
|
|
|
46
47
|
function convertResults(
|
|
47
|
-
rs: ({ Ok: string } | { Err: string })[],
|
|
48
|
+
rs: ({ Ok: string } | { Err: string })[] | undefined,
|
|
48
49
|
): (ClarityValue | Error)[] {
|
|
49
50
|
const results: (ClarityValue | Error)[] = [];
|
|
50
|
-
for (const v of rs) {
|
|
51
|
+
for (const v of rs ?? []) {
|
|
51
52
|
if ('Ok' in v) {
|
|
52
53
|
results.push(deserializeCV(v.Ok));
|
|
53
54
|
} else {
|
|
@@ -123,14 +124,14 @@ export async function batchRead(
|
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
const rs = JSON.parse(text) as {
|
|
126
|
-
|
|
127
|
-
vars
|
|
128
|
-
maps
|
|
129
|
-
readonly
|
|
127
|
+
index_block_hash: string;
|
|
128
|
+
vars?: ({ Ok: string } | { Err: string })[];
|
|
129
|
+
maps?: ({ Ok: string } | { Err: string })[];
|
|
130
|
+
readonly?: ({ Ok: string } | { Err: string })[];
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
return {
|
|
133
|
-
|
|
134
|
+
index_block_hash: rs.index_block_hash,
|
|
134
135
|
vars: convertResults(rs.vars),
|
|
135
136
|
maps: convertResults(rs.maps),
|
|
136
137
|
readonly: convertResults(rs.readonly),
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
+
// `dts build` (rollup-plugin-typescript2 + babel) does not enable
|
|
2
|
+
// `@babel/preset-typescript` on the entry, so inline `type` specifiers
|
|
3
|
+
// inside `export {}` and standalone `export type {}` blocks both crash
|
|
4
|
+
// the build (babel falls back to flow grammar). Stick with `export *`.
|
|
1
5
|
export * from './ast';
|
|
2
6
|
export * from './batch-api';
|
|
3
7
|
export * from './clarity-api';
|
|
4
8
|
export * from './constants';
|
|
5
9
|
export * from './simulation';
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
type CreateSessionOptions,
|
|
9
|
-
createSimulationSession,
|
|
10
|
-
getSimulationResult,
|
|
11
|
-
instantSimulation,
|
|
12
|
-
type SimulationApiOptions,
|
|
13
|
-
simulationBatchReads,
|
|
14
|
-
submitSimulationSteps,
|
|
15
|
-
} from './simulation-api';
|
|
10
|
+
export * from './simulation-api';
|
|
16
11
|
export * from './tip';
|
|
17
12
|
export * from './types';
|
package/src/simulation-api.ts
CHANGED
|
@@ -69,7 +69,7 @@ export async function instantSimulation(
|
|
|
69
69
|
const apiEndpoint = options.stxerApi ?? DEFAULT_STXER_API;
|
|
70
70
|
|
|
71
71
|
const response = await fetch(
|
|
72
|
-
`${apiEndpoint}/devtools/v2/
|
|
72
|
+
`${apiEndpoint}/devtools/v2/simulations:instant`,
|
|
73
73
|
{
|
|
74
74
|
method: 'POST',
|
|
75
75
|
body: JSON.stringify(request),
|