@secondlayer/stacks 2.12.0 → 2.14.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 +23 -0
- package/dist/shared/stacks-0cdm20eh.js +225 -0
- package/dist/shared/stacks-0cdm20eh.js.map +11 -0
- package/dist/shared/{stacks-y5epf0sb.cjs → stacks-6mhsf8hk.cjs} +52 -2
- package/dist/shared/{stacks-y5epf0sb.cjs.map → stacks-6mhsf8hk.cjs.map} +10 -5
- package/dist/shared/stacks-8khy9v27.cjs +7 -0
- package/dist/shared/stacks-8khy9v27.cjs.map +10 -0
- package/dist/shared/{stacks-kjg7fw4y.js → stacks-8rhjj23w.cjs} +40 -25
- package/dist/shared/{stacks-esn3wcw5.cjs.map → stacks-8rhjj23w.cjs.map} +7 -6
- package/dist/shared/stacks-bnbdqznq.cjs +211 -0
- package/dist/shared/stacks-bnbdqznq.cjs.map +11 -0
- package/dist/shared/{stacks-01pbr7gf.js → stacks-cqp2dgmc.js} +9 -3
- package/dist/shared/{stacks-01pbr7gf.js.map → stacks-cqp2dgmc.js.map} +3 -3
- package/dist/shared/stacks-fh48neva.js +13 -0
- package/dist/shared/stacks-fh48neva.js.map +10 -0
- package/dist/shared/{stacks-tbv5p6pn.cjs → stacks-fjrpnkt3.cjs} +5 -2
- package/dist/shared/{stacks-tbv5p6pn.cjs.map → stacks-fjrpnkt3.cjs.map} +3 -3
- package/dist/shared/{stacks-esn3wcw5.cjs → stacks-gh52j903.js} +61 -7
- package/dist/shared/{stacks-kjg7fw4y.js.map → stacks-gh52j903.js.map} +7 -6
- package/dist/shared/{stacks-59xy6t1p.js → stacks-hjaqtgaq.js} +58 -4
- package/dist/shared/{stacks-59xy6t1p.js.map → stacks-hjaqtgaq.js.map} +10 -5
- package/dist/shared/{stacks-g67f4w1d.js → stacks-hpcbn81g.js} +2 -2
- package/dist/shared/{stacks-6n2m9hyk.js → stacks-zzbkta7h.js} +3 -3
- package/dist/src/accounts/index.cjs +28 -1
- package/dist/src/accounts/index.cjs.map +4 -3
- package/dist/src/accounts/index.d.cts +23 -1
- package/dist/src/accounts/index.d.ts +23 -1
- package/dist/src/accounts/index.js +33 -1
- package/dist/src/accounts/index.js.map +4 -3
- package/dist/src/actions/index.cjs +6 -1
- package/dist/src/actions/index.cjs.map +1 -1
- package/dist/src/actions/index.d.cts +71 -1
- package/dist/src/actions/index.d.ts +71 -1
- package/dist/src/actions/index.js +17 -6
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.cjs +5 -176
- package/dist/src/bitcoin/index.cjs.map +5 -7
- package/dist/src/bitcoin/index.d.cts +18 -2
- package/dist/src/bitcoin/index.d.ts +18 -2
- package/dist/src/bitcoin/index.js +23 -182
- package/dist/src/bitcoin/index.js.map +5 -7
- package/dist/src/bns/index.cjs +9 -5
- package/dist/src/bns/index.cjs.map +3 -3
- package/dist/src/bns/index.js +13 -8
- package/dist/src/bns/index.js.map +3 -3
- package/dist/src/index.cjs +28 -8
- package/dist/src/index.cjs.map +4 -4
- package/dist/src/index.d.cts +53 -0
- package/dist/src/index.d.ts +53 -0
- package/dist/src/index.js +39 -12
- package/dist/src/index.js.map +4 -4
- package/dist/src/pox/index.js +5 -4
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/sbtc/index.cjs +49 -7
- package/dist/src/sbtc/index.cjs.map +6 -6
- package/dist/src/sbtc/index.d.cts +8 -2
- package/dist/src/sbtc/index.d.ts +8 -2
- package/dist/src/sbtc/index.js +57 -10
- package/dist/src/sbtc/index.js.map +6 -6
- package/dist/src/stackingdao/index.js +5 -4
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/tools/index.cjs +213 -116
- package/dist/src/tools/index.cjs.map +22 -15
- package/dist/src/tools/index.js +213 -116
- package/dist/src/tools/index.js.map +22 -15
- package/dist/src/x402/index.js +4 -3
- package/dist/src/x402/index.js.map +2 -2
- package/package.json +1 -1
- /package/dist/shared/{stacks-g67f4w1d.js.map → stacks-hpcbn81g.js.map} +0 -0
- /package/dist/shared/{stacks-6n2m9hyk.js.map → stacks-zzbkta7h.js.map} +0 -0
package/dist/src/tools/index.js
CHANGED
|
@@ -619,11 +619,51 @@ async function estimateFee(client, params) {
|
|
|
619
619
|
}));
|
|
620
620
|
}
|
|
621
621
|
|
|
622
|
+
// src/actions/public/getAccountHistory.ts
|
|
623
|
+
async function getAccountHistory(client, params) {
|
|
624
|
+
const limit = Math.min(params.limit ?? 20, 50);
|
|
625
|
+
return client.request(`/extended/v2/addresses/${params.address}/transactions?limit=${limit}`, { method: "GET" });
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// src/errors/base.ts
|
|
629
|
+
class BaseError extends Error {
|
|
630
|
+
name = "StacksError";
|
|
631
|
+
shortMessage;
|
|
632
|
+
details;
|
|
633
|
+
constructor(shortMessage, options) {
|
|
634
|
+
const message = [
|
|
635
|
+
shortMessage,
|
|
636
|
+
options?.details ? `
|
|
637
|
+
${options.details}` : ""
|
|
638
|
+
].join("");
|
|
639
|
+
super(message, { cause: options?.cause });
|
|
640
|
+
this.shortMessage = shortMessage;
|
|
641
|
+
this.details = options?.details;
|
|
642
|
+
}
|
|
643
|
+
toJSON() {
|
|
644
|
+
return {
|
|
645
|
+
name: this.name,
|
|
646
|
+
message: this.message,
|
|
647
|
+
shortMessage: this.shortMessage,
|
|
648
|
+
details: this.details,
|
|
649
|
+
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// src/errors/response.ts
|
|
655
|
+
class MalformedResponseError extends BaseError {
|
|
656
|
+
name = "MalformedResponseError";
|
|
657
|
+
}
|
|
658
|
+
|
|
622
659
|
// src/actions/public/getAccountInfo.ts
|
|
623
660
|
async function getAccountInfo(client, params) {
|
|
624
661
|
const data = await client.request(`/v2/accounts/${params.address}?proof=1`, {
|
|
625
662
|
method: "GET"
|
|
626
663
|
});
|
|
664
|
+
if (data?.balance === undefined || data?.nonce === undefined) {
|
|
665
|
+
throw new MalformedResponseError(`getAccountInfo: /v2/accounts/${params.address} response is missing "balance" or "nonce"`);
|
|
666
|
+
}
|
|
627
667
|
return {
|
|
628
668
|
balance: BigInt(data.balance),
|
|
629
669
|
nonce: BigInt(data.nonce),
|
|
@@ -637,6 +677,9 @@ async function getBalance(client, params) {
|
|
|
637
677
|
const data = await client.request(`/v2/accounts/${params.address}`, {
|
|
638
678
|
method: "GET"
|
|
639
679
|
});
|
|
680
|
+
if (data?.balance === undefined) {
|
|
681
|
+
throw new MalformedResponseError(`getBalance: /v2/accounts/${params.address} response is missing "balance"`);
|
|
682
|
+
}
|
|
640
683
|
return BigInt(data.balance);
|
|
641
684
|
}
|
|
642
685
|
|
|
@@ -658,9 +701,23 @@ async function getBlock(client, params) {
|
|
|
658
701
|
// src/actions/public/getBlockHeight.ts
|
|
659
702
|
async function getBlockHeight(client) {
|
|
660
703
|
const data = await client.request("/v2/info", { method: "GET" });
|
|
704
|
+
if (typeof data?.stacks_tip_height !== "number") {
|
|
705
|
+
throw new MalformedResponseError('getBlockHeight: /v2/info response is missing "stacks_tip_height"');
|
|
706
|
+
}
|
|
661
707
|
return data.stacks_tip_height;
|
|
662
708
|
}
|
|
663
709
|
|
|
710
|
+
// src/actions/public/getMempoolStats.ts
|
|
711
|
+
async function getMempoolStats(client) {
|
|
712
|
+
return client.request("/extended/v1/tx/mempool/stats", { method: "GET" });
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// src/actions/public/getNftHoldings.ts
|
|
716
|
+
async function getNftHoldings(client, params) {
|
|
717
|
+
const limit = Math.min(params.limit ?? 20, 50);
|
|
718
|
+
return client.request(`/extended/v1/tokens/nft/holdings?principal=${encodeURIComponent(params.address)}&limit=${limit}`, { method: "GET" });
|
|
719
|
+
}
|
|
720
|
+
|
|
664
721
|
// src/utils/bytes-reader.ts
|
|
665
722
|
class BytesReader {
|
|
666
723
|
data;
|
|
@@ -925,6 +982,82 @@ function deserializeCVBytes(input) {
|
|
|
925
982
|
return readCV(new BytesReader(bytes));
|
|
926
983
|
}
|
|
927
984
|
|
|
985
|
+
// src/errors/http.ts
|
|
986
|
+
class HttpRequestError extends BaseError {
|
|
987
|
+
name = "HttpRequestError";
|
|
988
|
+
status;
|
|
989
|
+
constructor(status, options) {
|
|
990
|
+
super(`HTTP request failed with status ${status}`, options);
|
|
991
|
+
this.status = status;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// src/actions/public/txSources.ts
|
|
996
|
+
function normalizeTxid(txid) {
|
|
997
|
+
return txid.startsWith("0x") ? txid : `0x${txid}`;
|
|
998
|
+
}
|
|
999
|
+
function decodeResultHex(hex) {
|
|
1000
|
+
if (!hex)
|
|
1001
|
+
return {};
|
|
1002
|
+
try {
|
|
1003
|
+
return { result: deserializeCVBytes(hex), resultHex: hex };
|
|
1004
|
+
} catch {
|
|
1005
|
+
return { resultHex: hex };
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
function normalizeStatus(txStatus) {
|
|
1009
|
+
switch (txStatus) {
|
|
1010
|
+
case "pending":
|
|
1011
|
+
case "success":
|
|
1012
|
+
case "abort_by_response":
|
|
1013
|
+
case "abort_by_post_condition":
|
|
1014
|
+
return txStatus;
|
|
1015
|
+
default:
|
|
1016
|
+
return txStatus.startsWith("dropped") ? "dropped" : undefined;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
function extendedApiSource() {
|
|
1020
|
+
return {
|
|
1021
|
+
async get({ client, txid }) {
|
|
1022
|
+
let data;
|
|
1023
|
+
try {
|
|
1024
|
+
data = await client.request(`/extended/v1/tx/${normalizeTxid(txid)}`, {
|
|
1025
|
+
method: "GET"
|
|
1026
|
+
});
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
if (error instanceof HttpRequestError && error.status === 404) {
|
|
1029
|
+
return { receipt: null };
|
|
1030
|
+
}
|
|
1031
|
+
throw error;
|
|
1032
|
+
}
|
|
1033
|
+
const txStatus = typeof data?.tx_status === "string" ? data.tx_status : undefined;
|
|
1034
|
+
if (!txStatus)
|
|
1035
|
+
return { receipt: null };
|
|
1036
|
+
const status = normalizeStatus(txStatus);
|
|
1037
|
+
if (!status)
|
|
1038
|
+
return { receipt: null };
|
|
1039
|
+
return {
|
|
1040
|
+
receipt: {
|
|
1041
|
+
txid: normalizeTxid(txid),
|
|
1042
|
+
status,
|
|
1043
|
+
blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
|
|
1044
|
+
blockHash: data.block_hash ?? undefined,
|
|
1045
|
+
...decodeResultHex(data.tx_result?.hex),
|
|
1046
|
+
events: Array.isArray(data.events) ? data.events : [],
|
|
1047
|
+
raw: data
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
// src/actions/public/getTransaction.ts
|
|
1055
|
+
async function getTransaction(client, params) {
|
|
1056
|
+
const source = params.source ?? extendedApiSource();
|
|
1057
|
+
const { receipt } = await source.get({ client, txid: params.txid });
|
|
1058
|
+
return receipt;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
928
1061
|
// src/actions/public/readContract.ts
|
|
929
1062
|
async function readContract(client, params) {
|
|
930
1063
|
const [address, name] = parseContractId(params.contract);
|
|
@@ -1373,6 +1506,9 @@ async function getMapEntry(client, params) {
|
|
|
1373
1506
|
method: "POST",
|
|
1374
1507
|
body: serializedKey
|
|
1375
1508
|
});
|
|
1509
|
+
if (typeof data?.data !== "string") {
|
|
1510
|
+
throw new MalformedResponseError(`getMapEntry: /v2/map_entry/${address}/${name}/${params.mapName} response is missing "data"`);
|
|
1511
|
+
}
|
|
1376
1512
|
return deserializeCVBytes(data.data);
|
|
1377
1513
|
}
|
|
1378
1514
|
|
|
@@ -1408,32 +1544,6 @@ function getTransactionId(tx) {
|
|
|
1408
1544
|
return txid(tx);
|
|
1409
1545
|
}
|
|
1410
1546
|
|
|
1411
|
-
// src/errors/base.ts
|
|
1412
|
-
class BaseError extends Error {
|
|
1413
|
-
name = "StacksError";
|
|
1414
|
-
shortMessage;
|
|
1415
|
-
details;
|
|
1416
|
-
constructor(shortMessage, options) {
|
|
1417
|
-
const message = [
|
|
1418
|
-
shortMessage,
|
|
1419
|
-
options?.details ? `
|
|
1420
|
-
${options.details}` : ""
|
|
1421
|
-
].join("");
|
|
1422
|
-
super(message, { cause: options?.cause });
|
|
1423
|
-
this.shortMessage = shortMessage;
|
|
1424
|
-
this.details = options?.details;
|
|
1425
|
-
}
|
|
1426
|
-
toJSON() {
|
|
1427
|
-
return {
|
|
1428
|
-
name: this.name,
|
|
1429
|
-
message: this.message,
|
|
1430
|
-
shortMessage: this.shortMessage,
|
|
1431
|
-
details: this.details,
|
|
1432
|
-
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
1433
|
-
};
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
1547
|
// src/errors/transaction.ts
|
|
1438
1548
|
class BroadcastError extends BaseError {
|
|
1439
1549
|
name = "BroadcastError";
|
|
@@ -1487,55 +1597,6 @@ async function getNonce(client, params) {
|
|
|
1487
1597
|
return BigInt(nonce);
|
|
1488
1598
|
}
|
|
1489
1599
|
|
|
1490
|
-
// src/actions/public/txSources.ts
|
|
1491
|
-
function normalizeTxid(txid2) {
|
|
1492
|
-
return txid2.startsWith("0x") ? txid2 : `0x${txid2}`;
|
|
1493
|
-
}
|
|
1494
|
-
function decodeResultHex(hex) {
|
|
1495
|
-
if (!hex)
|
|
1496
|
-
return {};
|
|
1497
|
-
try {
|
|
1498
|
-
return { result: deserializeCVBytes(hex), resultHex: hex };
|
|
1499
|
-
} catch {
|
|
1500
|
-
return { resultHex: hex };
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
function normalizeStatus(txStatus) {
|
|
1504
|
-
switch (txStatus) {
|
|
1505
|
-
case "pending":
|
|
1506
|
-
case "success":
|
|
1507
|
-
case "abort_by_response":
|
|
1508
|
-
case "abort_by_post_condition":
|
|
1509
|
-
return txStatus;
|
|
1510
|
-
default:
|
|
1511
|
-
return txStatus.startsWith("dropped") ? "dropped" : undefined;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
function extendedApiSource() {
|
|
1515
|
-
return {
|
|
1516
|
-
async get({ client, txid: txid2 }) {
|
|
1517
|
-
const data = await client.request(`/extended/v1/tx/${normalizeTxid(txid2)}`, { method: "GET" });
|
|
1518
|
-
const txStatus = typeof data?.tx_status === "string" ? data.tx_status : undefined;
|
|
1519
|
-
if (!txStatus)
|
|
1520
|
-
return { receipt: null };
|
|
1521
|
-
const status = normalizeStatus(txStatus);
|
|
1522
|
-
if (!status)
|
|
1523
|
-
return { receipt: null };
|
|
1524
|
-
return {
|
|
1525
|
-
receipt: {
|
|
1526
|
-
txid: normalizeTxid(txid2),
|
|
1527
|
-
status,
|
|
1528
|
-
blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
|
|
1529
|
-
blockHash: data.block_hash ?? undefined,
|
|
1530
|
-
...decodeResultHex(data.tx_result?.hex),
|
|
1531
|
-
events: Array.isArray(data.events) ? data.events : [],
|
|
1532
|
-
raw: data
|
|
1533
|
-
}
|
|
1534
|
-
};
|
|
1535
|
-
}
|
|
1536
|
-
};
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
1600
|
// src/actions/public/waitForTransactionReceipt.ts
|
|
1540
1601
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1541
1602
|
async function waitForTransactionReceipt(client, params) {
|
|
@@ -1595,10 +1656,20 @@ async function sendTransaction(client, params) {
|
|
|
1595
1656
|
if (params.attachment) {
|
|
1596
1657
|
body.attachment = typeof params.attachment === "string" ? params.attachment : bytesToHex(params.attachment);
|
|
1597
1658
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
body
|
|
1601
|
-
})
|
|
1659
|
+
let data;
|
|
1660
|
+
try {
|
|
1661
|
+
data = await client.request("/v2/transactions", { method: "POST", body });
|
|
1662
|
+
} catch (error) {
|
|
1663
|
+
if (error instanceof HttpRequestError && error.details) {
|
|
1664
|
+
try {
|
|
1665
|
+
data = JSON.parse(error.details);
|
|
1666
|
+
} catch {
|
|
1667
|
+
throw error;
|
|
1668
|
+
}
|
|
1669
|
+
} else {
|
|
1670
|
+
throw error;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1602
1673
|
if (data.error) {
|
|
1603
1674
|
throw new BroadcastError(data.reason ?? data.error, {
|
|
1604
1675
|
reason: data.reason,
|
|
@@ -2533,11 +2604,31 @@ async function getContractAbi(client, params) {
|
|
|
2533
2604
|
});
|
|
2534
2605
|
}
|
|
2535
2606
|
|
|
2536
|
-
// src/actions/public/
|
|
2537
|
-
async function
|
|
2538
|
-
const
|
|
2539
|
-
|
|
2540
|
-
|
|
2607
|
+
// src/actions/public/getContractSource.ts
|
|
2608
|
+
async function getContractSource(client, params) {
|
|
2609
|
+
const [address, name] = parseContractId(params.contract);
|
|
2610
|
+
try {
|
|
2611
|
+
const data = await client.request(`/v2/contracts/source/${address}/${name}`, { method: "GET" });
|
|
2612
|
+
return data?.source ? data : null;
|
|
2613
|
+
} catch (error) {
|
|
2614
|
+
if (error instanceof HttpRequestError && error.status === 404)
|
|
2615
|
+
return null;
|
|
2616
|
+
throw error;
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
// src/actions/public/getRawBlock.ts
|
|
2621
|
+
async function getRawBlock(client, params) {
|
|
2622
|
+
try {
|
|
2623
|
+
const data = await client.request(`/v2/blocks/${params.height}`, {
|
|
2624
|
+
method: "GET"
|
|
2625
|
+
});
|
|
2626
|
+
return data?.hash ? data : null;
|
|
2627
|
+
} catch (error) {
|
|
2628
|
+
if (error instanceof HttpRequestError && error.status === 404)
|
|
2629
|
+
return null;
|
|
2630
|
+
throw error;
|
|
2631
|
+
}
|
|
2541
2632
|
}
|
|
2542
2633
|
|
|
2543
2634
|
// src/actions/public/multicall.ts
|
|
@@ -2682,15 +2773,20 @@ function publicActions(client) {
|
|
|
2682
2773
|
getBalance: (params) => getBalance(client, params),
|
|
2683
2774
|
getAccountInfo: (params) => getAccountInfo(client, params),
|
|
2684
2775
|
getBlock: (params) => getBlock(client, params),
|
|
2776
|
+
getRawBlock: (params) => getRawBlock(client, params),
|
|
2685
2777
|
getBlockHeight: () => getBlockHeight(client),
|
|
2686
2778
|
readContract: (params) => readContract(client, params),
|
|
2687
2779
|
getContractAbi: (params) => getContractAbi(client, params),
|
|
2780
|
+
getContractSource: (params) => getContractSource(client, params),
|
|
2688
2781
|
getMapEntry: (params) => getMapEntry(client, params),
|
|
2689
2782
|
estimateFee: (params) => estimateFee(client, params),
|
|
2690
2783
|
multicall: (params) => multicall(client, params),
|
|
2691
2784
|
simulateCall: (params) => simulateCall(client, params),
|
|
2692
2785
|
simulateTransaction: (params) => simulateTransaction(client, params),
|
|
2693
2786
|
getTransaction: (params) => getTransaction(client, params),
|
|
2787
|
+
getAccountHistory: (params) => getAccountHistory(client, params),
|
|
2788
|
+
getMempoolStats: () => getMempoolStats(client),
|
|
2789
|
+
getNftHoldings: (params) => getNftHoldings(client, params),
|
|
2694
2790
|
waitForTransactionReceipt: (params) => waitForTransactionReceipt(client, params),
|
|
2695
2791
|
watchBlocks: (params) => watchBlocks(client, params),
|
|
2696
2792
|
watchMempool: (params) => watchMempool(client, params),
|
|
@@ -2714,27 +2810,42 @@ function createTransport(type, config) {
|
|
|
2714
2810
|
config
|
|
2715
2811
|
};
|
|
2716
2812
|
}
|
|
2813
|
+
function isRetryableStatus(status) {
|
|
2814
|
+
return status === 429 || status >= 500;
|
|
2815
|
+
}
|
|
2717
2816
|
async function fetchWithRetry(url, options, retryCount, retryDelay, timeout) {
|
|
2718
2817
|
let lastError;
|
|
2719
2818
|
for (let attempt = 0;attempt <= retryCount; attempt++) {
|
|
2819
|
+
let response;
|
|
2720
2820
|
try {
|
|
2721
2821
|
const controller = new AbortController;
|
|
2722
2822
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
2723
|
-
|
|
2823
|
+
response = await fetch(url, {
|
|
2724
2824
|
...options,
|
|
2725
2825
|
signal: controller.signal
|
|
2726
2826
|
});
|
|
2727
2827
|
clearTimeout(timeoutId);
|
|
2728
|
-
if (response.ok || response.status < 500) {
|
|
2729
|
-
return response;
|
|
2730
|
-
}
|
|
2731
|
-
lastError = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
2732
2828
|
} catch (error) {
|
|
2733
2829
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2830
|
+
if (attempt < retryCount) {
|
|
2831
|
+
await new Promise((r) => setTimeout(r, retryDelay * (attempt + 1)));
|
|
2832
|
+
continue;
|
|
2833
|
+
}
|
|
2834
|
+
throw lastError;
|
|
2734
2835
|
}
|
|
2735
|
-
if (
|
|
2736
|
-
|
|
2836
|
+
if (response.ok) {
|
|
2837
|
+
return response;
|
|
2737
2838
|
}
|
|
2839
|
+
const retryable = isRetryableStatus(response.status);
|
|
2840
|
+
if (!retryable || attempt === retryCount) {
|
|
2841
|
+
throw new HttpRequestError(response.status, {
|
|
2842
|
+
details: await response.text().catch(() => {
|
|
2843
|
+
return;
|
|
2844
|
+
})
|
|
2845
|
+
});
|
|
2846
|
+
}
|
|
2847
|
+
lastError = new HttpRequestError(response.status);
|
|
2848
|
+
await new Promise((r) => setTimeout(r, retryDelay * (attempt + 1)));
|
|
2738
2849
|
}
|
|
2739
2850
|
throw lastError ?? new Error("Request failed");
|
|
2740
2851
|
}
|
|
@@ -2844,31 +2955,17 @@ async function bnsResolveImpl(client, name) {
|
|
|
2844
2955
|
async function bnsReverseImpl(client, principal) {
|
|
2845
2956
|
return { name: await getPrimaryName(client, principal) };
|
|
2846
2957
|
}
|
|
2847
|
-
function hiroBase(client) {
|
|
2848
|
-
const url = client.chain?.rpcUrls.default.http[0] ?? process.env.STACKS_RPC_URL ?? "https://api.hiro.so";
|
|
2849
|
-
return url.replace(/\/$/, "");
|
|
2850
|
-
}
|
|
2851
|
-
async function hiroGet(client, path) {
|
|
2852
|
-
const res = await fetch(`${hiroBase(client)}${path}`, {
|
|
2853
|
-
headers: { Accept: "application/json" }
|
|
2854
|
-
});
|
|
2855
|
-
if (!res.ok) {
|
|
2856
|
-
throw new Error(`Hiro API ${path} → ${res.status} ${res.statusText}`);
|
|
2857
|
-
}
|
|
2858
|
-
return res.json();
|
|
2859
|
-
}
|
|
2860
2958
|
async function transactionByTxId(client, txId) {
|
|
2861
|
-
|
|
2862
|
-
return hiroGet(client, `/extended/v1/tx/${normalized}`);
|
|
2959
|
+
return getTransaction(client, { txid: txId });
|
|
2863
2960
|
}
|
|
2864
2961
|
async function accountHistory(client, principal, limit) {
|
|
2865
|
-
return
|
|
2962
|
+
return getAccountHistory(client, { address: principal, limit });
|
|
2866
2963
|
}
|
|
2867
2964
|
async function mempoolStats(client) {
|
|
2868
|
-
return
|
|
2965
|
+
return getMempoolStats(client);
|
|
2869
2966
|
}
|
|
2870
2967
|
async function nftHoldings(client, principal, limit) {
|
|
2871
|
-
return
|
|
2968
|
+
return getNftHoldings(client, { address: principal, limit });
|
|
2872
2969
|
}
|
|
2873
2970
|
function createStacksTools(client) {
|
|
2874
2971
|
return {
|
|
@@ -3005,7 +3102,7 @@ var getTransaction2 = tool({
|
|
|
3005
3102
|
inputSchema: z.object({ txId: z.string() }),
|
|
3006
3103
|
execute: ({ txId }) => transactionByTxId(getDefaultPublicClient(), txId)
|
|
3007
3104
|
});
|
|
3008
|
-
var
|
|
3105
|
+
var getAccountHistory2 = tool({
|
|
3009
3106
|
description: "Paginated transaction history for a Stacks principal (Hiro extended API).",
|
|
3010
3107
|
inputSchema: z.object({
|
|
3011
3108
|
principal: PRINCIPAL,
|
|
@@ -3013,12 +3110,12 @@ var getAccountHistory = tool({
|
|
|
3013
3110
|
}),
|
|
3014
3111
|
execute: ({ principal, limit }) => accountHistory(getDefaultPublicClient(), principal, limit)
|
|
3015
3112
|
});
|
|
3016
|
-
var
|
|
3113
|
+
var getMempoolStats2 = tool({
|
|
3017
3114
|
description: "Current mempool statistics: pending count, fee distribution, age buckets (Hiro extended API).",
|
|
3018
3115
|
inputSchema: z.object({}),
|
|
3019
3116
|
execute: () => mempoolStats(getDefaultPublicClient())
|
|
3020
3117
|
});
|
|
3021
|
-
var
|
|
3118
|
+
var getNftHoldings2 = tool({
|
|
3022
3119
|
description: "NFT holdings for a Stacks principal across all collections (Hiro extended API).",
|
|
3023
3120
|
inputSchema: z.object({
|
|
3024
3121
|
principal: PRINCIPAL,
|
|
@@ -3030,17 +3127,17 @@ export {
|
|
|
3030
3127
|
readContract2 as readContract,
|
|
3031
3128
|
getTransaction2 as getTransaction,
|
|
3032
3129
|
getStxBalance,
|
|
3033
|
-
getNftHoldings,
|
|
3034
|
-
getMempoolStats,
|
|
3130
|
+
getNftHoldings2 as getNftHoldings,
|
|
3131
|
+
getMempoolStats2 as getMempoolStats,
|
|
3035
3132
|
getBlockHeight2 as getBlockHeight,
|
|
3036
3133
|
getBlock2 as getBlock,
|
|
3037
3134
|
getAccountInfo2 as getAccountInfo,
|
|
3038
|
-
getAccountHistory,
|
|
3135
|
+
getAccountHistory2 as getAccountHistory,
|
|
3039
3136
|
estimateFee2 as estimateFee,
|
|
3040
3137
|
createStacksTools,
|
|
3041
3138
|
bnsReverse,
|
|
3042
3139
|
bnsResolve
|
|
3043
3140
|
};
|
|
3044
3141
|
|
|
3045
|
-
//# debugId=
|
|
3142
|
+
//# debugId=8FE40CC86F96048464756E2164756E21
|
|
3046
3143
|
//# sourceMappingURL=index.js.map
|