@secretkeylabs/stacks-tools 0.6.0 → 0.7.0-73ae437
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 -924
- package/dist/index.d.ts +84 -924
- package/dist/index.js +163 -220
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@ A collection of methods for calling the Stacks API and managing Stacks pools.
|
|
|
4
4
|
|
|
5
5
|
## Quickstart
|
|
6
6
|
|
|
7
|
-
Install dependencies with
|
|
7
|
+
Install dependencies with:
|
|
8
8
|
|
|
9
9
|
```shell
|
|
10
10
|
bun install
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
and build the package with
|
|
13
|
+
and build the package with:
|
|
14
14
|
|
|
15
15
|
```shell
|
|
16
16
|
bun run build
|
package/dist/index.cjs
CHANGED
|
@@ -28,38 +28,65 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
callRateLimitedApi: () => callRateLimitedApi,
|
|
34
34
|
error: () => error,
|
|
35
|
+
flatResults: () => flatResults,
|
|
35
36
|
pox4Api: () => pox4Api,
|
|
36
37
|
queries: () => queries,
|
|
38
|
+
safeBackOff: () => safeBackOff,
|
|
37
39
|
safeCall: () => safeCall,
|
|
38
40
|
safeCallRateLimitedApi: () => safeCallRateLimitedApi,
|
|
41
|
+
safeExtractResponseBody: () => safeExtractResponseBody,
|
|
39
42
|
safePromise: () => safePromise,
|
|
40
43
|
stacksApi: () => stacksApi,
|
|
41
44
|
stacksRpcApi: () => stacksRpcApi,
|
|
42
45
|
success: () => success
|
|
43
46
|
});
|
|
44
|
-
module.exports = __toCommonJS(
|
|
47
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
48
|
|
|
46
49
|
// src/utils/safe.ts
|
|
50
|
+
var import_exponential_backoff = require("exponential-backoff");
|
|
47
51
|
function success(data) {
|
|
48
52
|
return [null, data];
|
|
49
53
|
}
|
|
50
|
-
function error(
|
|
51
|
-
return [
|
|
54
|
+
function error(errorArg) {
|
|
55
|
+
return [errorArg, null];
|
|
52
56
|
}
|
|
53
57
|
async function safePromise(promise) {
|
|
54
58
|
try {
|
|
55
59
|
return success(await promise);
|
|
56
60
|
} catch (e) {
|
|
61
|
+
return error({ name: "SafeError", message: "Promise rejected.", data: e });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
var defaultStartingDelay = 15e3;
|
|
65
|
+
var defaultNumOfAttempts = 5;
|
|
66
|
+
async function safeBackOff(promise, options) {
|
|
67
|
+
const [backoffError, data] = await safePromise(
|
|
68
|
+
(0, import_exponential_backoff.backOff)(
|
|
69
|
+
async () => {
|
|
70
|
+
const [error2, data2] = await promise;
|
|
71
|
+
if (error2) {
|
|
72
|
+
throw error2;
|
|
73
|
+
}
|
|
74
|
+
return data2;
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
startingDelay: options?.startingDelay ?? defaultStartingDelay,
|
|
78
|
+
numOfAttempts: options?.numOfAttempts ?? defaultNumOfAttempts
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
if (backoffError) {
|
|
57
83
|
return error({
|
|
58
|
-
name: "
|
|
59
|
-
message: "
|
|
60
|
-
data:
|
|
84
|
+
name: "BackoffError",
|
|
85
|
+
message: "Retries exceeded.",
|
|
86
|
+
data: backoffError.data
|
|
61
87
|
});
|
|
62
88
|
}
|
|
89
|
+
return success(data);
|
|
63
90
|
}
|
|
64
91
|
function safeCall(fn) {
|
|
65
92
|
try {
|
|
@@ -72,6 +99,29 @@ function safeCall(fn) {
|
|
|
72
99
|
});
|
|
73
100
|
}
|
|
74
101
|
}
|
|
102
|
+
function flatResults(results) {
|
|
103
|
+
const errors = results.map((r) => r[0]).filter((maybeError) => maybeError !== null);
|
|
104
|
+
if (errors.length !== 0)
|
|
105
|
+
return error({
|
|
106
|
+
name: "FlatResultsError",
|
|
107
|
+
message: `Found ${errors.length} errors in result array of length ${results.length}.`,
|
|
108
|
+
data: errors.slice(0, 10)
|
|
109
|
+
// Only show first 10 errors to avoid spamming logs
|
|
110
|
+
});
|
|
111
|
+
const values = results.map((r) => r[1]);
|
|
112
|
+
return [null, values];
|
|
113
|
+
}
|
|
114
|
+
async function safeExtractResponseBody(response) {
|
|
115
|
+
try {
|
|
116
|
+
return await response.json();
|
|
117
|
+
} catch {
|
|
118
|
+
try {
|
|
119
|
+
return await response.text();
|
|
120
|
+
} catch {
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
75
125
|
|
|
76
126
|
// src/stacks-api/accounts/balances.ts
|
|
77
127
|
async function balances(opts) {
|
|
@@ -93,7 +143,7 @@ async function balances(opts) {
|
|
|
93
143
|
data: {
|
|
94
144
|
status: res.status,
|
|
95
145
|
statusText: res.statusText,
|
|
96
|
-
|
|
146
|
+
body: await safeExtractResponseBody(res)
|
|
97
147
|
}
|
|
98
148
|
});
|
|
99
149
|
}
|
|
@@ -134,7 +184,7 @@ async function latestNonce(opts) {
|
|
|
134
184
|
endpoint,
|
|
135
185
|
status: res.status,
|
|
136
186
|
statusText: res.statusText,
|
|
137
|
-
|
|
187
|
+
body: await safeExtractResponseBody(res)
|
|
138
188
|
}
|
|
139
189
|
});
|
|
140
190
|
}
|
|
@@ -213,7 +263,7 @@ async function getBlock(opts) {
|
|
|
213
263
|
data: {
|
|
214
264
|
status: res.status,
|
|
215
265
|
statusText: res.statusText,
|
|
216
|
-
|
|
266
|
+
body: await safeExtractResponseBody(res)
|
|
217
267
|
}
|
|
218
268
|
});
|
|
219
269
|
}
|
|
@@ -262,7 +312,7 @@ async function stx(opts) {
|
|
|
262
312
|
data: {
|
|
263
313
|
status: res.status,
|
|
264
314
|
statusText: res.statusText,
|
|
265
|
-
|
|
315
|
+
body: await safeExtractResponseBody(res)
|
|
266
316
|
}
|
|
267
317
|
});
|
|
268
318
|
}
|
|
@@ -315,7 +365,7 @@ async function coreApi(apiOpts) {
|
|
|
315
365
|
data: {
|
|
316
366
|
status: res.status,
|
|
317
367
|
statusText: res.statusText,
|
|
318
|
-
|
|
368
|
+
body: await safeExtractResponseBody(res)
|
|
319
369
|
}
|
|
320
370
|
});
|
|
321
371
|
}
|
|
@@ -370,7 +420,7 @@ async function cycle(opts) {
|
|
|
370
420
|
endpoint,
|
|
371
421
|
status: res.status,
|
|
372
422
|
statusText: res.statusText,
|
|
373
|
-
|
|
423
|
+
body: await safeExtractResponseBody(res)
|
|
374
424
|
}
|
|
375
425
|
});
|
|
376
426
|
}
|
|
@@ -428,7 +478,7 @@ async function cycles(args) {
|
|
|
428
478
|
endpoint,
|
|
429
479
|
status: res.status,
|
|
430
480
|
statusText: res.statusText,
|
|
431
|
-
|
|
481
|
+
body: await safeExtractResponseBody(res)
|
|
432
482
|
}
|
|
433
483
|
});
|
|
434
484
|
}
|
|
@@ -545,7 +595,7 @@ async function signersInCycle(args) {
|
|
|
545
595
|
endpoint,
|
|
546
596
|
status: res.status,
|
|
547
597
|
statusText: res.statusText,
|
|
548
|
-
|
|
598
|
+
body: await safeExtractResponseBody(res)
|
|
549
599
|
}
|
|
550
600
|
});
|
|
551
601
|
}
|
|
@@ -556,7 +606,7 @@ async function signersInCycle(args) {
|
|
|
556
606
|
message: "Failed to parse response body as JSON.",
|
|
557
607
|
data: {
|
|
558
608
|
endpoint,
|
|
559
|
-
|
|
609
|
+
body: data
|
|
560
610
|
}
|
|
561
611
|
});
|
|
562
612
|
}
|
|
@@ -572,18 +622,6 @@ async function signersInCycle(args) {
|
|
|
572
622
|
}
|
|
573
623
|
|
|
574
624
|
// src/stacks-api/proof-of-transfer/stackers-for-signer-in-cycle.ts
|
|
575
|
-
var v9 = __toESM(require("valibot"), 1);
|
|
576
|
-
var stackerInfoSchema = v9.object({
|
|
577
|
-
stacker_address: v9.string(),
|
|
578
|
-
stacked_amount: v9.string(),
|
|
579
|
-
pox_address: v9.string(),
|
|
580
|
-
stacker_type: v9.union([v9.literal("pooled"), v9.literal("solo")])
|
|
581
|
-
});
|
|
582
|
-
var resultsSchema3 = v9.array(stackerInfoSchema);
|
|
583
|
-
var stackersForSignerInCycleResponseSchema = v9.object({
|
|
584
|
-
...baseListResponseSchema.entries,
|
|
585
|
-
results: resultsSchema3
|
|
586
|
-
});
|
|
587
625
|
async function stackersForSignerInCycle(opts) {
|
|
588
626
|
const search = new URLSearchParams();
|
|
589
627
|
if (opts.limit) search.append("limit", opts.limit.toString());
|
|
@@ -605,7 +643,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
605
643
|
endpoint,
|
|
606
644
|
status: res.status,
|
|
607
645
|
statusText: res.statusText,
|
|
608
|
-
|
|
646
|
+
body: await safeExtractResponseBody(res)
|
|
609
647
|
}
|
|
610
648
|
});
|
|
611
649
|
}
|
|
@@ -617,18 +655,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
617
655
|
data: jsonError
|
|
618
656
|
});
|
|
619
657
|
}
|
|
620
|
-
|
|
621
|
-
stackersForSignerInCycleResponseSchema,
|
|
622
|
-
data
|
|
623
|
-
);
|
|
624
|
-
if (!validationResult.success) {
|
|
625
|
-
return error({
|
|
626
|
-
name: "ValidateDataError",
|
|
627
|
-
message: "Failed to validate response data.",
|
|
628
|
-
data: validationResult
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
return success(validationResult.output);
|
|
658
|
+
return success(data);
|
|
632
659
|
}
|
|
633
660
|
|
|
634
661
|
// src/stacks-api/proof-of-transfer/index.ts
|
|
@@ -641,21 +668,6 @@ var proofOfTransfer = {
|
|
|
641
668
|
};
|
|
642
669
|
|
|
643
670
|
// src/stacks-api/stacking-pool/members.ts
|
|
644
|
-
var v10 = __toESM(require("valibot"), 1);
|
|
645
|
-
var memberSchema = v10.object({
|
|
646
|
-
stacker: v10.string(),
|
|
647
|
-
pox_addr: v10.optional(v10.string()),
|
|
648
|
-
amount_ustx: v10.string(),
|
|
649
|
-
burn_block_unlock_height: v10.optional(v10.number()),
|
|
650
|
-
block_height: v10.number(),
|
|
651
|
-
tx_id: v10.string()
|
|
652
|
-
});
|
|
653
|
-
var membersResponseSchema = v10.object({
|
|
654
|
-
limit: v10.number(),
|
|
655
|
-
offset: v10.number(),
|
|
656
|
-
total: v10.number(),
|
|
657
|
-
results: v10.array(memberSchema)
|
|
658
|
-
});
|
|
659
671
|
async function members(args) {
|
|
660
672
|
const search = new URLSearchParams();
|
|
661
673
|
if (args.afterBlock) search.append("after_block", args.afterBlock.toString());
|
|
@@ -677,7 +689,7 @@ async function members(args) {
|
|
|
677
689
|
data: {
|
|
678
690
|
status: res.status,
|
|
679
691
|
statusText: res.statusText,
|
|
680
|
-
|
|
692
|
+
body: await safeExtractResponseBody(res)
|
|
681
693
|
}
|
|
682
694
|
});
|
|
683
695
|
}
|
|
@@ -689,15 +701,7 @@ async function members(args) {
|
|
|
689
701
|
data: jsonParseError
|
|
690
702
|
});
|
|
691
703
|
}
|
|
692
|
-
|
|
693
|
-
if (!validationResult.success) {
|
|
694
|
-
return error({
|
|
695
|
-
name: "ValidateDataError",
|
|
696
|
-
message: "Failed to validate data.",
|
|
697
|
-
data: validationResult
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
return success(validationResult.output);
|
|
704
|
+
return success(data);
|
|
701
705
|
}
|
|
702
706
|
|
|
703
707
|
// src/stacks-api/stacking-pool/index.ts
|
|
@@ -705,124 +709,7 @@ var stackingPool = {
|
|
|
705
709
|
members
|
|
706
710
|
};
|
|
707
711
|
|
|
708
|
-
// src/stacks-api/transactions/schemas.ts
|
|
709
|
-
var v11 = __toESM(require("valibot"), 1);
|
|
710
|
-
var baseTransactionSchema = v11.object({
|
|
711
|
-
tx_id: v11.string(),
|
|
712
|
-
nonce: v11.number(),
|
|
713
|
-
fee_rate: v11.string(),
|
|
714
|
-
sender_address: v11.string(),
|
|
715
|
-
sponsored: v11.boolean(),
|
|
716
|
-
post_condition_mode: v11.string(),
|
|
717
|
-
post_conditions: v11.array(v11.unknown()),
|
|
718
|
-
anchor_mode: v11.string(),
|
|
719
|
-
is_unanchored: v11.boolean(),
|
|
720
|
-
block_hash: v11.string(),
|
|
721
|
-
parent_block_hash: v11.string(),
|
|
722
|
-
block_height: v11.number(),
|
|
723
|
-
block_time: v11.number(),
|
|
724
|
-
block_time_iso: v11.string(),
|
|
725
|
-
burn_block_height: v11.number(),
|
|
726
|
-
burn_block_time: v11.number(),
|
|
727
|
-
burn_block_time_iso: v11.string(),
|
|
728
|
-
parent_burn_block_time: v11.number(),
|
|
729
|
-
parent_burn_block_time_iso: v11.string(),
|
|
730
|
-
canonical: v11.boolean(),
|
|
731
|
-
tx_index: v11.number(),
|
|
732
|
-
tx_status: v11.union([
|
|
733
|
-
v11.literal("success"),
|
|
734
|
-
v11.literal("abort_by_response"),
|
|
735
|
-
v11.literal("abort_by_post_condition")
|
|
736
|
-
]),
|
|
737
|
-
tx_result: v11.object({
|
|
738
|
-
hex: v11.string(),
|
|
739
|
-
repr: v11.string()
|
|
740
|
-
}),
|
|
741
|
-
microblock_hash: v11.string(),
|
|
742
|
-
microblock_sequence: v11.number(),
|
|
743
|
-
microblock_canonical: v11.boolean(),
|
|
744
|
-
event_count: v11.number(),
|
|
745
|
-
events: v11.array(v11.unknown()),
|
|
746
|
-
execution_cost_read_count: v11.number(),
|
|
747
|
-
execution_cost_read_length: v11.number(),
|
|
748
|
-
execution_cost_runtime: v11.number(),
|
|
749
|
-
execution_cost_write_count: v11.number(),
|
|
750
|
-
execution_cost_write_length: v11.number()
|
|
751
|
-
});
|
|
752
|
-
var contractCallTransactionSchema = v11.object({
|
|
753
|
-
tx_type: v11.literal("contract_call"),
|
|
754
|
-
contract_call: v11.object({
|
|
755
|
-
contract_id: v11.string(),
|
|
756
|
-
function_name: v11.string(),
|
|
757
|
-
function_signature: v11.string(),
|
|
758
|
-
function_args: v11.array(
|
|
759
|
-
v11.object({
|
|
760
|
-
hex: v11.string(),
|
|
761
|
-
repr: v11.string(),
|
|
762
|
-
name: v11.string(),
|
|
763
|
-
type: v11.string()
|
|
764
|
-
})
|
|
765
|
-
)
|
|
766
|
-
}),
|
|
767
|
-
...baseTransactionSchema.entries
|
|
768
|
-
});
|
|
769
|
-
var smartContractTransactionSchema = v11.object({
|
|
770
|
-
tx_type: v11.literal("smart_contract"),
|
|
771
|
-
smart_contract: v11.object({
|
|
772
|
-
/**
|
|
773
|
-
* NOTE: The types may be wrong, not sure what type of value is used when
|
|
774
|
-
* the version is not `null`.
|
|
775
|
-
*/
|
|
776
|
-
clarity_version: v11.union([v11.null(), v11.number()]),
|
|
777
|
-
contract_id: v11.string(),
|
|
778
|
-
source_code: v11.string()
|
|
779
|
-
}),
|
|
780
|
-
...baseTransactionSchema.entries
|
|
781
|
-
});
|
|
782
|
-
var tokenTransferSchema = v11.object({
|
|
783
|
-
tx_type: v11.literal("token_transfer"),
|
|
784
|
-
token_transfer: v11.object({
|
|
785
|
-
recipient_address: v11.string(),
|
|
786
|
-
amount: v11.string(),
|
|
787
|
-
memo: v11.string()
|
|
788
|
-
}),
|
|
789
|
-
...baseTransactionSchema.entries
|
|
790
|
-
});
|
|
791
|
-
var transactionSchema = v11.variant("tx_type", [
|
|
792
|
-
contractCallTransactionSchema,
|
|
793
|
-
smartContractTransactionSchema,
|
|
794
|
-
tokenTransferSchema
|
|
795
|
-
]);
|
|
796
|
-
|
|
797
712
|
// src/stacks-api/transactions/address-transactions.ts
|
|
798
|
-
var v12 = __toESM(require("valibot"), 1);
|
|
799
|
-
var resultSchema = v12.object({
|
|
800
|
-
tx: transactionSchema,
|
|
801
|
-
stx_sent: v12.string(),
|
|
802
|
-
stx_received: v12.string(),
|
|
803
|
-
events: v12.object({
|
|
804
|
-
stx: v12.object({
|
|
805
|
-
transfer: v12.number(),
|
|
806
|
-
mint: v12.number(),
|
|
807
|
-
burn: v12.number()
|
|
808
|
-
}),
|
|
809
|
-
ft: v12.object({
|
|
810
|
-
transfer: v12.number(),
|
|
811
|
-
mint: v12.number(),
|
|
812
|
-
burn: v12.number()
|
|
813
|
-
}),
|
|
814
|
-
nft: v12.object({
|
|
815
|
-
transfer: v12.number(),
|
|
816
|
-
mint: v12.number(),
|
|
817
|
-
burn: v12.number()
|
|
818
|
-
})
|
|
819
|
-
})
|
|
820
|
-
});
|
|
821
|
-
var resultsSchema4 = v12.array(resultSchema);
|
|
822
|
-
var addressTransactionsResponseSchema = v12.object({
|
|
823
|
-
...baseListResponseSchema.entries,
|
|
824
|
-
results: resultsSchema4
|
|
825
|
-
});
|
|
826
713
|
async function addressTransactions(args) {
|
|
827
714
|
const search = new URLSearchParams();
|
|
828
715
|
if (args.limit) search.append("limit", args.limit.toString());
|
|
@@ -844,7 +731,7 @@ async function addressTransactions(args) {
|
|
|
844
731
|
data: {
|
|
845
732
|
status: res.status,
|
|
846
733
|
statusText: res.statusText,
|
|
847
|
-
|
|
734
|
+
body: await safeExtractResponseBody(res)
|
|
848
735
|
}
|
|
849
736
|
});
|
|
850
737
|
}
|
|
@@ -856,19 +743,47 @@ async function addressTransactions(args) {
|
|
|
856
743
|
data: jsonParseError
|
|
857
744
|
});
|
|
858
745
|
}
|
|
859
|
-
|
|
860
|
-
|
|
746
|
+
return success(data);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// src/stacks-api/transactions/events-for-an-address-transaction.ts
|
|
750
|
+
async function eventsForAnAddressTransaction(args) {
|
|
751
|
+
const search = new URLSearchParams();
|
|
752
|
+
if (args.limit) search.append("limit", args.limit.toString());
|
|
753
|
+
if (args.offset) search.append("offset", args.offset.toString());
|
|
754
|
+
const init = {};
|
|
755
|
+
if (args.apiKeyConfig) {
|
|
756
|
+
init.headers = {
|
|
757
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
const endpoint = `${args.baseUrl}/extended/v2/addresses/${args.address}/transactions/${args.transactionId}/events?${search}`;
|
|
761
|
+
const res = await fetch(endpoint, init);
|
|
762
|
+
if (!res.ok) {
|
|
861
763
|
return error({
|
|
862
|
-
name: "
|
|
863
|
-
message:
|
|
864
|
-
data:
|
|
764
|
+
name: "FetchEventsForAnAddressTransactionError",
|
|
765
|
+
message: `Failed to fetch address transaction events.`,
|
|
766
|
+
data: {
|
|
767
|
+
address: args.address,
|
|
768
|
+
transactionId: args.transactionId,
|
|
769
|
+
status: res.status,
|
|
770
|
+
statusText: res.statusText,
|
|
771
|
+
body: await safeExtractResponseBody(res)
|
|
772
|
+
}
|
|
865
773
|
});
|
|
866
774
|
}
|
|
867
|
-
|
|
775
|
+
const [jsonParseError, data] = await safePromise(res.json());
|
|
776
|
+
if (jsonParseError) {
|
|
777
|
+
return error({
|
|
778
|
+
name: "ParseBodyError",
|
|
779
|
+
message: "Failed to parse response body as JSON.",
|
|
780
|
+
error: jsonParseError
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
return success(data);
|
|
868
784
|
}
|
|
869
785
|
|
|
870
786
|
// src/stacks-api/transactions/get-transaction.ts
|
|
871
|
-
var v13 = __toESM(require("valibot"), 1);
|
|
872
787
|
async function getTransaction(args) {
|
|
873
788
|
const init = {};
|
|
874
789
|
if (args.apiKeyConfig) {
|
|
@@ -881,11 +796,12 @@ async function getTransaction(args) {
|
|
|
881
796
|
if (!res.ok) {
|
|
882
797
|
return error({
|
|
883
798
|
name: "FetchTransactionError",
|
|
884
|
-
message: `Failed to fetch transaction
|
|
885
|
-
|
|
799
|
+
message: `Failed to fetch transaction.`,
|
|
800
|
+
data: {
|
|
801
|
+
transactionId: args.transactionId,
|
|
886
802
|
status: res.status,
|
|
887
803
|
statusText: res.statusText,
|
|
888
|
-
|
|
804
|
+
body: await safeExtractResponseBody(res)
|
|
889
805
|
}
|
|
890
806
|
});
|
|
891
807
|
}
|
|
@@ -897,15 +813,7 @@ async function getTransaction(args) {
|
|
|
897
813
|
error: jsonParseError
|
|
898
814
|
});
|
|
899
815
|
}
|
|
900
|
-
|
|
901
|
-
if (!validationResult.success) {
|
|
902
|
-
return error({
|
|
903
|
-
name: "ValidateDataError",
|
|
904
|
-
message: "Failed to validate data.",
|
|
905
|
-
error: validationResult
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
return success(validationResult.output);
|
|
816
|
+
return success(data);
|
|
909
817
|
}
|
|
910
818
|
|
|
911
819
|
// src/stacks-api/transactions/mempool-transactions.ts
|
|
@@ -936,7 +844,7 @@ async function mempoolTransactions(args) {
|
|
|
936
844
|
data: {
|
|
937
845
|
status: res.status,
|
|
938
846
|
statusText: res.statusText,
|
|
939
|
-
|
|
847
|
+
body: await safeExtractResponseBody(res)
|
|
940
848
|
}
|
|
941
849
|
});
|
|
942
850
|
}
|
|
@@ -951,11 +859,46 @@ async function mempoolTransactions(args) {
|
|
|
951
859
|
return success(data);
|
|
952
860
|
}
|
|
953
861
|
|
|
862
|
+
// src/stacks-api/transactions/get-raw-transaction.ts
|
|
863
|
+
async function getRawTransaction(args) {
|
|
864
|
+
const init = {};
|
|
865
|
+
if (args.apiKeyConfig) {
|
|
866
|
+
init.headers = {
|
|
867
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
const endpoint = `${args.baseUrl}/extended/v1/tx/${args.transactionId}/raw`;
|
|
871
|
+
const res = await fetch(endpoint, init);
|
|
872
|
+
if (!res.ok) {
|
|
873
|
+
return error({
|
|
874
|
+
name: "RawTransactionFetchError",
|
|
875
|
+
message: `Failed to fetch raw transaction.`,
|
|
876
|
+
data: {
|
|
877
|
+
transactionId: args.transactionId,
|
|
878
|
+
status: res.status,
|
|
879
|
+
statusText: res.statusText,
|
|
880
|
+
body: await safeExtractResponseBody(res)
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
const [jsonParseError, data] = await safePromise(res.json());
|
|
885
|
+
if (jsonParseError) {
|
|
886
|
+
return error({
|
|
887
|
+
name: "ParseBodyError",
|
|
888
|
+
message: "Failed to parse response body as JSON.",
|
|
889
|
+
error: jsonParseError
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
return success(data);
|
|
893
|
+
}
|
|
894
|
+
|
|
954
895
|
// src/stacks-api/transactions/index.ts
|
|
955
896
|
var transactions = {
|
|
956
897
|
addressTransactions,
|
|
898
|
+
eventsForAnAddressTransaction,
|
|
957
899
|
getTransaction,
|
|
958
|
-
mempoolTransactions
|
|
900
|
+
mempoolTransactions,
|
|
901
|
+
getRawTransaction
|
|
959
902
|
};
|
|
960
903
|
|
|
961
904
|
// src/stacks-api/mempool/transaction-fee-priorities.ts
|
|
@@ -975,7 +918,7 @@ async function transactionFeePriorities(opts) {
|
|
|
975
918
|
data: {
|
|
976
919
|
status: res.status,
|
|
977
920
|
statusText: res.statusText,
|
|
978
|
-
|
|
921
|
+
body: await safeExtractResponseBody(res)
|
|
979
922
|
}
|
|
980
923
|
});
|
|
981
924
|
}
|
|
@@ -1008,16 +951,16 @@ var stacksApi = {
|
|
|
1008
951
|
};
|
|
1009
952
|
|
|
1010
953
|
// src/stacks-rpc-api/smart-contracts/map-entry.ts
|
|
1011
|
-
var
|
|
1012
|
-
var mapEntryResponseSchema =
|
|
954
|
+
var v9 = __toESM(require("valibot"), 1);
|
|
955
|
+
var mapEntryResponseSchema = v9.object({
|
|
1013
956
|
/**
|
|
1014
957
|
* Hex-encoded string of clarity value. It is always an optional tuple.
|
|
1015
958
|
*/
|
|
1016
|
-
data:
|
|
959
|
+
data: v9.string(),
|
|
1017
960
|
/**
|
|
1018
961
|
* Hex-encoded string of the MARF proof for the data
|
|
1019
962
|
*/
|
|
1020
|
-
proof:
|
|
963
|
+
proof: v9.optional(v9.string())
|
|
1021
964
|
});
|
|
1022
965
|
async function mapEntry(args) {
|
|
1023
966
|
const search = new URLSearchParams();
|
|
@@ -1045,7 +988,7 @@ async function mapEntry(args) {
|
|
|
1045
988
|
status: res.status,
|
|
1046
989
|
statusText: res.statusText,
|
|
1047
990
|
endpoint,
|
|
1048
|
-
|
|
991
|
+
body: await safeExtractResponseBody(res)
|
|
1049
992
|
}
|
|
1050
993
|
});
|
|
1051
994
|
}
|
|
@@ -1057,7 +1000,7 @@ async function mapEntry(args) {
|
|
|
1057
1000
|
data: jsonError
|
|
1058
1001
|
});
|
|
1059
1002
|
}
|
|
1060
|
-
const validationResult =
|
|
1003
|
+
const validationResult = v9.safeParse(mapEntryResponseSchema, data);
|
|
1061
1004
|
if (!validationResult.success) {
|
|
1062
1005
|
return error({
|
|
1063
1006
|
name: "ValidateDataError",
|
|
@@ -1093,7 +1036,7 @@ async function readOnly(args) {
|
|
|
1093
1036
|
data: {
|
|
1094
1037
|
status: res.status,
|
|
1095
1038
|
statusText: res.statusText,
|
|
1096
|
-
|
|
1039
|
+
body: await safeExtractResponseBody(res)
|
|
1097
1040
|
}
|
|
1098
1041
|
});
|
|
1099
1042
|
}
|
|
@@ -1130,7 +1073,7 @@ async function contractInterface(args) {
|
|
|
1130
1073
|
status: res.status,
|
|
1131
1074
|
statusText: res.statusText,
|
|
1132
1075
|
endpoint,
|
|
1133
|
-
|
|
1076
|
+
body: await safeExtractResponseBody(res)
|
|
1134
1077
|
}
|
|
1135
1078
|
});
|
|
1136
1079
|
}
|
|
@@ -1168,7 +1111,7 @@ async function poxDetails(args) {
|
|
|
1168
1111
|
data: {
|
|
1169
1112
|
status: res.status,
|
|
1170
1113
|
statusText: res.statusText,
|
|
1171
|
-
|
|
1114
|
+
body: await safeExtractResponseBody(res)
|
|
1172
1115
|
}
|
|
1173
1116
|
});
|
|
1174
1117
|
}
|
|
@@ -1195,18 +1138,18 @@ var stacksRpcApi = {
|
|
|
1195
1138
|
};
|
|
1196
1139
|
|
|
1197
1140
|
// src/utils/call-rate-limited-api.ts
|
|
1198
|
-
var
|
|
1199
|
-
var
|
|
1200
|
-
var
|
|
1141
|
+
var import_exponential_backoff2 = require("exponential-backoff");
|
|
1142
|
+
var defaultStartingDelay2 = 15e3;
|
|
1143
|
+
var defaultNumOfAttempts2 = 5;
|
|
1201
1144
|
function callRateLimitedApi(fn, options) {
|
|
1202
|
-
return (0,
|
|
1203
|
-
startingDelay: options?.startingDelay ??
|
|
1204
|
-
numOfAttempts: options?.numOfAttempts ??
|
|
1145
|
+
return (0, import_exponential_backoff2.backOff)(fn, {
|
|
1146
|
+
startingDelay: options?.startingDelay ?? defaultStartingDelay2,
|
|
1147
|
+
numOfAttempts: options?.numOfAttempts ?? defaultNumOfAttempts2
|
|
1205
1148
|
});
|
|
1206
1149
|
}
|
|
1207
1150
|
async function safeCallRateLimitedApi(fn, options) {
|
|
1208
1151
|
try {
|
|
1209
|
-
return await (0,
|
|
1152
|
+
return await (0, import_exponential_backoff2.backOff)(
|
|
1210
1153
|
async () => {
|
|
1211
1154
|
const [error2, data] = await fn();
|
|
1212
1155
|
if (error2) {
|
|
@@ -1422,10 +1365,13 @@ var pox4Api = { maps, readOnly: readOnly2 };
|
|
|
1422
1365
|
0 && (module.exports = {
|
|
1423
1366
|
callRateLimitedApi,
|
|
1424
1367
|
error,
|
|
1368
|
+
flatResults,
|
|
1425
1369
|
pox4Api,
|
|
1426
1370
|
queries,
|
|
1371
|
+
safeBackOff,
|
|
1427
1372
|
safeCall,
|
|
1428
1373
|
safeCallRateLimitedApi,
|
|
1374
|
+
safeExtractResponseBody,
|
|
1429
1375
|
safePromise,
|
|
1430
1376
|
stacksApi,
|
|
1431
1377
|
stacksRpcApi,
|