@secondlayer/stacks 4.3.1 → 5.0.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 +27 -11
- package/dist/shared/{stacks-gxq2pbky.js → stacks-2as26bcg.js} +10 -7
- package/dist/shared/stacks-2as26bcg.js.map +13 -0
- package/dist/shared/{stacks-bfan7ex7.js → stacks-4d7c3x27.js} +5 -5
- package/dist/shared/{stacks-bfan7ex7.js.map → stacks-4d7c3x27.js.map} +3 -3
- package/dist/shared/{stacks-709tra19.js → stacks-4hs8r4q2.js} +16 -2
- package/dist/shared/stacks-4hs8r4q2.js.map +10 -0
- package/dist/shared/{stacks-w23294am.js → stacks-51ybf135.js} +3 -3
- package/dist/shared/{stacks-0jk7vd8r.cjs → stacks-69nq48jp.js} +120 -17
- package/dist/shared/stacks-69nq48jp.js.map +15 -0
- package/dist/shared/{stacks-8pfdscq6.js → stacks-6gavarmy.js} +37 -9
- package/dist/shared/stacks-6gavarmy.js.map +12 -0
- package/dist/shared/{stacks-7wkf2rph.js → stacks-7bqkf3b0.js} +86 -71
- package/dist/shared/{stacks-7wkf2rph.js.map → stacks-7bqkf3b0.js.map} +9 -10
- package/dist/shared/{stacks-zcpvzbr0.js → stacks-8brgfvqx.js} +3 -3
- package/dist/shared/{stacks-4vzmhw3q.cjs → stacks-8vzxax5e.cjs} +13 -3
- package/dist/shared/stacks-8vzxax5e.cjs.map +10 -0
- package/dist/shared/{stacks-hnqt5rz4.js → stacks-9c1yam8b.js} +3 -3
- package/dist/shared/{stacks-bnbdqznq.cjs → stacks-bdgh9n83.cjs} +11 -10
- package/dist/shared/{stacks-bnbdqznq.cjs.map → stacks-bdgh9n83.cjs.map} +3 -3
- package/dist/shared/{stacks-fb75yew8.js → stacks-db3kwavg.cjs} +346 -138
- package/dist/shared/stacks-db3kwavg.cjs.map +23 -0
- package/dist/shared/{stacks-jpt52csy.js → stacks-e3nwm1dz.js} +14 -17
- package/dist/shared/stacks-e3nwm1dz.js.map +10 -0
- package/dist/shared/{stacks-27fmgajb.js → stacks-ga026yxz.js} +9 -9
- package/dist/shared/{stacks-27fmgajb.js.map → stacks-ga026yxz.js.map} +3 -3
- package/dist/shared/{stacks-nyaw1z2a.cjs → stacks-ggdz96r1.cjs} +4 -4
- package/dist/shared/{stacks-nyaw1z2a.cjs.map → stacks-ggdz96r1.cjs.map} +3 -3
- package/dist/shared/{stacks-08y0y0t7.js → stacks-gjz26k6b.js} +2 -2
- package/dist/shared/{stacks-x5386y2y.cjs → stacks-gza2n1zs.cjs} +5 -5
- package/dist/shared/{stacks-x5386y2y.cjs.map → stacks-gza2n1zs.cjs.map} +3 -3
- package/dist/shared/{stacks-ta1gar0b.cjs → stacks-kqn4y8kq.cjs} +7 -5
- package/dist/shared/{stacks-ta1gar0b.cjs.map → stacks-kqn4y8kq.cjs.map} +3 -3
- package/dist/shared/{stacks-ztzygy90.js → stacks-mftyrc60.js} +2 -2
- package/dist/shared/stacks-n4d8j8q3.js +801 -0
- package/dist/shared/stacks-n4d8j8q3.js.map +23 -0
- package/dist/shared/{stacks-ycbq8pf7.cjs → stacks-p337hp6m.cjs} +74 -59
- package/dist/shared/{stacks-ycbq8pf7.cjs.map → stacks-p337hp6m.cjs.map} +9 -10
- package/dist/shared/{stacks-ttdk2g2f.js → stacks-s5vej5z6.cjs} +92 -41
- package/dist/shared/stacks-s5vej5z6.cjs.map +15 -0
- package/dist/shared/stacks-sdqkapct.cjs +67 -0
- package/dist/shared/stacks-sdqkapct.cjs.map +12 -0
- package/dist/shared/{stacks-1arrcd11.js → stacks-v2rfr46a.js} +2 -2
- package/dist/shared/{stacks-9mqveyjv.cjs → stacks-w9t61fra.cjs} +7 -10
- package/dist/shared/stacks-w9t61fra.cjs.map +10 -0
- package/dist/shared/{stacks-tjjnkt3r.js → stacks-wxfd6r4b.js} +2 -2
- package/dist/shared/{stacks-4z72akdf.js → stacks-x0qqwrev.js} +3 -3
- package/dist/shared/{stacks-gck1sq7h.cjs → stacks-xjkn3en1.cjs} +16 -2
- package/dist/shared/stacks-xjkn3en1.cjs.map +10 -0
- package/dist/shared/stacks-xnrywjf1.cjs +131 -0
- package/dist/shared/stacks-xnrywjf1.cjs.map +11 -0
- package/dist/shared/stacks-yajyej2y.js +139 -0
- package/dist/shared/stacks-yajyej2y.js.map +11 -0
- package/dist/shared/{stacks-913a2rx7.js → stacks-yvb7rvwk.js} +13 -3
- package/dist/shared/stacks-yvb7rvwk.js.map +10 -0
- package/dist/shared/{stacks-0cdm20eh.js → stacks-z90xdr1x.js} +7 -11
- package/dist/shared/{stacks-0cdm20eh.js.map → stacks-z90xdr1x.js.map} +3 -3
- package/dist/src/accounts/index.js +2 -3
- package/dist/src/accounts/index.js.map +2 -2
- package/dist/src/actions/index.cjs +2 -1
- package/dist/src/actions/index.cjs.map +1 -1
- package/dist/src/actions/index.d.cts +108 -20
- package/dist/src/actions/index.d.ts +108 -20
- package/dist/src/actions/index.js +17 -15
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.d.cts +27 -0
- package/dist/src/bitcoin/index.d.ts +27 -0
- package/dist/src/bitcoin/index.js +10 -11
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/bns/index.d.cts +27 -0
- package/dist/src/bns/index.d.ts +27 -0
- package/dist/src/bns/index.js +13 -13
- package/dist/src/bns/index.js.map +1 -1
- package/dist/src/clarity/index.js +7 -6
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/connect/index.cjs +44 -30
- package/dist/src/connect/index.cjs.map +7 -7
- package/dist/src/connect/index.d.cts +16 -1
- package/dist/src/connect/index.d.ts +16 -1
- package/dist/src/connect/index.js +44 -30
- package/dist/src/connect/index.js.map +7 -7
- package/dist/src/connect/walletconnect/index.cjs +49 -413
- package/dist/src/connect/walletconnect/index.cjs.map +4 -4
- package/dist/src/connect/walletconnect/index.js +47 -411
- package/dist/src/connect/walletconnect/index.js.map +4 -4
- package/dist/src/filters/index.js +2 -2
- package/dist/src/index.cjs +49 -124
- package/dist/src/index.cjs.map +6 -8
- package/dist/src/index.d.cts +163 -54
- package/dist/src/index.d.ts +163 -54
- package/dist/src/index.js +79 -147
- package/dist/src/index.js.map +6 -8
- package/dist/src/postconditions/index.js +6 -5
- package/dist/src/postconditions/index.js.map +1 -1
- package/dist/src/pox/index.cjs +7 -83
- package/dist/src/pox/index.cjs.map +3 -3
- package/dist/src/pox/index.d.cts +32 -1
- package/dist/src/pox/index.d.ts +32 -1
- package/dist/src/pox/index.js +22 -102
- package/dist/src/pox/index.js.map +3 -3
- package/dist/src/pox5/index.cjs +4 -129
- package/dist/src/pox5/index.cjs.map +3 -4
- package/dist/src/pox5/index.d.cts +27 -0
- package/dist/src/pox5/index.d.ts +27 -0
- package/dist/src/pox5/index.js +20 -148
- package/dist/src/pox5/index.js.map +3 -4
- package/dist/src/sbtc/index.cjs +2 -59
- package/dist/src/sbtc/index.cjs.map +3 -3
- package/dist/src/sbtc/index.d.cts +30 -2
- package/dist/src/sbtc/index.d.ts +30 -2
- package/dist/src/sbtc/index.js +15 -74
- package/dist/src/sbtc/index.js.map +3 -3
- package/dist/src/stackingdao/index.d.cts +27 -0
- package/dist/src/stackingdao/index.d.ts +27 -0
- package/dist/src/stackingdao/index.js +11 -11
- package/dist/src/stackingdao/index.js.map +1 -1
- package/dist/src/subscriptions/index.d.cts +27 -0
- package/dist/src/subscriptions/index.d.ts +27 -0
- package/dist/src/subscriptions/index.js +2 -2
- package/dist/src/tools/btc/index.cjs.map +2 -2
- package/dist/src/tools/btc/index.js.map +2 -2
- package/dist/src/tools/index.cjs +629 -392
- package/dist/src/tools/index.cjs.map +30 -28
- package/dist/src/tools/index.d.cts +44 -0
- package/dist/src/tools/index.d.ts +44 -0
- package/dist/src/tools/index.js +628 -391
- package/dist/src/tools/index.js.map +30 -28
- package/dist/src/transactions/index.js +6 -5
- package/dist/src/transactions/index.js.map +1 -1
- package/dist/src/utils/index.d.cts +2 -5
- package/dist/src/utils/index.d.ts +2 -5
- package/dist/src/utils/index.js +2 -2
- package/package.json +18 -7
- package/dist/shared/stacks-0eatsx6d.cjs +0 -25
- package/dist/shared/stacks-0eatsx6d.cjs.map +0 -10
- package/dist/shared/stacks-0jk7vd8r.cjs.map +0 -14
- package/dist/shared/stacks-4vzmhw3q.cjs.map +0 -10
- package/dist/shared/stacks-5nmz5ad9.js +0 -409
- package/dist/shared/stacks-5nmz5ad9.js.map +0 -10
- package/dist/shared/stacks-709tra19.js.map +0 -10
- package/dist/shared/stacks-8pfdscq6.js.map +0 -12
- package/dist/shared/stacks-913a2rx7.js.map +0 -10
- package/dist/shared/stacks-9mqveyjv.cjs.map +0 -10
- package/dist/shared/stacks-e4xn4m7j.js +0 -27
- package/dist/shared/stacks-e4xn4m7j.js.map +0 -10
- package/dist/shared/stacks-fb75yew8.js.map +0 -21
- package/dist/shared/stacks-gck1sq7h.cjs.map +0 -10
- package/dist/shared/stacks-gxq2pbky.js.map +0 -13
- package/dist/shared/stacks-jpt52csy.js.map +0 -10
- package/dist/shared/stacks-mnnhpex3.cjs +0 -407
- package/dist/shared/stacks-mnnhpex3.cjs.map +0 -10
- package/dist/shared/stacks-tdsp5gsb.cjs +0 -527
- package/dist/shared/stacks-tdsp5gsb.cjs.map +0 -21
- package/dist/shared/stacks-ttdk2g2f.js.map +0 -14
- package/dist/shared/stacks-wdp5yr8n.cjs +0 -39
- package/dist/shared/stacks-wdp5yr8n.cjs.map +0 -12
- /package/dist/shared/{stacks-w23294am.js.map → stacks-51ybf135.js.map} +0 -0
- /package/dist/shared/{stacks-zcpvzbr0.js.map → stacks-8brgfvqx.js.map} +0 -0
- /package/dist/shared/{stacks-hnqt5rz4.js.map → stacks-9c1yam8b.js.map} +0 -0
- /package/dist/shared/{stacks-08y0y0t7.js.map → stacks-gjz26k6b.js.map} +0 -0
- /package/dist/shared/{stacks-ztzygy90.js.map → stacks-mftyrc60.js.map} +0 -0
- /package/dist/shared/{stacks-1arrcd11.js.map → stacks-v2rfr46a.js.map} +0 -0
- /package/dist/shared/{stacks-tjjnkt3r.js.map → stacks-wxfd6r4b.js.map} +0 -0
- /package/dist/shared/{stacks-4z72akdf.js.map → stacks-x0qqwrev.js.map} +0 -0
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
on
|
|
3
|
-
} from "../shared/stacks-
|
|
3
|
+
} from "../shared/stacks-gjz26k6b.js";
|
|
4
4
|
import {
|
|
5
5
|
providerToAccount
|
|
6
6
|
} from "../shared/stacks-qcae5852.js";
|
|
@@ -22,36 +22,35 @@ import {
|
|
|
22
22
|
getMempoolStats,
|
|
23
23
|
getNftHoldings,
|
|
24
24
|
getRawBlock,
|
|
25
|
-
getTransaction,
|
|
26
25
|
signMessage,
|
|
27
26
|
signTransactionAction,
|
|
28
27
|
simulateCall,
|
|
29
28
|
simulateTransaction,
|
|
30
29
|
sponsorTransaction,
|
|
31
30
|
transferStx
|
|
32
|
-
} from "../shared/stacks-
|
|
31
|
+
} from "../shared/stacks-7bqkf3b0.js";
|
|
33
32
|
import {
|
|
34
33
|
getBalance,
|
|
35
34
|
getDataVar,
|
|
36
35
|
multicall
|
|
37
|
-
} from "../shared/stacks-
|
|
36
|
+
} from "../shared/stacks-6gavarmy.js";
|
|
38
37
|
import {
|
|
39
|
-
BroadcastError,
|
|
40
38
|
HttpRequestError,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
TransactionAbortedError,
|
|
44
|
-
TransactionDroppedError,
|
|
45
|
-
TransactionError,
|
|
46
|
-
WaitForTransactionTimeoutError,
|
|
39
|
+
IndexSourceConfigError,
|
|
40
|
+
TimeoutError,
|
|
47
41
|
broadcastWithNonceReset,
|
|
42
|
+
buildRequestFn,
|
|
48
43
|
callContract,
|
|
49
44
|
createNonceManager,
|
|
45
|
+
createTransport,
|
|
50
46
|
estimateFee,
|
|
51
47
|
extendedApiSource,
|
|
52
48
|
getBlockHeight,
|
|
53
49
|
getMapEntry,
|
|
54
50
|
getNonce,
|
|
51
|
+
getTransaction,
|
|
52
|
+
indexNotFound,
|
|
53
|
+
indexRequestFn,
|
|
55
54
|
indexTxSource,
|
|
56
55
|
isNonceConflictError,
|
|
57
56
|
jsonRpcSource,
|
|
@@ -62,11 +61,11 @@ import {
|
|
|
62
61
|
setUnsignedFee,
|
|
63
62
|
startNonceReconciler,
|
|
64
63
|
waitForTransactionReceipt
|
|
65
|
-
} from "../shared/stacks-
|
|
64
|
+
} from "../shared/stacks-n4d8j8q3.js";
|
|
66
65
|
import {
|
|
67
66
|
MalformedResponseError,
|
|
68
67
|
readContract
|
|
69
|
-
} from "../shared/stacks-
|
|
68
|
+
} from "../shared/stacks-ga026yxz.js";
|
|
70
69
|
import {
|
|
71
70
|
WebSocketError,
|
|
72
71
|
watchAddress,
|
|
@@ -75,24 +74,32 @@ import {
|
|
|
75
74
|
watchMempool,
|
|
76
75
|
watchNftEvent,
|
|
77
76
|
watchTransaction
|
|
78
|
-
} from "../shared/stacks-
|
|
79
|
-
import
|
|
80
|
-
BaseError
|
|
81
|
-
} from "../shared/stacks-709tra19.js";
|
|
82
|
-
import"../shared/stacks-1arrcd11.js";
|
|
77
|
+
} from "../shared/stacks-wxfd6r4b.js";
|
|
78
|
+
import"../shared/stacks-v2rfr46a.js";
|
|
83
79
|
import {
|
|
84
80
|
buildContractCall,
|
|
85
81
|
buildContractDeploy,
|
|
86
82
|
buildTokenTransfer,
|
|
87
83
|
finalizeMultiSig,
|
|
88
84
|
makeMultiSigAddress
|
|
89
|
-
} from "../shared/stacks-
|
|
90
|
-
import"../shared/stacks-
|
|
91
|
-
import
|
|
85
|
+
} from "../shared/stacks-9c1yam8b.js";
|
|
86
|
+
import"../shared/stacks-51ybf135.js";
|
|
87
|
+
import {
|
|
88
|
+
BroadcastError,
|
|
89
|
+
SerializationError,
|
|
90
|
+
SigningError,
|
|
91
|
+
TransactionAbortedError,
|
|
92
|
+
TransactionDroppedError,
|
|
93
|
+
TransactionError,
|
|
94
|
+
WaitForTransactionTimeoutError
|
|
95
|
+
} from "../shared/stacks-69nq48jp.js";
|
|
96
|
+
import {
|
|
97
|
+
BaseError
|
|
98
|
+
} from "../shared/stacks-4hs8r4q2.js";
|
|
92
99
|
import {
|
|
93
100
|
formatStx,
|
|
94
101
|
parseStx
|
|
95
|
-
} from "../shared/stacks-
|
|
102
|
+
} from "../shared/stacks-yvb7rvwk.js";
|
|
96
103
|
import {
|
|
97
104
|
AddressVersion,
|
|
98
105
|
MICROSTX_PER_STX,
|
|
@@ -102,7 +109,7 @@ import {
|
|
|
102
109
|
isAddressEqual,
|
|
103
110
|
isValidAddress,
|
|
104
111
|
parseContractId
|
|
105
|
-
} from "../shared/stacks-
|
|
112
|
+
} from "../shared/stacks-4d7c3x27.js";
|
|
106
113
|
import"../shared/stacks-qs5fzts5.js";
|
|
107
114
|
|
|
108
115
|
// src/clients/createClient.ts
|
|
@@ -311,6 +318,9 @@ var SEED_OR_TAKE = `local v = redis.call('GET', KEYS[1])
|
|
|
311
318
|
if v == false then redis.call('SET', KEYS[1], ARGV[1]); v = ARGV[1] end
|
|
312
319
|
redis.call('INCR', KEYS[1])
|
|
313
320
|
return v`;
|
|
321
|
+
var RELEASE_IF_LATEST = `local v = redis.call('GET', KEYS[1])
|
|
322
|
+
if v ~= false and v == ARGV[1] then redis.call('SET', KEYS[1], ARGV[2]) end
|
|
323
|
+
return v`;
|
|
314
324
|
function redisStore(params) {
|
|
315
325
|
const { redis } = params;
|
|
316
326
|
const prefix = params.prefix ?? "stacks:nonce:";
|
|
@@ -332,6 +342,15 @@ function redisStore(params) {
|
|
|
332
342
|
async reset(key) {
|
|
333
343
|
await redis.send("DEL", [prefix + key]);
|
|
334
344
|
},
|
|
345
|
+
async release(key, nonce) {
|
|
346
|
+
await redis.send("EVAL", [
|
|
347
|
+
RELEASE_IF_LATEST,
|
|
348
|
+
"1",
|
|
349
|
+
prefix + key,
|
|
350
|
+
(nonce + 1n).toString(),
|
|
351
|
+
nonce.toString()
|
|
352
|
+
]);
|
|
353
|
+
},
|
|
335
354
|
async peek(key) {
|
|
336
355
|
const v = await redis.send("GET", [prefix + key]);
|
|
337
356
|
return v == null ? undefined : BigInt(v);
|
|
@@ -366,6 +385,10 @@ function postgresStore(params) {
|
|
|
366
385
|
await ensureTable();
|
|
367
386
|
await sql`DELETE FROM stacks_nonce_state WHERE key = ${key}`;
|
|
368
387
|
},
|
|
388
|
+
async release(key, nonce) {
|
|
389
|
+
await ensureTable();
|
|
390
|
+
await sql`UPDATE stacks_nonce_state SET next = ${nonce.toString()} WHERE key = ${key} AND next = ${(nonce + 1n).toString()}`;
|
|
391
|
+
},
|
|
369
392
|
async peek(key) {
|
|
370
393
|
await ensureTable();
|
|
371
394
|
const rows = await sql`SELECT next FROM stacks_nonce_state WHERE key = ${key}`;
|
|
@@ -396,7 +419,9 @@ function mempoolAwareSource(params) {
|
|
|
396
419
|
let pending = [];
|
|
397
420
|
try {
|
|
398
421
|
pending = await params.getPending({ client, address });
|
|
399
|
-
} catch {
|
|
422
|
+
} catch (error) {
|
|
423
|
+
if (error instanceof IndexSourceConfigError)
|
|
424
|
+
throw error;
|
|
400
425
|
return confirmed;
|
|
401
426
|
}
|
|
402
427
|
return nextFreeNonce(confirmed, pending);
|
|
@@ -404,28 +429,33 @@ function mempoolAwareSource(params) {
|
|
|
404
429
|
};
|
|
405
430
|
}
|
|
406
431
|
function indexSource(params = {}) {
|
|
407
|
-
const baseUrl = (params.baseUrl ?? "https://api.secondlayer.tools").replace(/\/$/, "");
|
|
408
|
-
const fetchImpl = resolveFetch(params.fetchImpl);
|
|
409
432
|
const maxPages = params.maxPages ?? 10;
|
|
410
|
-
|
|
433
|
+
const headers = params.apiKey ? { authorization: `Bearer ${params.apiKey}` } : undefined;
|
|
434
|
+
const source = mempoolAwareSource({
|
|
411
435
|
getConfirmed: params.getConfirmed,
|
|
412
|
-
async getPending({ address }) {
|
|
436
|
+
async getPending({ client, address }) {
|
|
437
|
+
const request = indexRequestFn(client, params.baseUrl, "indexSource");
|
|
413
438
|
const out = [];
|
|
414
439
|
let cursor;
|
|
415
440
|
let pages = 0;
|
|
416
441
|
do {
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
if (cursor)
|
|
421
|
-
url.searchParams.set("from_cursor", cursor);
|
|
422
|
-
const res = await fetchImpl(url, {
|
|
423
|
-
headers: params.apiKey ? { authorization: `Bearer ${params.apiKey}` } : undefined
|
|
442
|
+
const query = new URLSearchParams({
|
|
443
|
+
sender: address,
|
|
444
|
+
limit: "200"
|
|
424
445
|
});
|
|
425
|
-
if (
|
|
426
|
-
|
|
446
|
+
if (cursor)
|
|
447
|
+
query.set("from_cursor", cursor);
|
|
448
|
+
let data;
|
|
449
|
+
try {
|
|
450
|
+
data = await request(`/v1/index/mempool?${query}`, {
|
|
451
|
+
method: "GET",
|
|
452
|
+
headers
|
|
453
|
+
});
|
|
454
|
+
} catch (error) {
|
|
455
|
+
if (indexNotFound(error, "indexSource"))
|
|
456
|
+
break;
|
|
457
|
+
throw error;
|
|
427
458
|
}
|
|
428
|
-
const data = await res.json();
|
|
429
459
|
for (const tx of data.mempool ?? []) {
|
|
430
460
|
if (tx.nonce != null)
|
|
431
461
|
out.push(BigInt(tx.nonce));
|
|
@@ -433,12 +463,15 @@ function indexSource(params = {}) {
|
|
|
433
463
|
cursor = data.next_cursor ?? undefined;
|
|
434
464
|
pages += 1;
|
|
435
465
|
} while (cursor && pages < maxPages);
|
|
436
|
-
if (cursor) {
|
|
437
|
-
console.warn(`indexSource: stopped paging mempool for ${address} after ${maxPages} pages; pending set may be incomplete`);
|
|
438
|
-
}
|
|
439
466
|
return out;
|
|
440
467
|
}
|
|
441
468
|
});
|
|
469
|
+
return {
|
|
470
|
+
async get(args) {
|
|
471
|
+
indexRequestFn(args.client, params.baseUrl, "indexSource");
|
|
472
|
+
return source.get(args);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
442
475
|
}
|
|
443
476
|
function hiroNonceSource(params) {
|
|
444
477
|
const baseUrl = params.baseUrl.replace(/\/$/, "");
|
|
@@ -459,100 +492,6 @@ function hiroNonceSource(params) {
|
|
|
459
492
|
}
|
|
460
493
|
};
|
|
461
494
|
}
|
|
462
|
-
// src/transports/createTransport.ts
|
|
463
|
-
function createTransport(type, config) {
|
|
464
|
-
return {
|
|
465
|
-
type,
|
|
466
|
-
request: config.request,
|
|
467
|
-
config
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
function isRetryableStatus(status) {
|
|
471
|
-
return status === 429 || status >= 500;
|
|
472
|
-
}
|
|
473
|
-
var MAX_RETRY_AFTER_MS = 60000;
|
|
474
|
-
function retryAfterMs(response) {
|
|
475
|
-
const value = response.headers.get("Retry-After");
|
|
476
|
-
if (!value)
|
|
477
|
-
return;
|
|
478
|
-
const seconds = Number(value);
|
|
479
|
-
const ms = Number.isFinite(seconds) ? seconds * 1000 : Date.parse(value) - Date.now();
|
|
480
|
-
if (!Number.isFinite(ms) || ms < 0 || ms > MAX_RETRY_AFTER_MS)
|
|
481
|
-
return;
|
|
482
|
-
return ms;
|
|
483
|
-
}
|
|
484
|
-
async function fetchWithRetry(url, options, retryCount, retryDelay, timeout) {
|
|
485
|
-
let lastError;
|
|
486
|
-
for (let attempt = 0;attempt <= retryCount; attempt++) {
|
|
487
|
-
let response;
|
|
488
|
-
try {
|
|
489
|
-
const controller = new AbortController;
|
|
490
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
491
|
-
response = await fetch(url, {
|
|
492
|
-
...options,
|
|
493
|
-
signal: controller.signal
|
|
494
|
-
});
|
|
495
|
-
clearTimeout(timeoutId);
|
|
496
|
-
} catch (error) {
|
|
497
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
498
|
-
if (attempt < retryCount) {
|
|
499
|
-
await new Promise((r) => setTimeout(r, retryDelay * (attempt + 1)));
|
|
500
|
-
continue;
|
|
501
|
-
}
|
|
502
|
-
throw lastError;
|
|
503
|
-
}
|
|
504
|
-
if (response.ok) {
|
|
505
|
-
return response;
|
|
506
|
-
}
|
|
507
|
-
const retryable = isRetryableStatus(response.status);
|
|
508
|
-
if (!retryable || attempt === retryCount) {
|
|
509
|
-
throw new HttpRequestError(response.status, {
|
|
510
|
-
details: await response.text().catch(() => {
|
|
511
|
-
return;
|
|
512
|
-
})
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
lastError = new HttpRequestError(response.status);
|
|
516
|
-
const delay = retryAfterMs(response) ?? retryDelay * (attempt + 1);
|
|
517
|
-
await new Promise((r) => setTimeout(r, delay));
|
|
518
|
-
}
|
|
519
|
-
throw lastError ?? new Error("Request failed");
|
|
520
|
-
}
|
|
521
|
-
function buildRequestFn(baseUrl, config) {
|
|
522
|
-
const {
|
|
523
|
-
timeout = 30000,
|
|
524
|
-
retryCount = 3,
|
|
525
|
-
retryDelay = 150,
|
|
526
|
-
fetchOptions = {},
|
|
527
|
-
apiKey
|
|
528
|
-
} = config;
|
|
529
|
-
return async (path, options) => {
|
|
530
|
-
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
531
|
-
const headers = {
|
|
532
|
-
"Content-Type": "application/json",
|
|
533
|
-
...fetchOptions.headers,
|
|
534
|
-
...options?.headers
|
|
535
|
-
};
|
|
536
|
-
if (apiKey) {
|
|
537
|
-
headers["x-api-key"] = apiKey;
|
|
538
|
-
}
|
|
539
|
-
const init = {
|
|
540
|
-
...fetchOptions,
|
|
541
|
-
method: options?.method ?? "GET",
|
|
542
|
-
headers
|
|
543
|
-
};
|
|
544
|
-
if (options?.body !== undefined) {
|
|
545
|
-
init.body = JSON.stringify(options.body);
|
|
546
|
-
}
|
|
547
|
-
const response = await fetchWithRetry(url, init, retryCount, retryDelay, timeout);
|
|
548
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
549
|
-
if (contentType.includes("application/json")) {
|
|
550
|
-
return response.json();
|
|
551
|
-
}
|
|
552
|
-
return response.text();
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
|
|
556
495
|
// src/transports/http.ts
|
|
557
496
|
function http(url, config) {
|
|
558
497
|
return (params) => {
|
|
@@ -812,24 +751,17 @@ function webSocket(url, config) {
|
|
|
812
751
|
url: httpUrl
|
|
813
752
|
};
|
|
814
753
|
const channel = new WebSocketChannel(wsUrl, config);
|
|
754
|
+
const { apiKey: _apiKey, ...exposedConfig } = resolvedHttpConfig;
|
|
815
755
|
const transport = {
|
|
816
756
|
type: "webSocket",
|
|
817
757
|
request: buildRequestFn(httpUrl, resolvedHttpConfig),
|
|
818
|
-
config:
|
|
758
|
+
config: exposedConfig,
|
|
819
759
|
subscribe: (subParams, callback) => channel.subscribe(subParams, callback),
|
|
820
760
|
destroy: () => channel.destroy()
|
|
821
761
|
};
|
|
822
762
|
return transport;
|
|
823
763
|
};
|
|
824
764
|
}
|
|
825
|
-
// src/errors/contract.ts
|
|
826
|
-
class ContractCallError extends BaseError {
|
|
827
|
-
name = "ContractCallError";
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
class ReadOnlyCallError extends BaseError {
|
|
831
|
-
name = "ReadOnlyCallError";
|
|
832
|
-
}
|
|
833
765
|
export {
|
|
834
766
|
webSocket,
|
|
835
767
|
walletActions,
|
|
@@ -878,19 +810,19 @@ export {
|
|
|
878
810
|
TransactionError,
|
|
879
811
|
TransactionDroppedError,
|
|
880
812
|
TransactionAbortedError,
|
|
813
|
+
TimeoutError,
|
|
881
814
|
TESTNET_ZERO_ADDRESS,
|
|
882
815
|
SimulationError,
|
|
883
816
|
SigningError,
|
|
884
817
|
SerializationError,
|
|
885
|
-
ReadOnlyCallError,
|
|
886
818
|
MalformedResponseError,
|
|
887
819
|
MICROSTX_PER_STX,
|
|
820
|
+
IndexSourceConfigError,
|
|
888
821
|
HttpRequestError,
|
|
889
|
-
ContractCallError,
|
|
890
822
|
BroadcastError,
|
|
891
823
|
BaseError,
|
|
892
824
|
AddressVersion
|
|
893
825
|
};
|
|
894
826
|
|
|
895
|
-
//# debugId=
|
|
827
|
+
//# debugId=81EF29AE87B82E1564756E2164756E21
|
|
896
828
|
//# sourceMappingURL=index.js.map
|