stxer 0.6.1 → 0.8.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/CHANGELOG.md +118 -0
- package/README.md +300 -55
- package/dist/ast.d.ts +1 -1
- package/dist/batch-api.d.ts +2 -1
- package/dist/bitcoin.d.ts +121 -0
- package/dist/index.d.ts +3 -1
- package/dist/simulation-api.d.ts +52 -3
- package/dist/simulation.d.ts +70 -3
- package/dist/stxer.cjs.development.js +917 -104
- 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 +897 -107
- package/dist/stxer.esm.js.map +1 -1
- package/dist/transaction.d.ts +71 -0
- package/dist/types.d.ts +547 -54
- package/package.json +17 -10
- package/src/ast.ts +1 -1
- package/src/batch-api.ts +9 -8
- package/src/bitcoin.ts +391 -0
- package/src/index.ts +7 -10
- package/src/simulation-api.ts +110 -13
- package/src/simulation.ts +245 -46
- package/src/transaction.ts +141 -0
- package/src/types.ts +594 -59
package/dist/stxer.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { serializeCV, deserializeCV, contractPrincipalCV, ClarityType,
|
|
1
|
+
import { serializeCV, deserializeCV, contractPrincipalCV, ClarityType, AddressHashMode, Cl, serializeTransaction, makeUnsignedContractCall, PostConditionMode, ClarityVersion, cvToString, makeUnsignedContractDeploy, makeUnsignedSTXTokenTransfer } from '@stacks/transactions';
|
|
2
|
+
import { sha256 as sha256$1 } from '@noble/hashes/sha2.js';
|
|
2
3
|
import { encodeAbi, decodeAbi, richFetch, getNodeInfo } from 'ts-clarity';
|
|
3
|
-
import { STACKS_MAINNET, STACKS_TESTNET
|
|
4
|
+
import { AddressVersion, STACKS_MAINNET, STACKS_TESTNET } from '@stacks/network';
|
|
4
5
|
import { c32addressDecode } from 'c32check';
|
|
5
6
|
|
|
6
7
|
function _arrayLikeToArray(r, a) {
|
|
@@ -33,6 +34,13 @@ function _asyncToGenerator(n) {
|
|
|
33
34
|
});
|
|
34
35
|
};
|
|
35
36
|
}
|
|
37
|
+
function _construct(t, e, r) {
|
|
38
|
+
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
39
|
+
var o = [null];
|
|
40
|
+
o.push.apply(o, e);
|
|
41
|
+
var p = new (t.bind.apply(t, o))();
|
|
42
|
+
return r && _setPrototypeOf(p, r.prototype), p;
|
|
43
|
+
}
|
|
36
44
|
function _createForOfIteratorHelperLoose(r, e) {
|
|
37
45
|
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
38
46
|
if (t) return (t = t.call(r)).next.bind(t);
|
|
@@ -59,6 +67,29 @@ function _extends() {
|
|
|
59
67
|
return n;
|
|
60
68
|
}, _extends.apply(null, arguments);
|
|
61
69
|
}
|
|
70
|
+
function _getPrototypeOf(t) {
|
|
71
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
72
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
73
|
+
}, _getPrototypeOf(t);
|
|
74
|
+
}
|
|
75
|
+
function _inheritsLoose(t, o) {
|
|
76
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
77
|
+
}
|
|
78
|
+
function _isNativeFunction(t) {
|
|
79
|
+
try {
|
|
80
|
+
return -1 !== Function.toString.call(t).indexOf("[native code]");
|
|
81
|
+
} catch (n) {
|
|
82
|
+
return "function" == typeof t;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function _isNativeReflectConstruct() {
|
|
86
|
+
try {
|
|
87
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
88
|
+
} catch (t) {}
|
|
89
|
+
return (_isNativeReflectConstruct = function () {
|
|
90
|
+
return !!t;
|
|
91
|
+
})();
|
|
92
|
+
}
|
|
62
93
|
function _regenerator() {
|
|
63
94
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
64
95
|
var e,
|
|
@@ -167,6 +198,11 @@ function _regeneratorDefine(e, r, n, t) {
|
|
|
167
198
|
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
168
199
|
}, _regeneratorDefine(e, r, n, t);
|
|
169
200
|
}
|
|
201
|
+
function _setPrototypeOf(t, e) {
|
|
202
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
203
|
+
return t.__proto__ = e, t;
|
|
204
|
+
}, _setPrototypeOf(t, e);
|
|
205
|
+
}
|
|
170
206
|
function _unsupportedIterableToArray(r, a) {
|
|
171
207
|
if (r) {
|
|
172
208
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -174,6 +210,28 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
174
210
|
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
175
211
|
}
|
|
176
212
|
}
|
|
213
|
+
function _wrapNativeSuper(t) {
|
|
214
|
+
var r = "function" == typeof Map ? new Map() : void 0;
|
|
215
|
+
return _wrapNativeSuper = function (t) {
|
|
216
|
+
if (null === t || !_isNativeFunction(t)) return t;
|
|
217
|
+
if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
|
|
218
|
+
if (void 0 !== r) {
|
|
219
|
+
if (r.has(t)) return r.get(t);
|
|
220
|
+
r.set(t, Wrapper);
|
|
221
|
+
}
|
|
222
|
+
function Wrapper() {
|
|
223
|
+
return _construct(t, arguments, _getPrototypeOf(this).constructor);
|
|
224
|
+
}
|
|
225
|
+
return Wrapper.prototype = Object.create(t.prototype, {
|
|
226
|
+
constructor: {
|
|
227
|
+
value: Wrapper,
|
|
228
|
+
enumerable: !1,
|
|
229
|
+
writable: !0,
|
|
230
|
+
configurable: !0
|
|
231
|
+
}
|
|
232
|
+
}), _setPrototypeOf(Wrapper, t);
|
|
233
|
+
}, _wrapNativeSuper(t);
|
|
234
|
+
}
|
|
177
235
|
|
|
178
236
|
/**
|
|
179
237
|
* API endpoint constants
|
|
@@ -295,7 +353,7 @@ function _parseContract() {
|
|
|
295
353
|
var DEFAULT_STXER_API = 'https://api.stxer.xyz';
|
|
296
354
|
function convertResults(rs) {
|
|
297
355
|
var results = [];
|
|
298
|
-
for (var _iterator = _createForOfIteratorHelperLoose(rs), _step; !(_step = _iterator()).done;) {
|
|
356
|
+
for (var _iterator = _createForOfIteratorHelperLoose(rs != null ? rs : []), _step; !(_step = _iterator()).done;) {
|
|
299
357
|
var v = _step.value;
|
|
300
358
|
if ('Ok' in v) {
|
|
301
359
|
results.push(deserializeCV(v.Ok));
|
|
@@ -368,7 +426,7 @@ function _batchRead() {
|
|
|
368
426
|
case 3:
|
|
369
427
|
rs = JSON.parse(text);
|
|
370
428
|
return _context.a(2, {
|
|
371
|
-
|
|
429
|
+
index_block_hash: rs.index_block_hash,
|
|
372
430
|
vars: convertResults(rs.vars),
|
|
373
431
|
maps: convertResults(rs.maps),
|
|
374
432
|
readonly: convertResults(rs.readonly)
|
|
@@ -379,6 +437,273 @@ function _batchRead() {
|
|
|
379
437
|
return _batchRead.apply(this, arguments);
|
|
380
438
|
}
|
|
381
439
|
|
|
440
|
+
// ============================================================================
|
|
441
|
+
// Hashing primitives
|
|
442
|
+
// ============================================================================
|
|
443
|
+
/**
|
|
444
|
+
* SHA-256. Pure-JS via `@noble/hashes` so this module works in
|
|
445
|
+
* browsers, Node, and Bun without a polyfill.
|
|
446
|
+
*/
|
|
447
|
+
function sha256(data) {
|
|
448
|
+
return sha256$1(data);
|
|
449
|
+
}
|
|
450
|
+
/** Bitcoin-style double-sha256 used for txids, block hashes, and Merkle nodes. */
|
|
451
|
+
function sha256d(data) {
|
|
452
|
+
return sha256(sha256(data));
|
|
453
|
+
}
|
|
454
|
+
// ============================================================================
|
|
455
|
+
// Hex encoding
|
|
456
|
+
// ============================================================================
|
|
457
|
+
/** Decode a hex string (with or without `0x` prefix). */
|
|
458
|
+
function hexToBytes(s) {
|
|
459
|
+
var t = s.toLowerCase().replace(/^0x/, '');
|
|
460
|
+
if (t.length % 2 !== 0) throw new Error('odd-length hex');
|
|
461
|
+
var out = new Uint8Array(t.length / 2);
|
|
462
|
+
for (var i = 0; i < out.length; i++) {
|
|
463
|
+
out[i] = Number.parseInt(t.slice(i * 2, i * 2 + 2), 16);
|
|
464
|
+
}
|
|
465
|
+
return out;
|
|
466
|
+
}
|
|
467
|
+
/** Lower-case hex (no `0x` prefix). */
|
|
468
|
+
function bytesToHex(b) {
|
|
469
|
+
return Array.from(b).map(function (x) {
|
|
470
|
+
return x.toString(16).padStart(2, '0');
|
|
471
|
+
}).join('');
|
|
472
|
+
}
|
|
473
|
+
// ============================================================================
|
|
474
|
+
// Bitcoin script builders
|
|
475
|
+
// ============================================================================
|
|
476
|
+
/** P2WPKH output script: `OP_0 <20-byte pubkey-hash>`. */
|
|
477
|
+
function p2wpkhScript(pubKeyHash20) {
|
|
478
|
+
if (pubKeyHash20.length !== 20) {
|
|
479
|
+
throw new Error('pubKeyHash must be 20 bytes');
|
|
480
|
+
}
|
|
481
|
+
var out = new Uint8Array(22);
|
|
482
|
+
out[0] = 0x00; // OP_0
|
|
483
|
+
out[1] = 0x14; // pushdata length 20
|
|
484
|
+
out.set(pubKeyHash20, 2);
|
|
485
|
+
return out;
|
|
486
|
+
}
|
|
487
|
+
/** P2PKH output script: `OP_DUP OP_HASH160 <hash> OP_EQUALVERIFY OP_CHECKSIG`. */
|
|
488
|
+
function p2pkhScript(pubKeyHash20) {
|
|
489
|
+
if (pubKeyHash20.length !== 20) {
|
|
490
|
+
throw new Error('pubKeyHash must be 20 bytes');
|
|
491
|
+
}
|
|
492
|
+
var out = new Uint8Array(25);
|
|
493
|
+
out[0] = 0x76; // OP_DUP
|
|
494
|
+
out[1] = 0xa9; // OP_HASH160
|
|
495
|
+
out[2] = 0x14; // pushdata 20
|
|
496
|
+
out.set(pubKeyHash20, 3);
|
|
497
|
+
out[23] = 0x88; // OP_EQUALVERIFY
|
|
498
|
+
out[24] = 0xac; // OP_CHECKSIG
|
|
499
|
+
return out;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* `OP_RETURN <data>` output. Used to embed peg-in metadata
|
|
503
|
+
* (recipient principal, marker bytes, etc.). Bitcoin's standard relay
|
|
504
|
+
* limit caps `data` at 80 bytes; this helper rejects > 75 to leave
|
|
505
|
+
* room for the prefix bytes.
|
|
506
|
+
*/
|
|
507
|
+
function opReturnScript(data) {
|
|
508
|
+
if (data.length > 75) {
|
|
509
|
+
throw new Error("OP_RETURN data too long: " + data.length);
|
|
510
|
+
}
|
|
511
|
+
var out = new Uint8Array(2 + data.length);
|
|
512
|
+
out[0] = 0x6a; // OP_RETURN
|
|
513
|
+
out[1] = data.length; // direct push
|
|
514
|
+
out.set(data, 2);
|
|
515
|
+
return out;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Build a non-witness Bitcoin transaction (legacy serialization). The
|
|
519
|
+
* txid is `sha256d` of the returned `bytes`. Use this form when you
|
|
520
|
+
* only need to assert SPV inclusion; segwit witness data is irrelevant
|
|
521
|
+
* to the txid.
|
|
522
|
+
*
|
|
523
|
+
* Wire format:
|
|
524
|
+
* ```
|
|
525
|
+
* 4 version (LE)
|
|
526
|
+
* varint in-count
|
|
527
|
+
* per-input: 32 prev_txid + 4 prev_vout + varint script-len + script + 4 sequence
|
|
528
|
+
* varint out-count
|
|
529
|
+
* per-output: 8 value (LE) + varint script-len + script
|
|
530
|
+
* 4 locktime (LE)
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
function forgeBitcoinTx(opts) {
|
|
534
|
+
var _opts$version, _opts$locktime;
|
|
535
|
+
var chunks = [];
|
|
536
|
+
var u32le = function u32le(n) {
|
|
537
|
+
var b = new Uint8Array(4);
|
|
538
|
+
new DataView(b.buffer).setUint32(0, n >>> 0, true);
|
|
539
|
+
return b;
|
|
540
|
+
};
|
|
541
|
+
var u64le = function u64le(n) {
|
|
542
|
+
var b = new Uint8Array(8);
|
|
543
|
+
var view = new DataView(b.buffer);
|
|
544
|
+
view.setUint32(0, Number(n & 0xffffffffn), true);
|
|
545
|
+
view.setUint32(4, Number(n >> 32n & 0xffffffffn), true);
|
|
546
|
+
return b;
|
|
547
|
+
};
|
|
548
|
+
var varint = function varint(n) {
|
|
549
|
+
if (n < 0xfd) return new Uint8Array([n]);
|
|
550
|
+
if (n <= 0xffff) {
|
|
551
|
+
var b = new Uint8Array(3);
|
|
552
|
+
b[0] = 0xfd;
|
|
553
|
+
new DataView(b.buffer).setUint16(1, n, true);
|
|
554
|
+
return b;
|
|
555
|
+
}
|
|
556
|
+
if (n <= 0xffffffff) {
|
|
557
|
+
var _b = new Uint8Array(5);
|
|
558
|
+
_b[0] = 0xfe;
|
|
559
|
+
new DataView(_b.buffer).setUint32(1, n, true);
|
|
560
|
+
return _b;
|
|
561
|
+
}
|
|
562
|
+
throw new Error("varint too large: " + n);
|
|
563
|
+
};
|
|
564
|
+
chunks.push(u32le((_opts$version = opts.version) != null ? _opts$version : 2));
|
|
565
|
+
chunks.push(varint(opts.inputs.length));
|
|
566
|
+
for (var _iterator = _createForOfIteratorHelperLoose(opts.inputs), _step; !(_step = _iterator()).done;) {
|
|
567
|
+
var _i$sequence;
|
|
568
|
+
var i = _step.value;
|
|
569
|
+
if (i.prevTxid.length !== 32) {
|
|
570
|
+
throw new Error('prevTxid must be 32 bytes');
|
|
571
|
+
}
|
|
572
|
+
chunks.push(i.prevTxid);
|
|
573
|
+
chunks.push(u32le(i.prevVout));
|
|
574
|
+
chunks.push(varint(i.scriptSig.length));
|
|
575
|
+
chunks.push(i.scriptSig);
|
|
576
|
+
chunks.push(u32le((_i$sequence = i.sequence) != null ? _i$sequence : 0xfffffffd));
|
|
577
|
+
}
|
|
578
|
+
chunks.push(varint(opts.outputs.length));
|
|
579
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(opts.outputs), _step2; !(_step2 = _iterator2()).done;) {
|
|
580
|
+
var o = _step2.value;
|
|
581
|
+
chunks.push(u64le(o.value));
|
|
582
|
+
chunks.push(varint(o.scriptPubKey.length));
|
|
583
|
+
chunks.push(o.scriptPubKey);
|
|
584
|
+
}
|
|
585
|
+
chunks.push(u32le((_opts$locktime = opts.locktime) != null ? _opts$locktime : 0));
|
|
586
|
+
var total = chunks.reduce(function (s, c) {
|
|
587
|
+
return s + c.length;
|
|
588
|
+
}, 0);
|
|
589
|
+
var bytes = new Uint8Array(total);
|
|
590
|
+
var off = 0;
|
|
591
|
+
for (var _i = 0, _chunks = chunks; _i < _chunks.length; _i++) {
|
|
592
|
+
var c = _chunks[_i];
|
|
593
|
+
bytes.set(c, off);
|
|
594
|
+
off += c.length;
|
|
595
|
+
}
|
|
596
|
+
var txid = sha256d(bytes);
|
|
597
|
+
var txidDisplay = reverseBytes(txid);
|
|
598
|
+
return {
|
|
599
|
+
bytes: bytes,
|
|
600
|
+
txid: txid,
|
|
601
|
+
txidDisplay: txidDisplay
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Build an 80-byte Bitcoin block header. `prevHash` and `merkleRoot`
|
|
606
|
+
* are written in internal byte order (raw `sha256d` output) — matching
|
|
607
|
+
* the on-chain `clarity-bitcoin-v1-07` parser convention.
|
|
608
|
+
*/
|
|
609
|
+
function buildBitcoinHeader(h) {
|
|
610
|
+
var _h$version, _h$prevHash, _h$timestamp, _h$bits, _h$nonce;
|
|
611
|
+
var out = new Uint8Array(80);
|
|
612
|
+
var view = new DataView(out.buffer);
|
|
613
|
+
view.setUint32(0, (_h$version = h.version) != null ? _h$version : 0x20000000, true);
|
|
614
|
+
out.set((_h$prevHash = h.prevHash) != null ? _h$prevHash : new Uint8Array(32), 4);
|
|
615
|
+
out.set(h.merkleRoot, 36);
|
|
616
|
+
view.setUint32(68, (_h$timestamp = h.timestamp) != null ? _h$timestamp : Math.floor(Date.now() / 1000), true);
|
|
617
|
+
view.setUint32(72, (_h$bits = h.bits) != null ? _h$bits : 0x1d00ffff, true);
|
|
618
|
+
view.setUint32(76, (_h$nonce = h.nonce) != null ? _h$nonce : 0, true);
|
|
619
|
+
var rawHash = sha256d(out);
|
|
620
|
+
return {
|
|
621
|
+
header: out,
|
|
622
|
+
hash: reverseBytes(rawHash),
|
|
623
|
+
rawHash: rawHash
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
// ============================================================================
|
|
627
|
+
// Merkle proofs (Bitcoin convention)
|
|
628
|
+
// ============================================================================
|
|
629
|
+
/**
|
|
630
|
+
* Single-tx Merkle root — the txid itself. Bitcoin's Merkle tree
|
|
631
|
+
* convention does NOT pre-hash the leaves; for a one-tx block the
|
|
632
|
+
* root equals the txid.
|
|
633
|
+
*/
|
|
634
|
+
function singleTxMerkleRoot(txid) {
|
|
635
|
+
return new Uint8Array(txid);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Compute a Bitcoin Merkle proof for `txid` at `index` in `txids`
|
|
639
|
+
* (transaction order within the block). Returns the sibling hashes
|
|
640
|
+
* from leaf to root.
|
|
641
|
+
*
|
|
642
|
+
* Bitcoin convention:
|
|
643
|
+
* - Leaves are the txids themselves (no pre-hashing).
|
|
644
|
+
* - Inner nodes are `sha256d(left || right)`.
|
|
645
|
+
* - Odd levels duplicate the last entry to pair.
|
|
646
|
+
*/
|
|
647
|
+
function merkleProof(txids, index) {
|
|
648
|
+
if (index < 0 || index >= txids.length) {
|
|
649
|
+
throw new Error("merkleProof: index " + index + " out of range " + txids.length);
|
|
650
|
+
}
|
|
651
|
+
var level = txids.map(function (t) {
|
|
652
|
+
return new Uint8Array(t);
|
|
653
|
+
});
|
|
654
|
+
var proof = [];
|
|
655
|
+
var i = index;
|
|
656
|
+
while (level.length > 1) {
|
|
657
|
+
if (level.length % 2 === 1) level.push(level[level.length - 1]);
|
|
658
|
+
var sibling = level[i ^ 1];
|
|
659
|
+
proof.push(sibling);
|
|
660
|
+
var next = [];
|
|
661
|
+
for (var j = 0; j < level.length; j += 2) {
|
|
662
|
+
next.push(sha256d(concatBytes(level[j], level[j + 1])));
|
|
663
|
+
}
|
|
664
|
+
level = next;
|
|
665
|
+
i = Math.floor(i / 2);
|
|
666
|
+
}
|
|
667
|
+
return {
|
|
668
|
+
proof: proof,
|
|
669
|
+
root: level[0]
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Verify a Bitcoin Merkle proof against `root`. Returns `true` iff the
|
|
674
|
+
* proof reconstructs the root from `txid` at `index`. Matches the
|
|
675
|
+
* on-chain `verify-merkle-proof` semantic.
|
|
676
|
+
*/
|
|
677
|
+
function verifyMerkleProof(txid, index, proof, root) {
|
|
678
|
+
var h = new Uint8Array(txid);
|
|
679
|
+
var i = index;
|
|
680
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(proof), _step3; !(_step3 = _iterator3()).done;) {
|
|
681
|
+
var sibling = _step3.value;
|
|
682
|
+
h = (i & 1) === 0 ? sha256d(concatBytes(h, sibling)) : sha256d(concatBytes(sibling, h));
|
|
683
|
+
i = Math.floor(i / 2);
|
|
684
|
+
}
|
|
685
|
+
return bytesEqual(h, root);
|
|
686
|
+
}
|
|
687
|
+
// ============================================================================
|
|
688
|
+
// Internal byte helpers
|
|
689
|
+
// ============================================================================
|
|
690
|
+
function reverseBytes(a) {
|
|
691
|
+
var out = new Uint8Array(a.length);
|
|
692
|
+
for (var i = 0; i < a.length; i++) out[i] = a[a.length - 1 - i];
|
|
693
|
+
return out;
|
|
694
|
+
}
|
|
695
|
+
function concatBytes(a, b) {
|
|
696
|
+
var out = new Uint8Array(a.length + b.length);
|
|
697
|
+
out.set(a, 0);
|
|
698
|
+
out.set(b, a.length);
|
|
699
|
+
return out;
|
|
700
|
+
}
|
|
701
|
+
function bytesEqual(a, b) {
|
|
702
|
+
if (a.length !== b.length) return false;
|
|
703
|
+
for (var i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
|
|
382
707
|
var BatchProcessor = /*#__PURE__*/function () {
|
|
383
708
|
function BatchProcessor(options) {
|
|
384
709
|
var _options$stxerAPIEndp;
|
|
@@ -692,6 +1017,43 @@ function _readVariable() {
|
|
|
692
1017
|
return _readVariable.apply(this, arguments);
|
|
693
1018
|
}
|
|
694
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* Thrown by the simulation-api fetch wrappers when the API responds
|
|
1022
|
+
* with a non-2xx status. `status` carries the wire HTTP code so
|
|
1023
|
+
* callers can branch on 409 (busy) / 410 (outdated) without parsing
|
|
1024
|
+
* the message string. `marker` is the server-side classification
|
|
1025
|
+
* extracted from the body prefix (`simulation_busy:` /
|
|
1026
|
+
* `simulation_outdated:`).
|
|
1027
|
+
*
|
|
1028
|
+
* Pre-0.8.0 SDKs threw a plain `Error` whose message embedded the body
|
|
1029
|
+
* text; that lossy form is still used for the message field here so
|
|
1030
|
+
* existing log scrapers keep working.
|
|
1031
|
+
*/
|
|
1032
|
+
var SimulationError = /*#__PURE__*/function (_Error) {
|
|
1033
|
+
function SimulationError(operation, status, body) {
|
|
1034
|
+
var _this;
|
|
1035
|
+
var marker = detectMarker(body);
|
|
1036
|
+
_this = _Error.call(this, operation + " (HTTP " + status + "): " + body) || this;
|
|
1037
|
+
_this.status = void 0;
|
|
1038
|
+
_this.marker = void 0;
|
|
1039
|
+
_this.body = void 0;
|
|
1040
|
+
_this.name = 'SimulationError';
|
|
1041
|
+
_this.status = status;
|
|
1042
|
+
_this.marker = marker;
|
|
1043
|
+
_this.body = body;
|
|
1044
|
+
return _this;
|
|
1045
|
+
}
|
|
1046
|
+
_inheritsLoose(SimulationError, _Error);
|
|
1047
|
+
return SimulationError;
|
|
1048
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
1049
|
+
function detectMarker(body) {
|
|
1050
|
+
if (body.includes('simulation_busy:')) return 'simulation_busy';
|
|
1051
|
+
if (body.includes('simulation_outdated:')) return 'simulation_outdated';
|
|
1052
|
+
return null;
|
|
1053
|
+
}
|
|
1054
|
+
function throwSimulationError(_x, _x2) {
|
|
1055
|
+
return _throwSimulationError.apply(this, arguments);
|
|
1056
|
+
}
|
|
695
1057
|
/**
|
|
696
1058
|
* Instantly simulate a transaction
|
|
697
1059
|
*
|
|
@@ -718,7 +1080,25 @@ function _readVariable() {
|
|
|
718
1080
|
* console.log(result.receipt.result);
|
|
719
1081
|
* ```
|
|
720
1082
|
*/
|
|
721
|
-
function
|
|
1083
|
+
function _throwSimulationError() {
|
|
1084
|
+
_throwSimulationError = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(operation, response) {
|
|
1085
|
+
var text;
|
|
1086
|
+
return _regenerator().w(function (_context) {
|
|
1087
|
+
while (1) switch (_context.n) {
|
|
1088
|
+
case 0:
|
|
1089
|
+
_context.n = 1;
|
|
1090
|
+
return response.text();
|
|
1091
|
+
case 1:
|
|
1092
|
+
text = _context.v;
|
|
1093
|
+
throw new SimulationError(operation, response.status, text);
|
|
1094
|
+
case 2:
|
|
1095
|
+
return _context.a(2);
|
|
1096
|
+
}
|
|
1097
|
+
}, _callee);
|
|
1098
|
+
}));
|
|
1099
|
+
return _throwSimulationError.apply(this, arguments);
|
|
1100
|
+
}
|
|
1101
|
+
function instantSimulation(_x3, _x4) {
|
|
722
1102
|
return _instantSimulation.apply(this, arguments);
|
|
723
1103
|
}
|
|
724
1104
|
/**
|
|
@@ -741,18 +1121,18 @@ function instantSimulation(_x, _x2) {
|
|
|
741
1121
|
* ```
|
|
742
1122
|
*/
|
|
743
1123
|
function _instantSimulation() {
|
|
744
|
-
_instantSimulation = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1124
|
+
_instantSimulation = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(request, options) {
|
|
745
1125
|
var _options$stxerApi;
|
|
746
|
-
var apiEndpoint, response
|
|
747
|
-
return _regenerator().w(function (
|
|
748
|
-
while (1) switch (
|
|
1126
|
+
var apiEndpoint, response;
|
|
1127
|
+
return _regenerator().w(function (_context2) {
|
|
1128
|
+
while (1) switch (_context2.n) {
|
|
749
1129
|
case 0:
|
|
750
1130
|
if (options === void 0) {
|
|
751
1131
|
options = {};
|
|
752
1132
|
}
|
|
753
1133
|
apiEndpoint = (_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API$1;
|
|
754
|
-
|
|
755
|
-
return fetch(apiEndpoint + "/devtools/v2/
|
|
1134
|
+
_context2.n = 1;
|
|
1135
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations:instant", {
|
|
756
1136
|
method: 'POST',
|
|
757
1137
|
body: JSON.stringify(request),
|
|
758
1138
|
headers: {
|
|
@@ -761,24 +1141,21 @@ function _instantSimulation() {
|
|
|
761
1141
|
}
|
|
762
1142
|
});
|
|
763
1143
|
case 1:
|
|
764
|
-
response =
|
|
1144
|
+
response = _context2.v;
|
|
765
1145
|
if (response.ok) {
|
|
766
|
-
|
|
1146
|
+
_context2.n = 2;
|
|
767
1147
|
break;
|
|
768
1148
|
}
|
|
769
|
-
|
|
770
|
-
return response
|
|
1149
|
+
_context2.n = 2;
|
|
1150
|
+
return throwSimulationError('Instant simulation failed', response);
|
|
771
1151
|
case 2:
|
|
772
|
-
|
|
773
|
-
throw new Error("Instant simulation failed: " + text);
|
|
774
|
-
case 3:
|
|
775
|
-
return _context.a(2, response.json());
|
|
1152
|
+
return _context2.a(2, response.json());
|
|
776
1153
|
}
|
|
777
|
-
},
|
|
1154
|
+
}, _callee2);
|
|
778
1155
|
}));
|
|
779
1156
|
return _instantSimulation.apply(this, arguments);
|
|
780
1157
|
}
|
|
781
|
-
function createSimulationSession(
|
|
1158
|
+
function createSimulationSession(_x5, _x6) {
|
|
782
1159
|
return _createSimulationSession.apply(this, arguments);
|
|
783
1160
|
}
|
|
784
1161
|
/**
|
|
@@ -805,11 +1182,11 @@ function createSimulationSession(_x3, _x4) {
|
|
|
805
1182
|
* ```
|
|
806
1183
|
*/
|
|
807
1184
|
function _createSimulationSession() {
|
|
808
|
-
_createSimulationSession = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1185
|
+
_createSimulationSession = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options, apiOptions) {
|
|
809
1186
|
var _apiOptions$stxerApi;
|
|
810
|
-
var apiEndpoint, response,
|
|
811
|
-
return _regenerator().w(function (
|
|
812
|
-
while (1) switch (
|
|
1187
|
+
var apiEndpoint, response, result;
|
|
1188
|
+
return _regenerator().w(function (_context3) {
|
|
1189
|
+
while (1) switch (_context3.n) {
|
|
813
1190
|
case 0:
|
|
814
1191
|
if (options === void 0) {
|
|
815
1192
|
options = {};
|
|
@@ -818,7 +1195,7 @@ function _createSimulationSession() {
|
|
|
818
1195
|
apiOptions = {};
|
|
819
1196
|
}
|
|
820
1197
|
apiEndpoint = (_apiOptions$stxerApi = apiOptions.stxerApi) != null ? _apiOptions$stxerApi : DEFAULT_STXER_API$1;
|
|
821
|
-
|
|
1198
|
+
_context3.n = 1;
|
|
822
1199
|
return fetch(apiEndpoint + "/devtools/v2/simulations", {
|
|
823
1200
|
method: 'POST',
|
|
824
1201
|
body: JSON.stringify(options),
|
|
@@ -828,28 +1205,25 @@ function _createSimulationSession() {
|
|
|
828
1205
|
}
|
|
829
1206
|
});
|
|
830
1207
|
case 1:
|
|
831
|
-
response =
|
|
1208
|
+
response = _context3.v;
|
|
832
1209
|
if (response.ok) {
|
|
833
|
-
|
|
1210
|
+
_context3.n = 2;
|
|
834
1211
|
break;
|
|
835
1212
|
}
|
|
836
|
-
|
|
837
|
-
return response
|
|
1213
|
+
_context3.n = 2;
|
|
1214
|
+
return throwSimulationError('Failed to create simulation session', response);
|
|
838
1215
|
case 2:
|
|
839
|
-
|
|
840
|
-
throw new Error("Failed to create simulation session: " + text);
|
|
841
|
-
case 3:
|
|
842
|
-
_context2.n = 4;
|
|
1216
|
+
_context3.n = 3;
|
|
843
1217
|
return response.json();
|
|
844
|
-
case
|
|
845
|
-
result =
|
|
846
|
-
return
|
|
1218
|
+
case 3:
|
|
1219
|
+
result = _context3.v;
|
|
1220
|
+
return _context3.a(2, result.id);
|
|
847
1221
|
}
|
|
848
|
-
},
|
|
1222
|
+
}, _callee3);
|
|
849
1223
|
}));
|
|
850
1224
|
return _createSimulationSession.apply(this, arguments);
|
|
851
1225
|
}
|
|
852
|
-
function submitSimulationSteps(
|
|
1226
|
+
function submitSimulationSteps(_x7, _x8, _x9) {
|
|
853
1227
|
return _submitSimulationSteps.apply(this, arguments);
|
|
854
1228
|
}
|
|
855
1229
|
/**
|
|
@@ -871,17 +1245,17 @@ function submitSimulationSteps(_x5, _x6, _x7) {
|
|
|
871
1245
|
* ```
|
|
872
1246
|
*/
|
|
873
1247
|
function _submitSimulationSteps() {
|
|
874
|
-
_submitSimulationSteps = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
1248
|
+
_submitSimulationSteps = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(sessionId, request, options) {
|
|
875
1249
|
var _options$stxerApi2;
|
|
876
|
-
var apiEndpoint, response
|
|
877
|
-
return _regenerator().w(function (
|
|
878
|
-
while (1) switch (
|
|
1250
|
+
var apiEndpoint, response;
|
|
1251
|
+
return _regenerator().w(function (_context4) {
|
|
1252
|
+
while (1) switch (_context4.n) {
|
|
879
1253
|
case 0:
|
|
880
1254
|
if (options === void 0) {
|
|
881
1255
|
options = {};
|
|
882
1256
|
}
|
|
883
1257
|
apiEndpoint = (_options$stxerApi2 = options.stxerApi) != null ? _options$stxerApi2 : DEFAULT_STXER_API$1;
|
|
884
|
-
|
|
1258
|
+
_context4.n = 1;
|
|
885
1259
|
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
|
|
886
1260
|
method: 'POST',
|
|
887
1261
|
body: JSON.stringify(request),
|
|
@@ -891,26 +1265,81 @@ function _submitSimulationSteps() {
|
|
|
891
1265
|
}
|
|
892
1266
|
});
|
|
893
1267
|
case 1:
|
|
894
|
-
response =
|
|
1268
|
+
response = _context4.v;
|
|
895
1269
|
if (response.ok) {
|
|
896
|
-
|
|
1270
|
+
_context4.n = 2;
|
|
897
1271
|
break;
|
|
898
1272
|
}
|
|
899
|
-
|
|
900
|
-
return response
|
|
1273
|
+
_context4.n = 2;
|
|
1274
|
+
return throwSimulationError('Failed to submit simulation steps', response);
|
|
901
1275
|
case 2:
|
|
902
|
-
|
|
903
|
-
throw new Error("Failed to submit simulation steps: " + text);
|
|
904
|
-
case 3:
|
|
905
|
-
return _context3.a(2, response.json());
|
|
1276
|
+
return _context4.a(2, response.json());
|
|
906
1277
|
}
|
|
907
|
-
},
|
|
1278
|
+
}, _callee4);
|
|
908
1279
|
}));
|
|
909
1280
|
return _submitSimulationSteps.apply(this, arguments);
|
|
910
1281
|
}
|
|
911
|
-
function getSimulationResult(
|
|
1282
|
+
function getSimulationResult(_x0, _x1) {
|
|
912
1283
|
return _getSimulationResult.apply(this, arguments);
|
|
913
1284
|
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Get the current tip of a simulation session.
|
|
1287
|
+
*
|
|
1288
|
+
* Returns the latest synthetic tip when at least one `AdvanceBlocks`
|
|
1289
|
+
* step has run (`synthetic: true`, includes `vrf_seed` and
|
|
1290
|
+
* `tenure_change`). Returns the parent metadata pinned at session
|
|
1291
|
+
* start otherwise (`synthetic: false`, `vrf_seed` and `tenure_change`
|
|
1292
|
+
* omitted).
|
|
1293
|
+
*
|
|
1294
|
+
* Backed by `GET /devtools/v2/simulations/{id}/tip`. Older simulator
|
|
1295
|
+
* builds that predate this route respond 404.
|
|
1296
|
+
*
|
|
1297
|
+
* @example
|
|
1298
|
+
* ```typescript
|
|
1299
|
+
* import { getSimulationTip } from 'stxer';
|
|
1300
|
+
*
|
|
1301
|
+
* const tip = await getSimulationTip(sessionId);
|
|
1302
|
+
* if (tip.synthetic) {
|
|
1303
|
+
* console.log('synthetic tip vrf_seed:', tip.vrf_seed);
|
|
1304
|
+
* }
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
1307
|
+
function _getSimulationResult() {
|
|
1308
|
+
_getSimulationResult = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(sessionId, options) {
|
|
1309
|
+
var _options$stxerApi3;
|
|
1310
|
+
var apiEndpoint, response;
|
|
1311
|
+
return _regenerator().w(function (_context5) {
|
|
1312
|
+
while (1) switch (_context5.n) {
|
|
1313
|
+
case 0:
|
|
1314
|
+
if (options === void 0) {
|
|
1315
|
+
options = {};
|
|
1316
|
+
}
|
|
1317
|
+
apiEndpoint = (_options$stxerApi3 = options.stxerApi) != null ? _options$stxerApi3 : DEFAULT_STXER_API$1;
|
|
1318
|
+
_context5.n = 1;
|
|
1319
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
|
|
1320
|
+
method: 'GET',
|
|
1321
|
+
headers: {
|
|
1322
|
+
Accept: 'application/json'
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
case 1:
|
|
1326
|
+
response = _context5.v;
|
|
1327
|
+
if (response.ok) {
|
|
1328
|
+
_context5.n = 2;
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
_context5.n = 2;
|
|
1332
|
+
return throwSimulationError('Failed to get simulation result', response);
|
|
1333
|
+
case 2:
|
|
1334
|
+
return _context5.a(2, response.json());
|
|
1335
|
+
}
|
|
1336
|
+
}, _callee5);
|
|
1337
|
+
}));
|
|
1338
|
+
return _getSimulationResult.apply(this, arguments);
|
|
1339
|
+
}
|
|
1340
|
+
function getSimulationTip(_x10, _x11) {
|
|
1341
|
+
return _getSimulationTip.apply(this, arguments);
|
|
1342
|
+
}
|
|
914
1343
|
/**
|
|
915
1344
|
* Batch reads from a simulation session
|
|
916
1345
|
*
|
|
@@ -933,57 +1362,54 @@ function getSimulationResult(_x8, _x9) {
|
|
|
933
1362
|
* console.log(results.vars);
|
|
934
1363
|
* ```
|
|
935
1364
|
*/
|
|
936
|
-
function
|
|
937
|
-
|
|
938
|
-
var _options$
|
|
939
|
-
var apiEndpoint, response
|
|
940
|
-
return _regenerator().w(function (
|
|
941
|
-
while (1) switch (
|
|
1365
|
+
function _getSimulationTip() {
|
|
1366
|
+
_getSimulationTip = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(sessionId, options) {
|
|
1367
|
+
var _options$stxerApi4;
|
|
1368
|
+
var apiEndpoint, response;
|
|
1369
|
+
return _regenerator().w(function (_context6) {
|
|
1370
|
+
while (1) switch (_context6.n) {
|
|
942
1371
|
case 0:
|
|
943
1372
|
if (options === void 0) {
|
|
944
1373
|
options = {};
|
|
945
1374
|
}
|
|
946
|
-
apiEndpoint = (_options$
|
|
947
|
-
|
|
948
|
-
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
|
|
1375
|
+
apiEndpoint = (_options$stxerApi4 = options.stxerApi) != null ? _options$stxerApi4 : DEFAULT_STXER_API$1;
|
|
1376
|
+
_context6.n = 1;
|
|
1377
|
+
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId + "/tip", {
|
|
949
1378
|
method: 'GET',
|
|
950
1379
|
headers: {
|
|
951
1380
|
Accept: 'application/json'
|
|
952
1381
|
}
|
|
953
1382
|
});
|
|
954
1383
|
case 1:
|
|
955
|
-
response =
|
|
1384
|
+
response = _context6.v;
|
|
956
1385
|
if (response.ok) {
|
|
957
|
-
|
|
1386
|
+
_context6.n = 2;
|
|
958
1387
|
break;
|
|
959
1388
|
}
|
|
960
|
-
|
|
961
|
-
return response
|
|
1389
|
+
_context6.n = 2;
|
|
1390
|
+
return throwSimulationError('Failed to get simulation tip', response);
|
|
962
1391
|
case 2:
|
|
963
|
-
|
|
964
|
-
throw new Error("Failed to get simulation result: " + text);
|
|
965
|
-
case 3:
|
|
966
|
-
return _context4.a(2, response.json());
|
|
1392
|
+
return _context6.a(2, response.json());
|
|
967
1393
|
}
|
|
968
|
-
},
|
|
1394
|
+
}, _callee6);
|
|
969
1395
|
}));
|
|
970
|
-
return
|
|
1396
|
+
return _getSimulationTip.apply(this, arguments);
|
|
971
1397
|
}
|
|
972
|
-
function simulationBatchReads(
|
|
1398
|
+
function simulationBatchReads(_x12, _x13, _x14) {
|
|
973
1399
|
return _simulationBatchReads.apply(this, arguments);
|
|
974
1400
|
}
|
|
975
1401
|
function _simulationBatchReads() {
|
|
976
|
-
_simulationBatchReads = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
977
|
-
var _options$
|
|
978
|
-
var apiEndpoint, response
|
|
979
|
-
return _regenerator().w(function (
|
|
980
|
-
while (1) switch (
|
|
1402
|
+
_simulationBatchReads = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(sessionId, request, options) {
|
|
1403
|
+
var _options$stxerApi5;
|
|
1404
|
+
var apiEndpoint, response;
|
|
1405
|
+
return _regenerator().w(function (_context7) {
|
|
1406
|
+
while (1) switch (_context7.n) {
|
|
981
1407
|
case 0:
|
|
982
1408
|
if (options === void 0) {
|
|
983
1409
|
options = {};
|
|
984
1410
|
}
|
|
985
|
-
apiEndpoint = (_options$
|
|
986
|
-
|
|
1411
|
+
apiEndpoint = (_options$stxerApi5 = options.stxerApi) != null ? _options$stxerApi5 : DEFAULT_STXER_API$1;
|
|
1412
|
+
_context7.n = 1;
|
|
987
1413
|
return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId + "/reads", {
|
|
988
1414
|
method: 'POST',
|
|
989
1415
|
body: JSON.stringify(request),
|
|
@@ -993,24 +1419,29 @@ function _simulationBatchReads() {
|
|
|
993
1419
|
}
|
|
994
1420
|
});
|
|
995
1421
|
case 1:
|
|
996
|
-
response =
|
|
1422
|
+
response = _context7.v;
|
|
997
1423
|
if (response.ok) {
|
|
998
|
-
|
|
1424
|
+
_context7.n = 2;
|
|
999
1425
|
break;
|
|
1000
1426
|
}
|
|
1001
|
-
|
|
1002
|
-
return response
|
|
1427
|
+
_context7.n = 2;
|
|
1428
|
+
return throwSimulationError('Failed to batch reads from simulation', response);
|
|
1003
1429
|
case 2:
|
|
1004
|
-
|
|
1005
|
-
throw new Error("Failed to batch reads from simulation: " + text);
|
|
1006
|
-
case 3:
|
|
1007
|
-
return _context5.a(2, response.json());
|
|
1430
|
+
return _context7.a(2, response.json());
|
|
1008
1431
|
}
|
|
1009
|
-
},
|
|
1432
|
+
}, _callee7);
|
|
1010
1433
|
}));
|
|
1011
1434
|
return _simulationBatchReads.apply(this, arguments);
|
|
1012
1435
|
}
|
|
1013
1436
|
|
|
1437
|
+
/**
|
|
1438
|
+
* Override the spending condition's `signer` (and `hashMode`) so the
|
|
1439
|
+
* simulator treats `tx-sender` as `sender`.
|
|
1440
|
+
*
|
|
1441
|
+
* Single-sig and multi-sig flavours are both handled — the multi-sig
|
|
1442
|
+
* spending condition is rebuilt with empty signature fields because
|
|
1443
|
+
* the simulator never validates signatures.
|
|
1444
|
+
*/
|
|
1014
1445
|
function setSender(tx, sender) {
|
|
1015
1446
|
var _c32addressDecode = c32addressDecode(sender),
|
|
1016
1447
|
addressVersion = _c32addressDecode[0],
|
|
@@ -1035,9 +1466,86 @@ function setSender(tx, sender) {
|
|
|
1035
1466
|
};
|
|
1036
1467
|
break;
|
|
1037
1468
|
}
|
|
1469
|
+
default:
|
|
1470
|
+
throw new Error("unsupported address version: " + addressVersion);
|
|
1038
1471
|
}
|
|
1039
1472
|
return tx;
|
|
1040
1473
|
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Build an unsigned contract-call transaction with `sender` patched
|
|
1476
|
+
* in via {@link setSender}, then return the serialized hex (no `0x`
|
|
1477
|
+
* prefix). Drop the result directly into `{ Transaction: <hex> }`.
|
|
1478
|
+
*
|
|
1479
|
+
* @example
|
|
1480
|
+
* ```typescript
|
|
1481
|
+
* import { Cl } from '@stacks/transactions';
|
|
1482
|
+
* import { buildUnsignedContractCallHex } from 'stxer';
|
|
1483
|
+
*
|
|
1484
|
+
* const txHex = await buildUnsignedContractCallHex({
|
|
1485
|
+
* sender: 'SP3573...',
|
|
1486
|
+
* contract: 'SM3VDXK...sbtc-deposit',
|
|
1487
|
+
* functionName: 'complete-deposit-wrapper',
|
|
1488
|
+
* functionArgs: [Cl.bufferFromHex(txid), Cl.uint(0), Cl.uint(amount), ...],
|
|
1489
|
+
* nonce: 5,
|
|
1490
|
+
* });
|
|
1491
|
+
* await submitSimulationSteps(sim, { steps: [{ Transaction: txHex }] });
|
|
1492
|
+
* ```
|
|
1493
|
+
*/
|
|
1494
|
+
function buildUnsignedContractCallHex(_x) {
|
|
1495
|
+
return _buildUnsignedContractCallHex.apply(this, arguments);
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Build a `Cl.contractPrincipal` from a `"SP….name"` id string.
|
|
1499
|
+
* Trips on standard principals or malformed ids — those should use
|
|
1500
|
+
* `Cl.principal` directly.
|
|
1501
|
+
*/
|
|
1502
|
+
function _buildUnsignedContractCallHex() {
|
|
1503
|
+
_buildUnsignedContractCallHex = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(args) {
|
|
1504
|
+
var _args$fee, _args$network, _args$postConditionMo;
|
|
1505
|
+
var _args$contract$split, contractAddress, contractName, tx;
|
|
1506
|
+
return _regenerator().w(function (_context) {
|
|
1507
|
+
while (1) switch (_context.n) {
|
|
1508
|
+
case 0:
|
|
1509
|
+
_args$contract$split = args.contract.split('.'), contractAddress = _args$contract$split[0], contractName = _args$contract$split[1];
|
|
1510
|
+
if (contractName) {
|
|
1511
|
+
_context.n = 1;
|
|
1512
|
+
break;
|
|
1513
|
+
}
|
|
1514
|
+
throw new Error("bad contract id \"" + args.contract + "\" \u2014 expected SP\u2026.name");
|
|
1515
|
+
case 1:
|
|
1516
|
+
_context.n = 2;
|
|
1517
|
+
return makeUnsignedContractCall({
|
|
1518
|
+
contractAddress: contractAddress,
|
|
1519
|
+
contractName: contractName,
|
|
1520
|
+
functionName: args.functionName,
|
|
1521
|
+
functionArgs: args.functionArgs,
|
|
1522
|
+
fee: (_args$fee = args.fee) != null ? _args$fee : 1000,
|
|
1523
|
+
nonce: args.nonce,
|
|
1524
|
+
// Dummy 33-byte compressed pubkey. The simulator never validates
|
|
1525
|
+
// the signature; setSender overwrites the derived signer hash.
|
|
1526
|
+
publicKey: '0'.repeat(66),
|
|
1527
|
+
network: (_args$network = args.network) != null ? _args$network : 'mainnet',
|
|
1528
|
+
postConditionMode: (_args$postConditionMo = args.postConditionMode) != null ? _args$postConditionMo : PostConditionMode.Allow
|
|
1529
|
+
});
|
|
1530
|
+
case 2:
|
|
1531
|
+
tx = _context.v;
|
|
1532
|
+
setSender(tx, args.sender);
|
|
1533
|
+
return _context.a(2, serializeTransaction(tx));
|
|
1534
|
+
}
|
|
1535
|
+
}, _callee);
|
|
1536
|
+
}));
|
|
1537
|
+
return _buildUnsignedContractCallHex.apply(this, arguments);
|
|
1538
|
+
}
|
|
1539
|
+
function ftPrincipal(contractId) {
|
|
1540
|
+
var _contractId$split = contractId.split('.'),
|
|
1541
|
+
addr = _contractId$split[0],
|
|
1542
|
+
name = _contractId$split[1];
|
|
1543
|
+
if (!name) {
|
|
1544
|
+
throw new Error("bad contract id \"" + contractId + "\" \u2014 expected SP\u2026.name");
|
|
1545
|
+
}
|
|
1546
|
+
return Cl.contractPrincipal(addr, name);
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1041
1549
|
var SimulationBuilder = /*#__PURE__*/function () {
|
|
1042
1550
|
function SimulationBuilder(options) {
|
|
1043
1551
|
var _options$network, _options$apiEndpoint, _options$stacksNodeAP, _options$skipTracing;
|
|
@@ -1048,8 +1556,7 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
1048
1556
|
this.stacksNodeAPI = void 0;
|
|
1049
1557
|
this.network = void 0;
|
|
1050
1558
|
this.skipTracing = void 0;
|
|
1051
|
-
|
|
1052
|
-
this.block = NaN;
|
|
1559
|
+
this.block = Number.NaN;
|
|
1053
1560
|
this.sender = '';
|
|
1054
1561
|
this.steps = [];
|
|
1055
1562
|
this.network = (_options$network = options.network) != null ? _options$network : 'mainnet';
|
|
@@ -1106,7 +1613,7 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
1106
1613
|
this.steps.push(_extends({}, params, {
|
|
1107
1614
|
deployer: (_params$deployer = params.deployer) != null ? _params$deployer : this.sender,
|
|
1108
1615
|
fee: (_params$fee3 = params.fee) != null ? _params$fee3 : 0,
|
|
1109
|
-
clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : ClarityVersion.
|
|
1616
|
+
clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : ClarityVersion.Clarity5
|
|
1110
1617
|
}));
|
|
1111
1618
|
return this;
|
|
1112
1619
|
};
|
|
@@ -1137,7 +1644,7 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
1137
1644
|
type: 'SetContractCode',
|
|
1138
1645
|
contract_id: params.contract_id,
|
|
1139
1646
|
source_code: params.source_code,
|
|
1140
|
-
clarity_version: (_params$clarity_versi2 = params.clarity_version) != null ? _params$clarity_versi2 : ClarityVersion.
|
|
1647
|
+
clarity_version: (_params$clarity_versi2 = params.clarity_version) != null ? _params$clarity_versi2 : ClarityVersion.Clarity5
|
|
1141
1648
|
});
|
|
1142
1649
|
return this;
|
|
1143
1650
|
};
|
|
@@ -1147,10 +1654,50 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
1147
1654
|
reads: reads
|
|
1148
1655
|
});
|
|
1149
1656
|
return this;
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Add a `TenureExtend` step. Defaults to `cause: 'Extended'` (full
|
|
1660
|
+
* cost reset) — equivalent in server-side behavior to the legacy
|
|
1661
|
+
* zero-arg call.
|
|
1662
|
+
*
|
|
1663
|
+
* Pass an explicit `TenureExtendCause` to reset only one SIP-034
|
|
1664
|
+
* dimension (`ExtendedRuntime` / `ExtendedReadCount` / etc.).
|
|
1665
|
+
*
|
|
1666
|
+
* On the wire SDK 0.8.0 emits the modern `{ TenureExtend: { cause } }`
|
|
1667
|
+
* shape. The server still parses the legacy `[]` shape for any
|
|
1668
|
+
* caller emitting raw step objects.
|
|
1669
|
+
*/;
|
|
1670
|
+
_proto.addTenureExtend = function addTenureExtend(cause) {
|
|
1671
|
+
if (cause === void 0) {
|
|
1672
|
+
cause = 'Extended';
|
|
1673
|
+
}
|
|
1674
|
+
this.steps.push({
|
|
1675
|
+
type: 'TenureExtend',
|
|
1676
|
+
cause: cause
|
|
1677
|
+
});
|
|
1678
|
+
return this;
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* Synthesize bitcoin and stacks blocks on top of the simulation's
|
|
1682
|
+
* pinned parent tip. Used to model burn-block / tenure boundaries
|
|
1683
|
+
* (bridge contracts, time-locked redemptions, locked-STX unlock).
|
|
1684
|
+
*
|
|
1685
|
+
* The simulator validates the request shape; older simulator builds
|
|
1686
|
+
* that don't yet support `AdvanceBlocks` reject this variant with
|
|
1687
|
+
* HTTP 400.
|
|
1688
|
+
*
|
|
1689
|
+
* @example
|
|
1690
|
+
* ```typescript
|
|
1691
|
+
* builder.addAdvanceBlocks({
|
|
1692
|
+
* bitcoin_blocks: 1,
|
|
1693
|
+
* stacks_blocks_per_bitcoin: 1,
|
|
1694
|
+
* });
|
|
1695
|
+
* ```
|
|
1696
|
+
*/;
|
|
1697
|
+
_proto.addAdvanceBlocks = function addAdvanceBlocks(request) {
|
|
1152
1698
|
this.steps.push({
|
|
1153
|
-
type: '
|
|
1699
|
+
type: 'AdvanceBlocks',
|
|
1700
|
+
request: request
|
|
1154
1701
|
});
|
|
1155
1702
|
return this;
|
|
1156
1703
|
};
|
|
@@ -1365,9 +1912,17 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
1365
1912
|
Reads: step.reads
|
|
1366
1913
|
});
|
|
1367
1914
|
} else if (step.type === 'TenureExtend') {
|
|
1368
|
-
// TenureExtend -
|
|
1915
|
+
// TenureExtend - modern wire shape (legacy `[]` is still parsed
|
|
1916
|
+
// server-side for direct-emit consumers, but the builder always
|
|
1917
|
+
// emits the explicit cause).
|
|
1369
1918
|
v2Steps.push({
|
|
1370
|
-
TenureExtend:
|
|
1919
|
+
TenureExtend: {
|
|
1920
|
+
cause: step.cause
|
|
1921
|
+
}
|
|
1922
|
+
});
|
|
1923
|
+
} else if (step.type === 'AdvanceBlocks') {
|
|
1924
|
+
v2Steps.push({
|
|
1925
|
+
AdvanceBlocks: step.request
|
|
1371
1926
|
});
|
|
1372
1927
|
} else {
|
|
1373
1928
|
console.log("Invalid simulation step: " + step);
|
|
@@ -1408,12 +1963,6 @@ var SimulationBuilder = /*#__PURE__*/function () {
|
|
|
1408
1963
|
};
|
|
1409
1964
|
return SimulationBuilder;
|
|
1410
1965
|
}();
|
|
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
1966
|
// Helper function to convert ClarityVersion to number
|
|
1418
1967
|
function clarityVersionToNumber(version) {
|
|
1419
1968
|
switch (version) {
|
|
@@ -1425,10 +1974,242 @@ function clarityVersionToNumber(version) {
|
|
|
1425
1974
|
return 3;
|
|
1426
1975
|
case ClarityVersion.Clarity4:
|
|
1427
1976
|
return 4;
|
|
1977
|
+
case ClarityVersion.Clarity5:
|
|
1978
|
+
return 5;
|
|
1428
1979
|
default:
|
|
1429
|
-
return
|
|
1980
|
+
return 5;
|
|
1430
1981
|
}
|
|
1431
1982
|
}
|
|
1983
|
+
/**
|
|
1984
|
+
* Build, submit, and decode a contract-call transaction. The caller
|
|
1985
|
+
* supplies the principal to use as `tx-sender`; nonce is auto-fetched
|
|
1986
|
+
* via {@link getNonce} unless `nonce` is explicitly provided.
|
|
1987
|
+
*/
|
|
1988
|
+
function callContract(_x2, _x3, _x4) {
|
|
1989
|
+
return _callContract.apply(this, arguments);
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* Read the SIP-010 / hBTC-style `(get-balance principal)` value.
|
|
1993
|
+
* Returns 0n if the read returns `(err …)`. Throws on infra failures.
|
|
1994
|
+
*/
|
|
1995
|
+
function _callContract() {
|
|
1996
|
+
_callContract = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(sessionId, args, options) {
|
|
1997
|
+
var _args$nonce;
|
|
1998
|
+
var nonce, txHex, r, step, receipt, _t, _t2;
|
|
1999
|
+
return _regenerator().w(function (_context4) {
|
|
2000
|
+
while (1) switch (_context4.n) {
|
|
2001
|
+
case 0:
|
|
2002
|
+
if (options === void 0) {
|
|
2003
|
+
options = {};
|
|
2004
|
+
}
|
|
2005
|
+
if (!((_args$nonce = args.nonce) != null)) {
|
|
2006
|
+
_context4.n = 1;
|
|
2007
|
+
break;
|
|
2008
|
+
}
|
|
2009
|
+
_t = _args$nonce;
|
|
2010
|
+
_context4.n = 3;
|
|
2011
|
+
break;
|
|
2012
|
+
case 1:
|
|
2013
|
+
_t2 = Number;
|
|
2014
|
+
_context4.n = 2;
|
|
2015
|
+
return getNonce(sessionId, args.sender, options);
|
|
2016
|
+
case 2:
|
|
2017
|
+
_t = _t2(_context4.v);
|
|
2018
|
+
case 3:
|
|
2019
|
+
nonce = _t;
|
|
2020
|
+
_context4.n = 4;
|
|
2021
|
+
return buildUnsignedContractCallHex(_extends({}, args, {
|
|
2022
|
+
nonce: nonce
|
|
2023
|
+
}));
|
|
2024
|
+
case 4:
|
|
2025
|
+
txHex = _context4.v;
|
|
2026
|
+
_context4.n = 5;
|
|
2027
|
+
return submitSimulationSteps(sessionId, {
|
|
2028
|
+
steps: [{
|
|
2029
|
+
Transaction: txHex
|
|
2030
|
+
}]
|
|
2031
|
+
}, options);
|
|
2032
|
+
case 5:
|
|
2033
|
+
r = _context4.v;
|
|
2034
|
+
step = r.steps[0];
|
|
2035
|
+
if ('Transaction' in step) {
|
|
2036
|
+
_context4.n = 6;
|
|
2037
|
+
break;
|
|
2038
|
+
}
|
|
2039
|
+
throw new Error("expected Transaction step, got " + JSON.stringify(step).slice(0, 200));
|
|
2040
|
+
case 6:
|
|
2041
|
+
if (!('Err' in step.Transaction)) {
|
|
2042
|
+
_context4.n = 7;
|
|
2043
|
+
break;
|
|
2044
|
+
}
|
|
2045
|
+
throw new Error("Transaction Err: " + step.Transaction.Err);
|
|
2046
|
+
case 7:
|
|
2047
|
+
receipt = step.Transaction.Ok;
|
|
2048
|
+
return _context4.a(2, {
|
|
2049
|
+
result: cvToString(deserializeCV(receipt.result)),
|
|
2050
|
+
resultHex: receipt.result,
|
|
2051
|
+
vmError: receipt.vm_error,
|
|
2052
|
+
pcAborted: receipt.post_condition_aborted,
|
|
2053
|
+
receipt: receipt
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
}, _callee4);
|
|
2057
|
+
}));
|
|
2058
|
+
return _callContract.apply(this, arguments);
|
|
2059
|
+
}
|
|
2060
|
+
function getFtBalance(_x5, _x6, _x7, _x8) {
|
|
2061
|
+
return _getFtBalance.apply(this, arguments);
|
|
2062
|
+
}
|
|
2063
|
+
/** Read a principal's STX balance (uSTX) from a simulation session. */
|
|
2064
|
+
function _getFtBalance() {
|
|
2065
|
+
_getFtBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(sessionId, contractId, principal, options) {
|
|
2066
|
+
var _r$readonly;
|
|
2067
|
+
var r, v, decoded;
|
|
2068
|
+
return _regenerator().w(function (_context5) {
|
|
2069
|
+
while (1) switch (_context5.n) {
|
|
2070
|
+
case 0:
|
|
2071
|
+
if (options === void 0) {
|
|
2072
|
+
options = {};
|
|
2073
|
+
}
|
|
2074
|
+
_context5.n = 1;
|
|
2075
|
+
return simulationBatchReads(sessionId, {
|
|
2076
|
+
readonly: [[contractId, 'get-balance', serializeCV(Cl.principal(principal))]]
|
|
2077
|
+
}, options);
|
|
2078
|
+
case 1:
|
|
2079
|
+
r = _context5.v;
|
|
2080
|
+
v = (_r$readonly = r.readonly) == null ? void 0 : _r$readonly[0];
|
|
2081
|
+
if (!(!v || !('Ok' in v))) {
|
|
2082
|
+
_context5.n = 2;
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
throw new Error("get-balance(" + contractId + ") failed: " + JSON.stringify(v));
|
|
2086
|
+
case 2:
|
|
2087
|
+
decoded = deserializeCV(v.Ok);
|
|
2088
|
+
if (!(decoded.type === ClarityType.ResponseErr)) {
|
|
2089
|
+
_context5.n = 3;
|
|
2090
|
+
break;
|
|
2091
|
+
}
|
|
2092
|
+
return _context5.a(2, 0n);
|
|
2093
|
+
case 3:
|
|
2094
|
+
if (!(decoded.type !== ClarityType.ResponseOk)) {
|
|
2095
|
+
_context5.n = 4;
|
|
2096
|
+
break;
|
|
2097
|
+
}
|
|
2098
|
+
throw new Error("unexpected get-balance shape: " + cvToString(decoded));
|
|
2099
|
+
case 4:
|
|
2100
|
+
if (!(decoded.value.type !== ClarityType.UInt)) {
|
|
2101
|
+
_context5.n = 5;
|
|
2102
|
+
break;
|
|
2103
|
+
}
|
|
2104
|
+
throw new Error("expected uint inside (ok \u2026), got " + decoded.value.type);
|
|
2105
|
+
case 5:
|
|
2106
|
+
return _context5.a(2, BigInt(decoded.value.value));
|
|
2107
|
+
}
|
|
2108
|
+
}, _callee5);
|
|
2109
|
+
}));
|
|
2110
|
+
return _getFtBalance.apply(this, arguments);
|
|
2111
|
+
}
|
|
2112
|
+
function getStxBalance(_x9, _x0, _x1) {
|
|
2113
|
+
return _getStxBalance.apply(this, arguments);
|
|
2114
|
+
}
|
|
2115
|
+
/** Read a principal's current nonce. Returns 0n if never seen. */
|
|
2116
|
+
function _getStxBalance() {
|
|
2117
|
+
_getStxBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(sessionId, principal, options) {
|
|
2118
|
+
var _r$stx;
|
|
2119
|
+
var r, v;
|
|
2120
|
+
return _regenerator().w(function (_context6) {
|
|
2121
|
+
while (1) switch (_context6.n) {
|
|
2122
|
+
case 0:
|
|
2123
|
+
if (options === void 0) {
|
|
2124
|
+
options = {};
|
|
2125
|
+
}
|
|
2126
|
+
_context6.n = 1;
|
|
2127
|
+
return simulationBatchReads(sessionId, {
|
|
2128
|
+
stx: [principal]
|
|
2129
|
+
}, options);
|
|
2130
|
+
case 1:
|
|
2131
|
+
r = _context6.v;
|
|
2132
|
+
v = (_r$stx = r.stx) == null ? void 0 : _r$stx[0];
|
|
2133
|
+
if (!(!v || !('Ok' in v))) {
|
|
2134
|
+
_context6.n = 2;
|
|
2135
|
+
break;
|
|
2136
|
+
}
|
|
2137
|
+
throw new Error("stx balance read for " + principal + " failed");
|
|
2138
|
+
case 2:
|
|
2139
|
+
return _context6.a(2, BigInt(v.Ok));
|
|
2140
|
+
}
|
|
2141
|
+
}, _callee6);
|
|
2142
|
+
}));
|
|
2143
|
+
return _getStxBalance.apply(this, arguments);
|
|
2144
|
+
}
|
|
2145
|
+
function getNonce(_x10, _x11, _x12) {
|
|
2146
|
+
return _getNonce.apply(this, arguments);
|
|
2147
|
+
}
|
|
2148
|
+
/**
|
|
2149
|
+
* Read a Clarity data variable. Returns the decoded `ClarityValue`,
|
|
2150
|
+
* or throws if the read failed.
|
|
2151
|
+
*/
|
|
2152
|
+
function _getNonce() {
|
|
2153
|
+
_getNonce = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(sessionId, principal, options) {
|
|
2154
|
+
var _r$nonces;
|
|
2155
|
+
var r, v;
|
|
2156
|
+
return _regenerator().w(function (_context7) {
|
|
2157
|
+
while (1) switch (_context7.n) {
|
|
2158
|
+
case 0:
|
|
2159
|
+
if (options === void 0) {
|
|
2160
|
+
options = {};
|
|
2161
|
+
}
|
|
2162
|
+
_context7.n = 1;
|
|
2163
|
+
return simulationBatchReads(sessionId, {
|
|
2164
|
+
nonces: [principal]
|
|
2165
|
+
}, options);
|
|
2166
|
+
case 1:
|
|
2167
|
+
r = _context7.v;
|
|
2168
|
+
v = (_r$nonces = r.nonces) == null ? void 0 : _r$nonces[0];
|
|
2169
|
+
if (!(!v || !('Ok' in v))) {
|
|
2170
|
+
_context7.n = 2;
|
|
2171
|
+
break;
|
|
2172
|
+
}
|
|
2173
|
+
return _context7.a(2, 0n);
|
|
2174
|
+
case 2:
|
|
2175
|
+
return _context7.a(2, BigInt(v.Ok));
|
|
2176
|
+
}
|
|
2177
|
+
}, _callee7);
|
|
2178
|
+
}));
|
|
2179
|
+
return _getNonce.apply(this, arguments);
|
|
2180
|
+
}
|
|
2181
|
+
function readDataVar(_x13, _x14, _x15, _x16) {
|
|
2182
|
+
return _readDataVar.apply(this, arguments);
|
|
2183
|
+
}
|
|
2184
|
+
function _readDataVar() {
|
|
2185
|
+
_readDataVar = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(sessionId, contractId, varName, options) {
|
|
2186
|
+
var _r$vars;
|
|
2187
|
+
var r, v;
|
|
2188
|
+
return _regenerator().w(function (_context8) {
|
|
2189
|
+
while (1) switch (_context8.n) {
|
|
2190
|
+
case 0:
|
|
2191
|
+
if (options === void 0) {
|
|
2192
|
+
options = {};
|
|
2193
|
+
}
|
|
2194
|
+
_context8.n = 1;
|
|
2195
|
+
return simulationBatchReads(sessionId, {
|
|
2196
|
+
vars: [[contractId, varName]]
|
|
2197
|
+
}, options);
|
|
2198
|
+
case 1:
|
|
2199
|
+
r = _context8.v;
|
|
2200
|
+
v = (_r$vars = r.vars) == null ? void 0 : _r$vars[0];
|
|
2201
|
+
if (!(!v || !('Ok' in v))) {
|
|
2202
|
+
_context8.n = 2;
|
|
2203
|
+
break;
|
|
2204
|
+
}
|
|
2205
|
+
throw new Error("var-get " + contractId + " " + varName + " failed: " + JSON.stringify(v));
|
|
2206
|
+
case 2:
|
|
2207
|
+
return _context8.a(2, deserializeCV(v.Ok));
|
|
2208
|
+
}
|
|
2209
|
+
}, _callee8);
|
|
2210
|
+
}));
|
|
2211
|
+
return _readDataVar.apply(this, arguments);
|
|
2212
|
+
}
|
|
1432
2213
|
|
|
1433
2214
|
/**
|
|
1434
2215
|
* Fetch the current tip information from the sidecar.
|
|
@@ -1481,5 +2262,14 @@ function _getTip() {
|
|
|
1481
2262
|
return _getTip.apply(this, arguments);
|
|
1482
2263
|
}
|
|
1483
2264
|
|
|
1484
|
-
|
|
2265
|
+
/**
|
|
2266
|
+
* Type definitions for stxer-api V2 endpoints
|
|
2267
|
+
* Hand-written types based on OpenAPI spec at https://api.stxer.xyz/openapi.json
|
|
2268
|
+
*/
|
|
2269
|
+
/** Convenience parser for `TransactionReceipt.events[i]`. */
|
|
2270
|
+
function parseSimulationEvent(raw) {
|
|
2271
|
+
return JSON.parse(raw);
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
export { DEFAULT_STXER_API$1 as DEFAULT_STXER_API, STXER_API_MAINNET, STXER_API_TESTNET, SimulationBuilder, SimulationError, batchRead, buildBitcoinHeader, buildUnsignedContractCallHex, bytesToHex, callContract, callReadonly, createSimulationSession, forgeBitcoinTx, ftPrincipal, getContractAST, getFtBalance, getNonce, getSimulationResult, getSimulationTip, getStxBalance, getTip, hexToBytes, instantSimulation, merkleProof, opReturnScript, p2pkhScript, p2wpkhScript, parseContract, parseSimulationEvent, readDataVar, readMap, readVariable, setSender, sha256, sha256d, simulationBatchReads, singleTxMerkleRoot, submitSimulationSteps, verifyMerkleProof };
|
|
1485
2275
|
//# sourceMappingURL=stxer.esm.js.map
|