@secretkeylabs/stacks-tools 0.6.0 → 0.7.0-3be878c
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 +2 -2
- package/dist/index.cjs +169 -223
- package/dist/index.d.cts +84 -918
- package/dist/index.d.ts +84 -918
- package/dist/index.js +163 -220
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
// src/utils/safe.ts
|
|
2
|
+
import { backOff } from "exponential-backoff";
|
|
2
3
|
function success(data) {
|
|
3
4
|
return [null, data];
|
|
4
5
|
}
|
|
5
|
-
function error(
|
|
6
|
-
return [
|
|
6
|
+
function error(errorArg) {
|
|
7
|
+
return [errorArg, null];
|
|
7
8
|
}
|
|
8
9
|
async function safePromise(promise) {
|
|
9
10
|
try {
|
|
10
11
|
return success(await promise);
|
|
11
12
|
} catch (e) {
|
|
13
|
+
return error({ name: "SafeError", message: "Promise rejected.", data: e });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var defaultStartingDelay = 15e3;
|
|
17
|
+
var defaultNumOfAttempts = 5;
|
|
18
|
+
async function safeBackOff(promise, options) {
|
|
19
|
+
const [backoffError, data] = await safePromise(
|
|
20
|
+
backOff(
|
|
21
|
+
async () => {
|
|
22
|
+
const [error2, data2] = await promise;
|
|
23
|
+
if (error2) {
|
|
24
|
+
throw error2;
|
|
25
|
+
}
|
|
26
|
+
return data2;
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
startingDelay: options?.startingDelay ?? defaultStartingDelay,
|
|
30
|
+
numOfAttempts: options?.numOfAttempts ?? defaultNumOfAttempts
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
if (backoffError) {
|
|
12
35
|
return error({
|
|
13
|
-
name: "
|
|
14
|
-
message: "
|
|
15
|
-
data:
|
|
36
|
+
name: "BackoffError",
|
|
37
|
+
message: "Retries exceeded.",
|
|
38
|
+
data: backoffError.data
|
|
16
39
|
});
|
|
17
40
|
}
|
|
41
|
+
return success(data);
|
|
18
42
|
}
|
|
19
43
|
function safeCall(fn) {
|
|
20
44
|
try {
|
|
@@ -27,6 +51,29 @@ function safeCall(fn) {
|
|
|
27
51
|
});
|
|
28
52
|
}
|
|
29
53
|
}
|
|
54
|
+
function flatResults(results) {
|
|
55
|
+
const errors = results.map((r) => r[0]).filter((maybeError) => maybeError !== null);
|
|
56
|
+
if (errors.length !== 0)
|
|
57
|
+
return error({
|
|
58
|
+
name: "FlatResultsError",
|
|
59
|
+
message: `Found ${errors.length} errors in result array of length ${results.length}.`,
|
|
60
|
+
data: errors.slice(0, 10)
|
|
61
|
+
// Only show first 10 errors to avoid spamming logs
|
|
62
|
+
});
|
|
63
|
+
const values = results.map((r) => r[1]);
|
|
64
|
+
return [null, values];
|
|
65
|
+
}
|
|
66
|
+
async function safeExtractResponseBody(response) {
|
|
67
|
+
try {
|
|
68
|
+
return await response.json();
|
|
69
|
+
} catch {
|
|
70
|
+
try {
|
|
71
|
+
return await response.text();
|
|
72
|
+
} catch {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
30
77
|
|
|
31
78
|
// src/stacks-api/accounts/balances.ts
|
|
32
79
|
async function balances(opts) {
|
|
@@ -48,7 +95,7 @@ async function balances(opts) {
|
|
|
48
95
|
data: {
|
|
49
96
|
status: res.status,
|
|
50
97
|
statusText: res.statusText,
|
|
51
|
-
|
|
98
|
+
body: await safeExtractResponseBody(res)
|
|
52
99
|
}
|
|
53
100
|
});
|
|
54
101
|
}
|
|
@@ -89,7 +136,7 @@ async function latestNonce(opts) {
|
|
|
89
136
|
endpoint,
|
|
90
137
|
status: res.status,
|
|
91
138
|
statusText: res.statusText,
|
|
92
|
-
|
|
139
|
+
body: await safeExtractResponseBody(res)
|
|
93
140
|
}
|
|
94
141
|
});
|
|
95
142
|
}
|
|
@@ -168,7 +215,7 @@ async function getBlock(opts) {
|
|
|
168
215
|
data: {
|
|
169
216
|
status: res.status,
|
|
170
217
|
statusText: res.statusText,
|
|
171
|
-
|
|
218
|
+
body: await safeExtractResponseBody(res)
|
|
172
219
|
}
|
|
173
220
|
});
|
|
174
221
|
}
|
|
@@ -217,7 +264,7 @@ async function stx(opts) {
|
|
|
217
264
|
data: {
|
|
218
265
|
status: res.status,
|
|
219
266
|
statusText: res.statusText,
|
|
220
|
-
|
|
267
|
+
body: await safeExtractResponseBody(res)
|
|
221
268
|
}
|
|
222
269
|
});
|
|
223
270
|
}
|
|
@@ -270,7 +317,7 @@ async function coreApi(apiOpts) {
|
|
|
270
317
|
data: {
|
|
271
318
|
status: res.status,
|
|
272
319
|
statusText: res.statusText,
|
|
273
|
-
|
|
320
|
+
body: await safeExtractResponseBody(res)
|
|
274
321
|
}
|
|
275
322
|
});
|
|
276
323
|
}
|
|
@@ -325,7 +372,7 @@ async function cycle(opts) {
|
|
|
325
372
|
endpoint,
|
|
326
373
|
status: res.status,
|
|
327
374
|
statusText: res.statusText,
|
|
328
|
-
|
|
375
|
+
body: await safeExtractResponseBody(res)
|
|
329
376
|
}
|
|
330
377
|
});
|
|
331
378
|
}
|
|
@@ -383,7 +430,7 @@ async function cycles(args) {
|
|
|
383
430
|
endpoint,
|
|
384
431
|
status: res.status,
|
|
385
432
|
statusText: res.statusText,
|
|
386
|
-
|
|
433
|
+
body: await safeExtractResponseBody(res)
|
|
387
434
|
}
|
|
388
435
|
});
|
|
389
436
|
}
|
|
@@ -500,7 +547,7 @@ async function signersInCycle(args) {
|
|
|
500
547
|
endpoint,
|
|
501
548
|
status: res.status,
|
|
502
549
|
statusText: res.statusText,
|
|
503
|
-
|
|
550
|
+
body: await safeExtractResponseBody(res)
|
|
504
551
|
}
|
|
505
552
|
});
|
|
506
553
|
}
|
|
@@ -511,7 +558,7 @@ async function signersInCycle(args) {
|
|
|
511
558
|
message: "Failed to parse response body as JSON.",
|
|
512
559
|
data: {
|
|
513
560
|
endpoint,
|
|
514
|
-
|
|
561
|
+
body: data
|
|
515
562
|
}
|
|
516
563
|
});
|
|
517
564
|
}
|
|
@@ -527,18 +574,6 @@ async function signersInCycle(args) {
|
|
|
527
574
|
}
|
|
528
575
|
|
|
529
576
|
// src/stacks-api/proof-of-transfer/stackers-for-signer-in-cycle.ts
|
|
530
|
-
import * as v9 from "valibot";
|
|
531
|
-
var stackerInfoSchema = v9.object({
|
|
532
|
-
stacker_address: v9.string(),
|
|
533
|
-
stacked_amount: v9.string(),
|
|
534
|
-
pox_address: v9.string(),
|
|
535
|
-
stacker_type: v9.union([v9.literal("pooled"), v9.literal("solo")])
|
|
536
|
-
});
|
|
537
|
-
var resultsSchema3 = v9.array(stackerInfoSchema);
|
|
538
|
-
var stackersForSignerInCycleResponseSchema = v9.object({
|
|
539
|
-
...baseListResponseSchema.entries,
|
|
540
|
-
results: resultsSchema3
|
|
541
|
-
});
|
|
542
577
|
async function stackersForSignerInCycle(opts) {
|
|
543
578
|
const search = new URLSearchParams();
|
|
544
579
|
if (opts.limit) search.append("limit", opts.limit.toString());
|
|
@@ -560,7 +595,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
560
595
|
endpoint,
|
|
561
596
|
status: res.status,
|
|
562
597
|
statusText: res.statusText,
|
|
563
|
-
|
|
598
|
+
body: await safeExtractResponseBody(res)
|
|
564
599
|
}
|
|
565
600
|
});
|
|
566
601
|
}
|
|
@@ -572,18 +607,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
572
607
|
data: jsonError
|
|
573
608
|
});
|
|
574
609
|
}
|
|
575
|
-
|
|
576
|
-
stackersForSignerInCycleResponseSchema,
|
|
577
|
-
data
|
|
578
|
-
);
|
|
579
|
-
if (!validationResult.success) {
|
|
580
|
-
return error({
|
|
581
|
-
name: "ValidateDataError",
|
|
582
|
-
message: "Failed to validate response data.",
|
|
583
|
-
data: validationResult
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
return success(validationResult.output);
|
|
610
|
+
return success(data);
|
|
587
611
|
}
|
|
588
612
|
|
|
589
613
|
// src/stacks-api/proof-of-transfer/index.ts
|
|
@@ -596,21 +620,6 @@ var proofOfTransfer = {
|
|
|
596
620
|
};
|
|
597
621
|
|
|
598
622
|
// src/stacks-api/stacking-pool/members.ts
|
|
599
|
-
import * as v10 from "valibot";
|
|
600
|
-
var memberSchema = v10.object({
|
|
601
|
-
stacker: v10.string(),
|
|
602
|
-
pox_addr: v10.optional(v10.string()),
|
|
603
|
-
amount_ustx: v10.string(),
|
|
604
|
-
burn_block_unlock_height: v10.optional(v10.number()),
|
|
605
|
-
block_height: v10.number(),
|
|
606
|
-
tx_id: v10.string()
|
|
607
|
-
});
|
|
608
|
-
var membersResponseSchema = v10.object({
|
|
609
|
-
limit: v10.number(),
|
|
610
|
-
offset: v10.number(),
|
|
611
|
-
total: v10.number(),
|
|
612
|
-
results: v10.array(memberSchema)
|
|
613
|
-
});
|
|
614
623
|
async function members(args) {
|
|
615
624
|
const search = new URLSearchParams();
|
|
616
625
|
if (args.afterBlock) search.append("after_block", args.afterBlock.toString());
|
|
@@ -632,7 +641,7 @@ async function members(args) {
|
|
|
632
641
|
data: {
|
|
633
642
|
status: res.status,
|
|
634
643
|
statusText: res.statusText,
|
|
635
|
-
|
|
644
|
+
body: await safeExtractResponseBody(res)
|
|
636
645
|
}
|
|
637
646
|
});
|
|
638
647
|
}
|
|
@@ -644,15 +653,7 @@ async function members(args) {
|
|
|
644
653
|
data: jsonParseError
|
|
645
654
|
});
|
|
646
655
|
}
|
|
647
|
-
|
|
648
|
-
if (!validationResult.success) {
|
|
649
|
-
return error({
|
|
650
|
-
name: "ValidateDataError",
|
|
651
|
-
message: "Failed to validate data.",
|
|
652
|
-
data: validationResult
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
return success(validationResult.output);
|
|
656
|
+
return success(data);
|
|
656
657
|
}
|
|
657
658
|
|
|
658
659
|
// src/stacks-api/stacking-pool/index.ts
|
|
@@ -660,124 +661,7 @@ var stackingPool = {
|
|
|
660
661
|
members
|
|
661
662
|
};
|
|
662
663
|
|
|
663
|
-
// src/stacks-api/transactions/schemas.ts
|
|
664
|
-
import * as v11 from "valibot";
|
|
665
|
-
var baseTransactionSchema = v11.object({
|
|
666
|
-
tx_id: v11.string(),
|
|
667
|
-
nonce: v11.number(),
|
|
668
|
-
fee_rate: v11.string(),
|
|
669
|
-
sender_address: v11.string(),
|
|
670
|
-
sponsored: v11.boolean(),
|
|
671
|
-
post_condition_mode: v11.string(),
|
|
672
|
-
post_conditions: v11.array(v11.unknown()),
|
|
673
|
-
anchor_mode: v11.string(),
|
|
674
|
-
is_unanchored: v11.boolean(),
|
|
675
|
-
block_hash: v11.string(),
|
|
676
|
-
parent_block_hash: v11.string(),
|
|
677
|
-
block_height: v11.number(),
|
|
678
|
-
block_time: v11.number(),
|
|
679
|
-
block_time_iso: v11.string(),
|
|
680
|
-
burn_block_height: v11.number(),
|
|
681
|
-
burn_block_time: v11.number(),
|
|
682
|
-
burn_block_time_iso: v11.string(),
|
|
683
|
-
parent_burn_block_time: v11.number(),
|
|
684
|
-
parent_burn_block_time_iso: v11.string(),
|
|
685
|
-
canonical: v11.boolean(),
|
|
686
|
-
tx_index: v11.number(),
|
|
687
|
-
tx_status: v11.union([
|
|
688
|
-
v11.literal("success"),
|
|
689
|
-
v11.literal("abort_by_response"),
|
|
690
|
-
v11.literal("abort_by_post_condition")
|
|
691
|
-
]),
|
|
692
|
-
tx_result: v11.object({
|
|
693
|
-
hex: v11.string(),
|
|
694
|
-
repr: v11.string()
|
|
695
|
-
}),
|
|
696
|
-
microblock_hash: v11.string(),
|
|
697
|
-
microblock_sequence: v11.number(),
|
|
698
|
-
microblock_canonical: v11.boolean(),
|
|
699
|
-
event_count: v11.number(),
|
|
700
|
-
events: v11.array(v11.unknown()),
|
|
701
|
-
execution_cost_read_count: v11.number(),
|
|
702
|
-
execution_cost_read_length: v11.number(),
|
|
703
|
-
execution_cost_runtime: v11.number(),
|
|
704
|
-
execution_cost_write_count: v11.number(),
|
|
705
|
-
execution_cost_write_length: v11.number()
|
|
706
|
-
});
|
|
707
|
-
var contractCallTransactionSchema = v11.object({
|
|
708
|
-
tx_type: v11.literal("contract_call"),
|
|
709
|
-
contract_call: v11.object({
|
|
710
|
-
contract_id: v11.string(),
|
|
711
|
-
function_name: v11.string(),
|
|
712
|
-
function_signature: v11.string(),
|
|
713
|
-
function_args: v11.array(
|
|
714
|
-
v11.object({
|
|
715
|
-
hex: v11.string(),
|
|
716
|
-
repr: v11.string(),
|
|
717
|
-
name: v11.string(),
|
|
718
|
-
type: v11.string()
|
|
719
|
-
})
|
|
720
|
-
)
|
|
721
|
-
}),
|
|
722
|
-
...baseTransactionSchema.entries
|
|
723
|
-
});
|
|
724
|
-
var smartContractTransactionSchema = v11.object({
|
|
725
|
-
tx_type: v11.literal("smart_contract"),
|
|
726
|
-
smart_contract: v11.object({
|
|
727
|
-
/**
|
|
728
|
-
* NOTE: The types may be wrong, not sure what type of value is used when
|
|
729
|
-
* the version is not `null`.
|
|
730
|
-
*/
|
|
731
|
-
clarity_version: v11.union([v11.null(), v11.number()]),
|
|
732
|
-
contract_id: v11.string(),
|
|
733
|
-
source_code: v11.string()
|
|
734
|
-
}),
|
|
735
|
-
...baseTransactionSchema.entries
|
|
736
|
-
});
|
|
737
|
-
var tokenTransferSchema = v11.object({
|
|
738
|
-
tx_type: v11.literal("token_transfer"),
|
|
739
|
-
token_transfer: v11.object({
|
|
740
|
-
recipient_address: v11.string(),
|
|
741
|
-
amount: v11.string(),
|
|
742
|
-
memo: v11.string()
|
|
743
|
-
}),
|
|
744
|
-
...baseTransactionSchema.entries
|
|
745
|
-
});
|
|
746
|
-
var transactionSchema = v11.variant("tx_type", [
|
|
747
|
-
contractCallTransactionSchema,
|
|
748
|
-
smartContractTransactionSchema,
|
|
749
|
-
tokenTransferSchema
|
|
750
|
-
]);
|
|
751
|
-
|
|
752
664
|
// src/stacks-api/transactions/address-transactions.ts
|
|
753
|
-
import * as v12 from "valibot";
|
|
754
|
-
var resultSchema = v12.object({
|
|
755
|
-
tx: transactionSchema,
|
|
756
|
-
stx_sent: v12.string(),
|
|
757
|
-
stx_received: v12.string(),
|
|
758
|
-
events: v12.object({
|
|
759
|
-
stx: v12.object({
|
|
760
|
-
transfer: v12.number(),
|
|
761
|
-
mint: v12.number(),
|
|
762
|
-
burn: v12.number()
|
|
763
|
-
}),
|
|
764
|
-
ft: v12.object({
|
|
765
|
-
transfer: v12.number(),
|
|
766
|
-
mint: v12.number(),
|
|
767
|
-
burn: v12.number()
|
|
768
|
-
}),
|
|
769
|
-
nft: v12.object({
|
|
770
|
-
transfer: v12.number(),
|
|
771
|
-
mint: v12.number(),
|
|
772
|
-
burn: v12.number()
|
|
773
|
-
})
|
|
774
|
-
})
|
|
775
|
-
});
|
|
776
|
-
var resultsSchema4 = v12.array(resultSchema);
|
|
777
|
-
var addressTransactionsResponseSchema = v12.object({
|
|
778
|
-
...baseListResponseSchema.entries,
|
|
779
|
-
results: resultsSchema4
|
|
780
|
-
});
|
|
781
665
|
async function addressTransactions(args) {
|
|
782
666
|
const search = new URLSearchParams();
|
|
783
667
|
if (args.limit) search.append("limit", args.limit.toString());
|
|
@@ -799,7 +683,7 @@ async function addressTransactions(args) {
|
|
|
799
683
|
data: {
|
|
800
684
|
status: res.status,
|
|
801
685
|
statusText: res.statusText,
|
|
802
|
-
|
|
686
|
+
body: await safeExtractResponseBody(res)
|
|
803
687
|
}
|
|
804
688
|
});
|
|
805
689
|
}
|
|
@@ -811,19 +695,47 @@ async function addressTransactions(args) {
|
|
|
811
695
|
data: jsonParseError
|
|
812
696
|
});
|
|
813
697
|
}
|
|
814
|
-
|
|
815
|
-
|
|
698
|
+
return success(data);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// src/stacks-api/transactions/events-for-an-address-transaction.ts
|
|
702
|
+
async function eventsForAnAddressTransaction(args) {
|
|
703
|
+
const search = new URLSearchParams();
|
|
704
|
+
if (args.limit) search.append("limit", args.limit.toString());
|
|
705
|
+
if (args.offset) search.append("offset", args.offset.toString());
|
|
706
|
+
const init = {};
|
|
707
|
+
if (args.apiKeyConfig) {
|
|
708
|
+
init.headers = {
|
|
709
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
const endpoint = `${args.baseUrl}/extended/v2/addresses/${args.address}/transactions/${args.transactionId}/events?${search}`;
|
|
713
|
+
const res = await fetch(endpoint, init);
|
|
714
|
+
if (!res.ok) {
|
|
816
715
|
return error({
|
|
817
|
-
name: "
|
|
818
|
-
message:
|
|
819
|
-
data:
|
|
716
|
+
name: "FetchEventsForAnAddressTransactionError",
|
|
717
|
+
message: `Failed to fetch address transaction events.`,
|
|
718
|
+
data: {
|
|
719
|
+
address: args.address,
|
|
720
|
+
transactionId: args.transactionId,
|
|
721
|
+
status: res.status,
|
|
722
|
+
statusText: res.statusText,
|
|
723
|
+
body: await safeExtractResponseBody(res)
|
|
724
|
+
}
|
|
820
725
|
});
|
|
821
726
|
}
|
|
822
|
-
|
|
727
|
+
const [jsonParseError, data] = await safePromise(res.json());
|
|
728
|
+
if (jsonParseError) {
|
|
729
|
+
return error({
|
|
730
|
+
name: "ParseBodyError",
|
|
731
|
+
message: "Failed to parse response body as JSON.",
|
|
732
|
+
error: jsonParseError
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
return success(data);
|
|
823
736
|
}
|
|
824
737
|
|
|
825
738
|
// src/stacks-api/transactions/get-transaction.ts
|
|
826
|
-
import * as v13 from "valibot";
|
|
827
739
|
async function getTransaction(args) {
|
|
828
740
|
const init = {};
|
|
829
741
|
if (args.apiKeyConfig) {
|
|
@@ -836,11 +748,12 @@ async function getTransaction(args) {
|
|
|
836
748
|
if (!res.ok) {
|
|
837
749
|
return error({
|
|
838
750
|
name: "FetchTransactionError",
|
|
839
|
-
message: `Failed to fetch transaction
|
|
840
|
-
|
|
751
|
+
message: `Failed to fetch transaction.`,
|
|
752
|
+
data: {
|
|
753
|
+
transactionId: args.transactionId,
|
|
841
754
|
status: res.status,
|
|
842
755
|
statusText: res.statusText,
|
|
843
|
-
|
|
756
|
+
body: await safeExtractResponseBody(res)
|
|
844
757
|
}
|
|
845
758
|
});
|
|
846
759
|
}
|
|
@@ -852,15 +765,7 @@ async function getTransaction(args) {
|
|
|
852
765
|
error: jsonParseError
|
|
853
766
|
});
|
|
854
767
|
}
|
|
855
|
-
|
|
856
|
-
if (!validationResult.success) {
|
|
857
|
-
return error({
|
|
858
|
-
name: "ValidateDataError",
|
|
859
|
-
message: "Failed to validate data.",
|
|
860
|
-
error: validationResult
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
return success(validationResult.output);
|
|
768
|
+
return success(data);
|
|
864
769
|
}
|
|
865
770
|
|
|
866
771
|
// src/stacks-api/transactions/mempool-transactions.ts
|
|
@@ -891,7 +796,7 @@ async function mempoolTransactions(args) {
|
|
|
891
796
|
data: {
|
|
892
797
|
status: res.status,
|
|
893
798
|
statusText: res.statusText,
|
|
894
|
-
|
|
799
|
+
body: await safeExtractResponseBody(res)
|
|
895
800
|
}
|
|
896
801
|
});
|
|
897
802
|
}
|
|
@@ -906,11 +811,46 @@ async function mempoolTransactions(args) {
|
|
|
906
811
|
return success(data);
|
|
907
812
|
}
|
|
908
813
|
|
|
814
|
+
// src/stacks-api/transactions/get-raw-transaction.ts
|
|
815
|
+
async function getRawTransaction(args) {
|
|
816
|
+
const init = {};
|
|
817
|
+
if (args.apiKeyConfig) {
|
|
818
|
+
init.headers = {
|
|
819
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
const endpoint = `${args.baseUrl}/extended/v1/tx/${args.transactionId}/raw`;
|
|
823
|
+
const res = await fetch(endpoint, init);
|
|
824
|
+
if (!res.ok) {
|
|
825
|
+
return error({
|
|
826
|
+
name: "RawTransactionFetchError",
|
|
827
|
+
message: `Failed to fetch raw transaction.`,
|
|
828
|
+
data: {
|
|
829
|
+
transactionId: args.transactionId,
|
|
830
|
+
status: res.status,
|
|
831
|
+
statusText: res.statusText,
|
|
832
|
+
body: await safeExtractResponseBody(res)
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
const [jsonParseError, data] = await safePromise(res.json());
|
|
837
|
+
if (jsonParseError) {
|
|
838
|
+
return error({
|
|
839
|
+
name: "ParseBodyError",
|
|
840
|
+
message: "Failed to parse response body as JSON.",
|
|
841
|
+
error: jsonParseError
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
return success(data);
|
|
845
|
+
}
|
|
846
|
+
|
|
909
847
|
// src/stacks-api/transactions/index.ts
|
|
910
848
|
var transactions = {
|
|
911
849
|
addressTransactions,
|
|
850
|
+
eventsForAnAddressTransaction,
|
|
912
851
|
getTransaction,
|
|
913
|
-
mempoolTransactions
|
|
852
|
+
mempoolTransactions,
|
|
853
|
+
getRawTransaction
|
|
914
854
|
};
|
|
915
855
|
|
|
916
856
|
// src/stacks-api/mempool/transaction-fee-priorities.ts
|
|
@@ -930,7 +870,7 @@ async function transactionFeePriorities(opts) {
|
|
|
930
870
|
data: {
|
|
931
871
|
status: res.status,
|
|
932
872
|
statusText: res.statusText,
|
|
933
|
-
|
|
873
|
+
body: await safeExtractResponseBody(res)
|
|
934
874
|
}
|
|
935
875
|
});
|
|
936
876
|
}
|
|
@@ -963,16 +903,16 @@ var stacksApi = {
|
|
|
963
903
|
};
|
|
964
904
|
|
|
965
905
|
// src/stacks-rpc-api/smart-contracts/map-entry.ts
|
|
966
|
-
import * as
|
|
967
|
-
var mapEntryResponseSchema =
|
|
906
|
+
import * as v9 from "valibot";
|
|
907
|
+
var mapEntryResponseSchema = v9.object({
|
|
968
908
|
/**
|
|
969
909
|
* Hex-encoded string of clarity value. It is always an optional tuple.
|
|
970
910
|
*/
|
|
971
|
-
data:
|
|
911
|
+
data: v9.string(),
|
|
972
912
|
/**
|
|
973
913
|
* Hex-encoded string of the MARF proof for the data
|
|
974
914
|
*/
|
|
975
|
-
proof:
|
|
915
|
+
proof: v9.optional(v9.string())
|
|
976
916
|
});
|
|
977
917
|
async function mapEntry(args) {
|
|
978
918
|
const search = new URLSearchParams();
|
|
@@ -1000,7 +940,7 @@ async function mapEntry(args) {
|
|
|
1000
940
|
status: res.status,
|
|
1001
941
|
statusText: res.statusText,
|
|
1002
942
|
endpoint,
|
|
1003
|
-
|
|
943
|
+
body: await safeExtractResponseBody(res)
|
|
1004
944
|
}
|
|
1005
945
|
});
|
|
1006
946
|
}
|
|
@@ -1012,7 +952,7 @@ async function mapEntry(args) {
|
|
|
1012
952
|
data: jsonError
|
|
1013
953
|
});
|
|
1014
954
|
}
|
|
1015
|
-
const validationResult =
|
|
955
|
+
const validationResult = v9.safeParse(mapEntryResponseSchema, data);
|
|
1016
956
|
if (!validationResult.success) {
|
|
1017
957
|
return error({
|
|
1018
958
|
name: "ValidateDataError",
|
|
@@ -1048,7 +988,7 @@ async function readOnly(args) {
|
|
|
1048
988
|
data: {
|
|
1049
989
|
status: res.status,
|
|
1050
990
|
statusText: res.statusText,
|
|
1051
|
-
|
|
991
|
+
body: await safeExtractResponseBody(res)
|
|
1052
992
|
}
|
|
1053
993
|
});
|
|
1054
994
|
}
|
|
@@ -1085,7 +1025,7 @@ async function contractInterface(args) {
|
|
|
1085
1025
|
status: res.status,
|
|
1086
1026
|
statusText: res.statusText,
|
|
1087
1027
|
endpoint,
|
|
1088
|
-
|
|
1028
|
+
body: await safeExtractResponseBody(res)
|
|
1089
1029
|
}
|
|
1090
1030
|
});
|
|
1091
1031
|
}
|
|
@@ -1123,7 +1063,7 @@ async function poxDetails(args) {
|
|
|
1123
1063
|
data: {
|
|
1124
1064
|
status: res.status,
|
|
1125
1065
|
statusText: res.statusText,
|
|
1126
|
-
|
|
1066
|
+
body: await safeExtractResponseBody(res)
|
|
1127
1067
|
}
|
|
1128
1068
|
});
|
|
1129
1069
|
}
|
|
@@ -1150,18 +1090,18 @@ var stacksRpcApi = {
|
|
|
1150
1090
|
};
|
|
1151
1091
|
|
|
1152
1092
|
// src/utils/call-rate-limited-api.ts
|
|
1153
|
-
import { backOff } from "exponential-backoff";
|
|
1154
|
-
var
|
|
1155
|
-
var
|
|
1093
|
+
import { backOff as backOff2 } from "exponential-backoff";
|
|
1094
|
+
var defaultStartingDelay2 = 15e3;
|
|
1095
|
+
var defaultNumOfAttempts2 = 5;
|
|
1156
1096
|
function callRateLimitedApi(fn, options) {
|
|
1157
|
-
return
|
|
1158
|
-
startingDelay: options?.startingDelay ??
|
|
1159
|
-
numOfAttempts: options?.numOfAttempts ??
|
|
1097
|
+
return backOff2(fn, {
|
|
1098
|
+
startingDelay: options?.startingDelay ?? defaultStartingDelay2,
|
|
1099
|
+
numOfAttempts: options?.numOfAttempts ?? defaultNumOfAttempts2
|
|
1160
1100
|
});
|
|
1161
1101
|
}
|
|
1162
1102
|
async function safeCallRateLimitedApi(fn, options) {
|
|
1163
1103
|
try {
|
|
1164
|
-
return await
|
|
1104
|
+
return await backOff2(
|
|
1165
1105
|
async () => {
|
|
1166
1106
|
const [error2, data] = await fn();
|
|
1167
1107
|
if (error2) {
|
|
@@ -1387,10 +1327,13 @@ var pox4Api = { maps, readOnly: readOnly2 };
|
|
|
1387
1327
|
export {
|
|
1388
1328
|
callRateLimitedApi,
|
|
1389
1329
|
error,
|
|
1330
|
+
flatResults,
|
|
1390
1331
|
pox4Api,
|
|
1391
1332
|
queries,
|
|
1333
|
+
safeBackOff,
|
|
1392
1334
|
safeCall,
|
|
1393
1335
|
safeCallRateLimitedApi,
|
|
1336
|
+
safeExtractResponseBody,
|
|
1394
1337
|
safePromise,
|
|
1395
1338
|
stacksApi,
|
|
1396
1339
|
stacksRpcApi,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secretkeylabs/stacks-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-3be878c",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@arethetypeswrong/cli": "0.15.4",
|
|
26
26
|
"@types/bun": "latest",
|
|
27
|
-
"prettier": "
|
|
28
|
-
"tsup": "
|
|
29
|
-
"typescript": "
|
|
27
|
+
"prettier": "3.5.3",
|
|
28
|
+
"tsup": "8.5.0",
|
|
29
|
+
"typescript": "5.8.3"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@stacks/blockchain-api-client": "
|
|
32
|
+
"@stacks/blockchain-api-client": "8.11.1",
|
|
33
33
|
"@stacks/transactions": "^7.0.0",
|
|
34
|
-
"valibot": "^
|
|
34
|
+
"valibot": "^1.1.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"exponential-backoff": "3.1.1"
|