@secondlayer/stacks 6.2.2 → 6.3.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/dist/shared/{stacks-esm-nt5hf8ht.js → stacks-esm-z0rq3ejt.js} +44 -21
- package/dist/shared/stacks-esm-z0rq3ejt.js.map +12 -0
- package/dist/src/bitcoin/index.cjs +43 -19
- package/dist/src/bitcoin/index.cjs.map +3 -3
- package/dist/src/bitcoin/index.d.cts +13 -1
- package/dist/src/bitcoin/index.d.ts +13 -1
- package/dist/src/bitcoin/index.js +4 -2
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/pox5/index.cjs +42 -19
- package/dist/src/pox5/index.cjs.map +3 -3
- package/dist/src/pox5/index.js +1 -1
- package/package.json +1 -1
- package/dist/shared/stacks-esm-nt5hf8ht.js.map +0 -12
package/dist/src/pox5/index.cjs
CHANGED
|
@@ -5452,6 +5452,14 @@ function rootFromProof(leafInternal, proof) {
|
|
|
5452
5452
|
}
|
|
5453
5453
|
|
|
5454
5454
|
// src/bitcoin/proof.ts
|
|
5455
|
+
class BitcoinSourceError extends Error {
|
|
5456
|
+
code;
|
|
5457
|
+
name = "BitcoinSourceError";
|
|
5458
|
+
constructor(code, message) {
|
|
5459
|
+
super(message);
|
|
5460
|
+
this.code = code;
|
|
5461
|
+
}
|
|
5462
|
+
}
|
|
5455
5463
|
function normalizeTxid2(txid) {
|
|
5456
5464
|
return without0x(txid).toLowerCase();
|
|
5457
5465
|
}
|
|
@@ -5528,22 +5536,32 @@ function bitcoinRpcSource(config) {
|
|
|
5528
5536
|
const basic = typeof config.auth === "string" ? config.auth : btoa(`${config.auth.username}:${config.auth.password}`);
|
|
5529
5537
|
headers.authorization = `Basic ${basic}`;
|
|
5530
5538
|
}
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5539
|
+
let res;
|
|
5540
|
+
try {
|
|
5541
|
+
res = await doFetch(config.url, {
|
|
5542
|
+
method: "POST",
|
|
5543
|
+
headers,
|
|
5544
|
+
body: JSON.stringify({
|
|
5545
|
+
jsonrpc: "1.0",
|
|
5546
|
+
id: "secondlayer",
|
|
5547
|
+
method,
|
|
5548
|
+
params: rpcParams
|
|
5549
|
+
})
|
|
5550
|
+
});
|
|
5551
|
+
} catch (error) {
|
|
5552
|
+
throw new BitcoinSourceError("unavailable", `bitcoin rpc ${method} failed: ${error instanceof Error ? error.message : "network error"}`);
|
|
5553
|
+
}
|
|
5554
|
+
let json;
|
|
5555
|
+
try {
|
|
5556
|
+
json = await res.json();
|
|
5557
|
+
} catch {
|
|
5558
|
+
throw new BitcoinSourceError("unavailable", `bitcoin rpc ${method} failed: HTTP ${res.status}`);
|
|
5543
5559
|
}
|
|
5544
|
-
const json = await res.json();
|
|
5545
5560
|
if (json.error) {
|
|
5546
|
-
throw new
|
|
5561
|
+
throw new BitcoinSourceError(json.error.code === -5 ? "not-found" : "unavailable", `bitcoin rpc ${method} error: ${json.error.message}`);
|
|
5562
|
+
}
|
|
5563
|
+
if (!res.ok) {
|
|
5564
|
+
throw new BitcoinSourceError("unavailable", `bitcoin rpc ${method} failed: HTTP ${res.status}`);
|
|
5547
5565
|
}
|
|
5548
5566
|
return json.result;
|
|
5549
5567
|
}
|
|
@@ -5557,7 +5575,7 @@ function bitcoinRpcSource(config) {
|
|
|
5557
5575
|
true
|
|
5558
5576
|
]);
|
|
5559
5577
|
if (!tx.blockhash) {
|
|
5560
|
-
throw new
|
|
5578
|
+
throw new BitcoinSourceError("unconfirmed", `tx ${txid} is not in a block (node needs -txindex, or the tx is unconfirmed)`);
|
|
5561
5579
|
}
|
|
5562
5580
|
const block = await rpc("getblock", [
|
|
5563
5581
|
tx.blockhash,
|
|
@@ -5578,9 +5596,14 @@ function esploraSource(config) {
|
|
|
5578
5596
|
const doFetch = config.fetch ?? fetch;
|
|
5579
5597
|
const base = config.url.replace(/\/+$/, "");
|
|
5580
5598
|
async function get(path) {
|
|
5581
|
-
|
|
5599
|
+
let res;
|
|
5600
|
+
try {
|
|
5601
|
+
res = await doFetch(`${base}${path}`);
|
|
5602
|
+
} catch (error) {
|
|
5603
|
+
throw new BitcoinSourceError("unavailable", `esplora GET ${path} failed: ${error instanceof Error ? error.message : "network error"}`);
|
|
5604
|
+
}
|
|
5582
5605
|
if (!res.ok) {
|
|
5583
|
-
throw new
|
|
5606
|
+
throw new BitcoinSourceError(res.status === 404 ? "not-found" : "unavailable", `esplora GET ${path} failed: HTTP ${res.status}`);
|
|
5584
5607
|
}
|
|
5585
5608
|
return res;
|
|
5586
5609
|
}
|
|
@@ -5591,7 +5614,7 @@ function esploraSource(config) {
|
|
|
5591
5614
|
async getBlockForTx(txid) {
|
|
5592
5615
|
const status = await (await get(`/tx/${txid}`)).json();
|
|
5593
5616
|
if (!status.status.confirmed) {
|
|
5594
|
-
throw new
|
|
5617
|
+
throw new BitcoinSourceError("unconfirmed", `tx ${txid} is unconfirmed`);
|
|
5595
5618
|
}
|
|
5596
5619
|
const blockHashHex = status.status.block_hash;
|
|
5597
5620
|
const header = (await (await get(`/block/${blockHashHex}/header`)).text()).trim();
|
|
@@ -6137,5 +6160,5 @@ function parseSignerCalldata(calldata) {
|
|
|
6137
6160
|
};
|
|
6138
6161
|
}
|
|
6139
6162
|
|
|
6140
|
-
//# debugId=
|
|
6163
|
+
//# debugId=B8DD8E4772B8284D64756E2164756E21
|
|
6141
6164
|
//# sourceMappingURL=index.cjs.map
|