@secondlayer/stacks 2.13.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/shared/{stacks-01pbr7gf.js → stacks-3vyvtahh.js} +9 -3
- package/dist/shared/{stacks-01pbr7gf.js.map → stacks-3vyvtahh.js.map} +3 -3
- 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-esn3wcw5.cjs → stacks-dmrvk1mz.js} +61 -7
- package/dist/shared/{stacks-kjg7fw4y.js.map → stacks-dmrvk1mz.js.map} +7 -6
- package/dist/shared/{stacks-g67f4w1d.js → stacks-f66v961k.js} +2 -2
- 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-6n2m9hyk.js → stacks-hxp7v905.js} +3 -3
- package/dist/shared/{stacks-kjg7fw4y.js → stacks-jcgvn5v5.cjs} +40 -25
- package/dist/shared/{stacks-esn3wcw5.cjs.map → stacks-jcgvn5v5.cjs.map} +7 -6
- package/dist/shared/{stacks-59xy6t1p.js → stacks-tswh2xav.js} +58 -4
- package/dist/shared/{stacks-59xy6t1p.js.map → stacks-tswh2xav.js.map} +10 -5
- 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 +2 -2
- package/dist/src/bitcoin/index.cjs.map +3 -3
- package/dist/src/bitcoin/index.js +6 -2
- package/dist/src/bitcoin/index.js.map +3 -3
- 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 +30 -8
- package/dist/src/index.cjs.map +4 -4
- package/dist/src/index.d.cts +67 -1
- package/dist/src/index.d.ts +67 -1
- package/dist/src/index.js +43 -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.js +5 -4
- package/dist/src/sbtc/index.js.map +2 -2
- 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 +4 -2
- /package/dist/shared/{stacks-g67f4w1d.js.map → stacks-f66v961k.js.map} +0 -0
- /package/dist/shared/{stacks-6n2m9hyk.js.map → stacks-hxp7v905.js.map} +0 -0
package/dist/src/tools/index.cjs
CHANGED
|
@@ -43,12 +43,12 @@ __export(exports_tools, {
|
|
|
43
43
|
readContract: () => readContract2,
|
|
44
44
|
getTransaction: () => getTransaction2,
|
|
45
45
|
getStxBalance: () => getStxBalance,
|
|
46
|
-
getNftHoldings: () =>
|
|
47
|
-
getMempoolStats: () =>
|
|
46
|
+
getNftHoldings: () => getNftHoldings2,
|
|
47
|
+
getMempoolStats: () => getMempoolStats2,
|
|
48
48
|
getBlockHeight: () => getBlockHeight2,
|
|
49
49
|
getBlock: () => getBlock2,
|
|
50
50
|
getAccountInfo: () => getAccountInfo2,
|
|
51
|
-
getAccountHistory: () =>
|
|
51
|
+
getAccountHistory: () => getAccountHistory2,
|
|
52
52
|
estimateFee: () => estimateFee2,
|
|
53
53
|
createStacksTools: () => createStacksTools,
|
|
54
54
|
bnsReverse: () => bnsReverse,
|
|
@@ -672,11 +672,51 @@ async function estimateFee(client, params) {
|
|
|
672
672
|
}));
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
+
// src/actions/public/getAccountHistory.ts
|
|
676
|
+
async function getAccountHistory(client, params) {
|
|
677
|
+
const limit = Math.min(params.limit ?? 20, 50);
|
|
678
|
+
return client.request(`/extended/v2/addresses/${params.address}/transactions?limit=${limit}`, { method: "GET" });
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/errors/base.ts
|
|
682
|
+
class BaseError extends Error {
|
|
683
|
+
name = "StacksError";
|
|
684
|
+
shortMessage;
|
|
685
|
+
details;
|
|
686
|
+
constructor(shortMessage, options) {
|
|
687
|
+
const message = [
|
|
688
|
+
shortMessage,
|
|
689
|
+
options?.details ? `
|
|
690
|
+
${options.details}` : ""
|
|
691
|
+
].join("");
|
|
692
|
+
super(message, { cause: options?.cause });
|
|
693
|
+
this.shortMessage = shortMessage;
|
|
694
|
+
this.details = options?.details;
|
|
695
|
+
}
|
|
696
|
+
toJSON() {
|
|
697
|
+
return {
|
|
698
|
+
name: this.name,
|
|
699
|
+
message: this.message,
|
|
700
|
+
shortMessage: this.shortMessage,
|
|
701
|
+
details: this.details,
|
|
702
|
+
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/errors/response.ts
|
|
708
|
+
class MalformedResponseError extends BaseError {
|
|
709
|
+
name = "MalformedResponseError";
|
|
710
|
+
}
|
|
711
|
+
|
|
675
712
|
// src/actions/public/getAccountInfo.ts
|
|
676
713
|
async function getAccountInfo(client, params) {
|
|
677
714
|
const data = await client.request(`/v2/accounts/${params.address}?proof=1`, {
|
|
678
715
|
method: "GET"
|
|
679
716
|
});
|
|
717
|
+
if (data?.balance === undefined || data?.nonce === undefined) {
|
|
718
|
+
throw new MalformedResponseError(`getAccountInfo: /v2/accounts/${params.address} response is missing "balance" or "nonce"`);
|
|
719
|
+
}
|
|
680
720
|
return {
|
|
681
721
|
balance: BigInt(data.balance),
|
|
682
722
|
nonce: BigInt(data.nonce),
|
|
@@ -690,6 +730,9 @@ async function getBalance(client, params) {
|
|
|
690
730
|
const data = await client.request(`/v2/accounts/${params.address}`, {
|
|
691
731
|
method: "GET"
|
|
692
732
|
});
|
|
733
|
+
if (data?.balance === undefined) {
|
|
734
|
+
throw new MalformedResponseError(`getBalance: /v2/accounts/${params.address} response is missing "balance"`);
|
|
735
|
+
}
|
|
693
736
|
return BigInt(data.balance);
|
|
694
737
|
}
|
|
695
738
|
|
|
@@ -711,9 +754,23 @@ async function getBlock(client, params) {
|
|
|
711
754
|
// src/actions/public/getBlockHeight.ts
|
|
712
755
|
async function getBlockHeight(client) {
|
|
713
756
|
const data = await client.request("/v2/info", { method: "GET" });
|
|
757
|
+
if (typeof data?.stacks_tip_height !== "number") {
|
|
758
|
+
throw new MalformedResponseError('getBlockHeight: /v2/info response is missing "stacks_tip_height"');
|
|
759
|
+
}
|
|
714
760
|
return data.stacks_tip_height;
|
|
715
761
|
}
|
|
716
762
|
|
|
763
|
+
// src/actions/public/getMempoolStats.ts
|
|
764
|
+
async function getMempoolStats(client) {
|
|
765
|
+
return client.request("/extended/v1/tx/mempool/stats", { method: "GET" });
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/actions/public/getNftHoldings.ts
|
|
769
|
+
async function getNftHoldings(client, params) {
|
|
770
|
+
const limit = Math.min(params.limit ?? 20, 50);
|
|
771
|
+
return client.request(`/extended/v1/tokens/nft/holdings?principal=${encodeURIComponent(params.address)}&limit=${limit}`, { method: "GET" });
|
|
772
|
+
}
|
|
773
|
+
|
|
717
774
|
// src/utils/bytes-reader.ts
|
|
718
775
|
class BytesReader {
|
|
719
776
|
data;
|
|
@@ -978,6 +1035,82 @@ function deserializeCVBytes(input) {
|
|
|
978
1035
|
return readCV(new BytesReader(bytes));
|
|
979
1036
|
}
|
|
980
1037
|
|
|
1038
|
+
// src/errors/http.ts
|
|
1039
|
+
class HttpRequestError extends BaseError {
|
|
1040
|
+
name = "HttpRequestError";
|
|
1041
|
+
status;
|
|
1042
|
+
constructor(status, options) {
|
|
1043
|
+
super(`HTTP request failed with status ${status}`, options);
|
|
1044
|
+
this.status = status;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// src/actions/public/txSources.ts
|
|
1049
|
+
function normalizeTxid(txid) {
|
|
1050
|
+
return txid.startsWith("0x") ? txid : `0x${txid}`;
|
|
1051
|
+
}
|
|
1052
|
+
function decodeResultHex(hex) {
|
|
1053
|
+
if (!hex)
|
|
1054
|
+
return {};
|
|
1055
|
+
try {
|
|
1056
|
+
return { result: deserializeCVBytes(hex), resultHex: hex };
|
|
1057
|
+
} catch {
|
|
1058
|
+
return { resultHex: hex };
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function normalizeStatus(txStatus) {
|
|
1062
|
+
switch (txStatus) {
|
|
1063
|
+
case "pending":
|
|
1064
|
+
case "success":
|
|
1065
|
+
case "abort_by_response":
|
|
1066
|
+
case "abort_by_post_condition":
|
|
1067
|
+
return txStatus;
|
|
1068
|
+
default:
|
|
1069
|
+
return txStatus.startsWith("dropped") ? "dropped" : undefined;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
function extendedApiSource() {
|
|
1073
|
+
return {
|
|
1074
|
+
async get({ client, txid }) {
|
|
1075
|
+
let data;
|
|
1076
|
+
try {
|
|
1077
|
+
data = await client.request(`/extended/v1/tx/${normalizeTxid(txid)}`, {
|
|
1078
|
+
method: "GET"
|
|
1079
|
+
});
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
if (error instanceof HttpRequestError && error.status === 404) {
|
|
1082
|
+
return { receipt: null };
|
|
1083
|
+
}
|
|
1084
|
+
throw error;
|
|
1085
|
+
}
|
|
1086
|
+
const txStatus = typeof data?.tx_status === "string" ? data.tx_status : undefined;
|
|
1087
|
+
if (!txStatus)
|
|
1088
|
+
return { receipt: null };
|
|
1089
|
+
const status = normalizeStatus(txStatus);
|
|
1090
|
+
if (!status)
|
|
1091
|
+
return { receipt: null };
|
|
1092
|
+
return {
|
|
1093
|
+
receipt: {
|
|
1094
|
+
txid: normalizeTxid(txid),
|
|
1095
|
+
status,
|
|
1096
|
+
blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
|
|
1097
|
+
blockHash: data.block_hash ?? undefined,
|
|
1098
|
+
...decodeResultHex(data.tx_result?.hex),
|
|
1099
|
+
events: Array.isArray(data.events) ? data.events : [],
|
|
1100
|
+
raw: data
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// src/actions/public/getTransaction.ts
|
|
1108
|
+
async function getTransaction(client, params) {
|
|
1109
|
+
const source = params.source ?? extendedApiSource();
|
|
1110
|
+
const { receipt } = await source.get({ client, txid: params.txid });
|
|
1111
|
+
return receipt;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
981
1114
|
// src/actions/public/readContract.ts
|
|
982
1115
|
async function readContract(client, params) {
|
|
983
1116
|
const [address, name] = parseContractId(params.contract);
|
|
@@ -1423,6 +1556,9 @@ async function getMapEntry(client, params) {
|
|
|
1423
1556
|
method: "POST",
|
|
1424
1557
|
body: serializedKey
|
|
1425
1558
|
});
|
|
1559
|
+
if (typeof data?.data !== "string") {
|
|
1560
|
+
throw new MalformedResponseError(`getMapEntry: /v2/map_entry/${address}/${name}/${params.mapName} response is missing "data"`);
|
|
1561
|
+
}
|
|
1426
1562
|
return deserializeCVBytes(data.data);
|
|
1427
1563
|
}
|
|
1428
1564
|
|
|
@@ -1458,32 +1594,6 @@ function getTransactionId(tx) {
|
|
|
1458
1594
|
return txid(tx);
|
|
1459
1595
|
}
|
|
1460
1596
|
|
|
1461
|
-
// src/errors/base.ts
|
|
1462
|
-
class BaseError extends Error {
|
|
1463
|
-
name = "StacksError";
|
|
1464
|
-
shortMessage;
|
|
1465
|
-
details;
|
|
1466
|
-
constructor(shortMessage, options) {
|
|
1467
|
-
const message = [
|
|
1468
|
-
shortMessage,
|
|
1469
|
-
options?.details ? `
|
|
1470
|
-
${options.details}` : ""
|
|
1471
|
-
].join("");
|
|
1472
|
-
super(message, { cause: options?.cause });
|
|
1473
|
-
this.shortMessage = shortMessage;
|
|
1474
|
-
this.details = options?.details;
|
|
1475
|
-
}
|
|
1476
|
-
toJSON() {
|
|
1477
|
-
return {
|
|
1478
|
-
name: this.name,
|
|
1479
|
-
message: this.message,
|
|
1480
|
-
shortMessage: this.shortMessage,
|
|
1481
|
-
details: this.details,
|
|
1482
|
-
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
1483
|
-
};
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
1597
|
// src/errors/transaction.ts
|
|
1488
1598
|
class BroadcastError extends BaseError {
|
|
1489
1599
|
name = "BroadcastError";
|
|
@@ -1537,55 +1647,6 @@ async function getNonce(client, params) {
|
|
|
1537
1647
|
return BigInt(nonce);
|
|
1538
1648
|
}
|
|
1539
1649
|
|
|
1540
|
-
// src/actions/public/txSources.ts
|
|
1541
|
-
function normalizeTxid(txid2) {
|
|
1542
|
-
return txid2.startsWith("0x") ? txid2 : `0x${txid2}`;
|
|
1543
|
-
}
|
|
1544
|
-
function decodeResultHex(hex) {
|
|
1545
|
-
if (!hex)
|
|
1546
|
-
return {};
|
|
1547
|
-
try {
|
|
1548
|
-
return { result: deserializeCVBytes(hex), resultHex: hex };
|
|
1549
|
-
} catch {
|
|
1550
|
-
return { resultHex: hex };
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
function normalizeStatus(txStatus) {
|
|
1554
|
-
switch (txStatus) {
|
|
1555
|
-
case "pending":
|
|
1556
|
-
case "success":
|
|
1557
|
-
case "abort_by_response":
|
|
1558
|
-
case "abort_by_post_condition":
|
|
1559
|
-
return txStatus;
|
|
1560
|
-
default:
|
|
1561
|
-
return txStatus.startsWith("dropped") ? "dropped" : undefined;
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
function extendedApiSource() {
|
|
1565
|
-
return {
|
|
1566
|
-
async get({ client, txid: txid2 }) {
|
|
1567
|
-
const data = await client.request(`/extended/v1/tx/${normalizeTxid(txid2)}`, { method: "GET" });
|
|
1568
|
-
const txStatus = typeof data?.tx_status === "string" ? data.tx_status : undefined;
|
|
1569
|
-
if (!txStatus)
|
|
1570
|
-
return { receipt: null };
|
|
1571
|
-
const status = normalizeStatus(txStatus);
|
|
1572
|
-
if (!status)
|
|
1573
|
-
return { receipt: null };
|
|
1574
|
-
return {
|
|
1575
|
-
receipt: {
|
|
1576
|
-
txid: normalizeTxid(txid2),
|
|
1577
|
-
status,
|
|
1578
|
-
blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
|
|
1579
|
-
blockHash: data.block_hash ?? undefined,
|
|
1580
|
-
...decodeResultHex(data.tx_result?.hex),
|
|
1581
|
-
events: Array.isArray(data.events) ? data.events : [],
|
|
1582
|
-
raw: data
|
|
1583
|
-
}
|
|
1584
|
-
};
|
|
1585
|
-
}
|
|
1586
|
-
};
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
1650
|
// src/actions/public/waitForTransactionReceipt.ts
|
|
1590
1651
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1591
1652
|
async function waitForTransactionReceipt(client, params) {
|
|
@@ -1645,10 +1706,20 @@ async function sendTransaction(client, params) {
|
|
|
1645
1706
|
if (params.attachment) {
|
|
1646
1707
|
body.attachment = typeof params.attachment === "string" ? params.attachment : bytesToHex(params.attachment);
|
|
1647
1708
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
body
|
|
1651
|
-
})
|
|
1709
|
+
let data;
|
|
1710
|
+
try {
|
|
1711
|
+
data = await client.request("/v2/transactions", { method: "POST", body });
|
|
1712
|
+
} catch (error) {
|
|
1713
|
+
if (error instanceof HttpRequestError && error.details) {
|
|
1714
|
+
try {
|
|
1715
|
+
data = JSON.parse(error.details);
|
|
1716
|
+
} catch {
|
|
1717
|
+
throw error;
|
|
1718
|
+
}
|
|
1719
|
+
} else {
|
|
1720
|
+
throw error;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1652
1723
|
if (data.error) {
|
|
1653
1724
|
throw new BroadcastError(data.reason ?? data.error, {
|
|
1654
1725
|
reason: data.reason,
|
|
@@ -2583,11 +2654,31 @@ async function getContractAbi(client, params) {
|
|
|
2583
2654
|
});
|
|
2584
2655
|
}
|
|
2585
2656
|
|
|
2586
|
-
// src/actions/public/
|
|
2587
|
-
async function
|
|
2588
|
-
const
|
|
2589
|
-
|
|
2590
|
-
|
|
2657
|
+
// src/actions/public/getContractSource.ts
|
|
2658
|
+
async function getContractSource(client, params) {
|
|
2659
|
+
const [address, name] = parseContractId(params.contract);
|
|
2660
|
+
try {
|
|
2661
|
+
const data = await client.request(`/v2/contracts/source/${address}/${name}`, { method: "GET" });
|
|
2662
|
+
return data?.source ? data : null;
|
|
2663
|
+
} catch (error) {
|
|
2664
|
+
if (error instanceof HttpRequestError && error.status === 404)
|
|
2665
|
+
return null;
|
|
2666
|
+
throw error;
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2670
|
+
// src/actions/public/getRawBlock.ts
|
|
2671
|
+
async function getRawBlock(client, params) {
|
|
2672
|
+
try {
|
|
2673
|
+
const data = await client.request(`/v2/blocks/${params.height}`, {
|
|
2674
|
+
method: "GET"
|
|
2675
|
+
});
|
|
2676
|
+
return data?.hash ? data : null;
|
|
2677
|
+
} catch (error) {
|
|
2678
|
+
if (error instanceof HttpRequestError && error.status === 404)
|
|
2679
|
+
return null;
|
|
2680
|
+
throw error;
|
|
2681
|
+
}
|
|
2591
2682
|
}
|
|
2592
2683
|
|
|
2593
2684
|
// src/actions/public/multicall.ts
|
|
@@ -2732,15 +2823,20 @@ function publicActions(client) {
|
|
|
2732
2823
|
getBalance: (params) => getBalance(client, params),
|
|
2733
2824
|
getAccountInfo: (params) => getAccountInfo(client, params),
|
|
2734
2825
|
getBlock: (params) => getBlock(client, params),
|
|
2826
|
+
getRawBlock: (params) => getRawBlock(client, params),
|
|
2735
2827
|
getBlockHeight: () => getBlockHeight(client),
|
|
2736
2828
|
readContract: (params) => readContract(client, params),
|
|
2737
2829
|
getContractAbi: (params) => getContractAbi(client, params),
|
|
2830
|
+
getContractSource: (params) => getContractSource(client, params),
|
|
2738
2831
|
getMapEntry: (params) => getMapEntry(client, params),
|
|
2739
2832
|
estimateFee: (params) => estimateFee(client, params),
|
|
2740
2833
|
multicall: (params) => multicall(client, params),
|
|
2741
2834
|
simulateCall: (params) => simulateCall(client, params),
|
|
2742
2835
|
simulateTransaction: (params) => simulateTransaction(client, params),
|
|
2743
2836
|
getTransaction: (params) => getTransaction(client, params),
|
|
2837
|
+
getAccountHistory: (params) => getAccountHistory(client, params),
|
|
2838
|
+
getMempoolStats: () => getMempoolStats(client),
|
|
2839
|
+
getNftHoldings: (params) => getNftHoldings(client, params),
|
|
2744
2840
|
waitForTransactionReceipt: (params) => waitForTransactionReceipt(client, params),
|
|
2745
2841
|
watchBlocks: (params) => watchBlocks(client, params),
|
|
2746
2842
|
watchMempool: (params) => watchMempool(client, params),
|
|
@@ -2764,27 +2860,42 @@ function createTransport(type, config) {
|
|
|
2764
2860
|
config
|
|
2765
2861
|
};
|
|
2766
2862
|
}
|
|
2863
|
+
function isRetryableStatus(status) {
|
|
2864
|
+
return status === 429 || status >= 500;
|
|
2865
|
+
}
|
|
2767
2866
|
async function fetchWithRetry(url, options, retryCount, retryDelay, timeout) {
|
|
2768
2867
|
let lastError;
|
|
2769
2868
|
for (let attempt = 0;attempt <= retryCount; attempt++) {
|
|
2869
|
+
let response;
|
|
2770
2870
|
try {
|
|
2771
2871
|
const controller = new AbortController;
|
|
2772
2872
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
2773
|
-
|
|
2873
|
+
response = await fetch(url, {
|
|
2774
2874
|
...options,
|
|
2775
2875
|
signal: controller.signal
|
|
2776
2876
|
});
|
|
2777
2877
|
clearTimeout(timeoutId);
|
|
2778
|
-
if (response.ok || response.status < 500) {
|
|
2779
|
-
return response;
|
|
2780
|
-
}
|
|
2781
|
-
lastError = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
2782
2878
|
} catch (error) {
|
|
2783
2879
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2880
|
+
if (attempt < retryCount) {
|
|
2881
|
+
await new Promise((r) => setTimeout(r, retryDelay * (attempt + 1)));
|
|
2882
|
+
continue;
|
|
2883
|
+
}
|
|
2884
|
+
throw lastError;
|
|
2784
2885
|
}
|
|
2785
|
-
if (
|
|
2786
|
-
|
|
2886
|
+
if (response.ok) {
|
|
2887
|
+
return response;
|
|
2787
2888
|
}
|
|
2889
|
+
const retryable = isRetryableStatus(response.status);
|
|
2890
|
+
if (!retryable || attempt === retryCount) {
|
|
2891
|
+
throw new HttpRequestError(response.status, {
|
|
2892
|
+
details: await response.text().catch(() => {
|
|
2893
|
+
return;
|
|
2894
|
+
})
|
|
2895
|
+
});
|
|
2896
|
+
}
|
|
2897
|
+
lastError = new HttpRequestError(response.status);
|
|
2898
|
+
await new Promise((r) => setTimeout(r, retryDelay * (attempt + 1)));
|
|
2788
2899
|
}
|
|
2789
2900
|
throw lastError ?? new Error("Request failed");
|
|
2790
2901
|
}
|
|
@@ -2894,31 +3005,17 @@ async function bnsResolveImpl(client, name) {
|
|
|
2894
3005
|
async function bnsReverseImpl(client, principal) {
|
|
2895
3006
|
return { name: await getPrimaryName(client, principal) };
|
|
2896
3007
|
}
|
|
2897
|
-
function hiroBase(client) {
|
|
2898
|
-
const url = client.chain?.rpcUrls.default.http[0] ?? process.env.STACKS_RPC_URL ?? "https://api.hiro.so";
|
|
2899
|
-
return url.replace(/\/$/, "");
|
|
2900
|
-
}
|
|
2901
|
-
async function hiroGet(client, path) {
|
|
2902
|
-
const res = await fetch(`${hiroBase(client)}${path}`, {
|
|
2903
|
-
headers: { Accept: "application/json" }
|
|
2904
|
-
});
|
|
2905
|
-
if (!res.ok) {
|
|
2906
|
-
throw new Error(`Hiro API ${path} → ${res.status} ${res.statusText}`);
|
|
2907
|
-
}
|
|
2908
|
-
return res.json();
|
|
2909
|
-
}
|
|
2910
3008
|
async function transactionByTxId(client, txId) {
|
|
2911
|
-
|
|
2912
|
-
return hiroGet(client, `/extended/v1/tx/${normalized}`);
|
|
3009
|
+
return getTransaction(client, { txid: txId });
|
|
2913
3010
|
}
|
|
2914
3011
|
async function accountHistory(client, principal, limit) {
|
|
2915
|
-
return
|
|
3012
|
+
return getAccountHistory(client, { address: principal, limit });
|
|
2916
3013
|
}
|
|
2917
3014
|
async function mempoolStats(client) {
|
|
2918
|
-
return
|
|
3015
|
+
return getMempoolStats(client);
|
|
2919
3016
|
}
|
|
2920
3017
|
async function nftHoldings(client, principal, limit) {
|
|
2921
|
-
return
|
|
3018
|
+
return getNftHoldings(client, { address: principal, limit });
|
|
2922
3019
|
}
|
|
2923
3020
|
function createStacksTools(client) {
|
|
2924
3021
|
return {
|
|
@@ -3055,7 +3152,7 @@ var getTransaction2 = import_ai.tool({
|
|
|
3055
3152
|
inputSchema: import_zod.z.object({ txId: import_zod.z.string() }),
|
|
3056
3153
|
execute: ({ txId }) => transactionByTxId(getDefaultPublicClient(), txId)
|
|
3057
3154
|
});
|
|
3058
|
-
var
|
|
3155
|
+
var getAccountHistory2 = import_ai.tool({
|
|
3059
3156
|
description: "Paginated transaction history for a Stacks principal (Hiro extended API).",
|
|
3060
3157
|
inputSchema: import_zod.z.object({
|
|
3061
3158
|
principal: PRINCIPAL,
|
|
@@ -3063,12 +3160,12 @@ var getAccountHistory = import_ai.tool({
|
|
|
3063
3160
|
}),
|
|
3064
3161
|
execute: ({ principal, limit }) => accountHistory(getDefaultPublicClient(), principal, limit)
|
|
3065
3162
|
});
|
|
3066
|
-
var
|
|
3163
|
+
var getMempoolStats2 = import_ai.tool({
|
|
3067
3164
|
description: "Current mempool statistics: pending count, fee distribution, age buckets (Hiro extended API).",
|
|
3068
3165
|
inputSchema: import_zod.z.object({}),
|
|
3069
3166
|
execute: () => mempoolStats(getDefaultPublicClient())
|
|
3070
3167
|
});
|
|
3071
|
-
var
|
|
3168
|
+
var getNftHoldings2 = import_ai.tool({
|
|
3072
3169
|
description: "NFT holdings for a Stacks principal across all collections (Hiro extended API).",
|
|
3073
3170
|
inputSchema: import_zod.z.object({
|
|
3074
3171
|
principal: PRINCIPAL,
|
|
@@ -3077,5 +3174,5 @@ var getNftHoldings = import_ai.tool({
|
|
|
3077
3174
|
execute: ({ principal, limit }) => nftHoldings(getDefaultPublicClient(), principal, limit)
|
|
3078
3175
|
});
|
|
3079
3176
|
|
|
3080
|
-
//# debugId=
|
|
3177
|
+
//# debugId=726789478731037064756E2164756E21
|
|
3081
3178
|
//# sourceMappingURL=index.cjs.map
|