@secretkeylabs/stacks-tools 0.6.0-6e4e19c → 0.6.0-9c72bfd
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 +88 -85
- package/dist/index.d.cts +22 -487
- package/dist/index.d.ts +22 -487
- package/dist/index.js +85 -82
- 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,8 +28,8 @@ 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
35
|
pox4Api: () => pox4Api,
|
|
@@ -41,7 +41,7 @@ __export(src_exports, {
|
|
|
41
41
|
stacksRpcApi: () => stacksRpcApi,
|
|
42
42
|
success: () => success
|
|
43
43
|
});
|
|
44
|
-
module.exports = __toCommonJS(
|
|
44
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
45
|
|
|
46
46
|
// src/utils/safe.ts
|
|
47
47
|
function success(data) {
|
|
@@ -705,6 +705,80 @@ var stackingPool = {
|
|
|
705
705
|
members
|
|
706
706
|
};
|
|
707
707
|
|
|
708
|
+
// src/stacks-api/transactions/address-transactions.ts
|
|
709
|
+
async function addressTransactions(args) {
|
|
710
|
+
const search = new URLSearchParams();
|
|
711
|
+
if (args.limit) search.append("limit", args.limit.toString());
|
|
712
|
+
if (args.offset) search.append("offset", args.offset.toString());
|
|
713
|
+
const init = {};
|
|
714
|
+
if (args.apiKeyConfig) {
|
|
715
|
+
init.headers = {
|
|
716
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
const res = await fetch(
|
|
720
|
+
`${args.baseUrl}/extended/v2/addresses/${args.address}/transactions?${search}`,
|
|
721
|
+
init
|
|
722
|
+
);
|
|
723
|
+
if (!res.ok) {
|
|
724
|
+
return error({
|
|
725
|
+
name: "FetchAddressTransactionsError",
|
|
726
|
+
message: "Failed to fetch address transactions.",
|
|
727
|
+
data: {
|
|
728
|
+
status: res.status,
|
|
729
|
+
statusText: res.statusText,
|
|
730
|
+
bodyText: await safePromise(res.text())
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
const [jsonParseError, data] = await safePromise(res.json());
|
|
735
|
+
if (jsonParseError) {
|
|
736
|
+
return error({
|
|
737
|
+
name: "ParseBodyError",
|
|
738
|
+
message: "Failed to parse response body as JSON.",
|
|
739
|
+
data: jsonParseError
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
return success(data);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// src/stacks-api/transactions/events-for-an-address-transaction.ts
|
|
746
|
+
async function eventsForAnAddressTransaction(args) {
|
|
747
|
+
const search = new URLSearchParams();
|
|
748
|
+
if (args.limit) search.append("limit", args.limit.toString());
|
|
749
|
+
if (args.offset) search.append("offset", args.offset.toString());
|
|
750
|
+
const init = {};
|
|
751
|
+
if (args.apiKeyConfig) {
|
|
752
|
+
init.headers = {
|
|
753
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
const endpoint = `${args.baseUrl}/extended/v2/addresses/${args.address}/transactions/${args.transactionId}/events?${search}`;
|
|
757
|
+
const res = await fetch(endpoint, init);
|
|
758
|
+
if (!res.ok) {
|
|
759
|
+
return error({
|
|
760
|
+
name: "FetchEventsForAnAddressTransactionError",
|
|
761
|
+
message: `Failed to fetch address transaction events.`,
|
|
762
|
+
data: {
|
|
763
|
+
address: args.address,
|
|
764
|
+
transactionId: args.transactionId,
|
|
765
|
+
status: res.status,
|
|
766
|
+
statusText: res.statusText,
|
|
767
|
+
bodyText: await safePromise(res.text())
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
const [jsonParseError, data] = await safePromise(res.json());
|
|
772
|
+
if (jsonParseError) {
|
|
773
|
+
return error({
|
|
774
|
+
name: "ParseBodyError",
|
|
775
|
+
message: "Failed to parse response body as JSON.",
|
|
776
|
+
error: jsonParseError
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
return success(data);
|
|
780
|
+
}
|
|
781
|
+
|
|
708
782
|
// src/stacks-api/transactions/schemas.ts
|
|
709
783
|
var v11 = __toESM(require("valibot"), 1);
|
|
710
784
|
var baseTransactionSchema = v11.object({
|
|
@@ -794,81 +868,8 @@ var transactionSchema = v11.variant("tx_type", [
|
|
|
794
868
|
tokenTransferSchema
|
|
795
869
|
]);
|
|
796
870
|
|
|
797
|
-
// 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
|
-
async function addressTransactions(args) {
|
|
827
|
-
const search = new URLSearchParams();
|
|
828
|
-
if (args.limit) search.append("limit", args.limit.toString());
|
|
829
|
-
if (args.offset) search.append("offset", args.offset.toString());
|
|
830
|
-
const init = {};
|
|
831
|
-
if (args.apiKeyConfig) {
|
|
832
|
-
init.headers = {
|
|
833
|
-
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
const res = await fetch(
|
|
837
|
-
`${args.baseUrl}/extended/v2/addresses/${args.address}/transactions?${search}`,
|
|
838
|
-
init
|
|
839
|
-
);
|
|
840
|
-
if (!res.ok) {
|
|
841
|
-
return error({
|
|
842
|
-
name: "FetchAddressTransactionsError",
|
|
843
|
-
message: "Failed to fetch address transactions.",
|
|
844
|
-
data: {
|
|
845
|
-
status: res.status,
|
|
846
|
-
statusText: res.statusText,
|
|
847
|
-
bodyText: await safePromise(res.text())
|
|
848
|
-
}
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
const [jsonParseError, data] = await safePromise(res.json());
|
|
852
|
-
if (jsonParseError) {
|
|
853
|
-
return error({
|
|
854
|
-
name: "ParseBodyError",
|
|
855
|
-
message: "Failed to parse response body as JSON.",
|
|
856
|
-
data: jsonParseError
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
const validationResult = v12.safeParse(addressTransactionsResponseSchema, data);
|
|
860
|
-
if (!validationResult.success) {
|
|
861
|
-
return error({
|
|
862
|
-
name: "ValidateDataError",
|
|
863
|
-
message: "Failed to validate data.",
|
|
864
|
-
data: validationResult
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
return success(validationResult.output);
|
|
868
|
-
}
|
|
869
|
-
|
|
870
871
|
// src/stacks-api/transactions/get-transaction.ts
|
|
871
|
-
var
|
|
872
|
+
var v12 = __toESM(require("valibot"), 1);
|
|
872
873
|
async function getTransaction(args) {
|
|
873
874
|
const init = {};
|
|
874
875
|
if (args.apiKeyConfig) {
|
|
@@ -881,8 +882,9 @@ async function getTransaction(args) {
|
|
|
881
882
|
if (!res.ok) {
|
|
882
883
|
return error({
|
|
883
884
|
name: "FetchTransactionError",
|
|
884
|
-
message: `Failed to fetch transaction
|
|
885
|
-
|
|
885
|
+
message: `Failed to fetch transaction.`,
|
|
886
|
+
data: {
|
|
887
|
+
transactionId: args.transactionId,
|
|
886
888
|
status: res.status,
|
|
887
889
|
statusText: res.statusText,
|
|
888
890
|
bodyText: await safePromise(res.text())
|
|
@@ -897,7 +899,7 @@ async function getTransaction(args) {
|
|
|
897
899
|
error: jsonParseError
|
|
898
900
|
});
|
|
899
901
|
}
|
|
900
|
-
const validationResult =
|
|
902
|
+
const validationResult = v12.safeParse(transactionSchema, data);
|
|
901
903
|
if (!validationResult.success) {
|
|
902
904
|
return error({
|
|
903
905
|
name: "ValidateDataError",
|
|
@@ -954,6 +956,7 @@ async function mempoolTransactions(args) {
|
|
|
954
956
|
// src/stacks-api/transactions/index.ts
|
|
955
957
|
var transactions = {
|
|
956
958
|
addressTransactions,
|
|
959
|
+
eventsForAnAddressTransaction,
|
|
957
960
|
getTransaction,
|
|
958
961
|
mempoolTransactions
|
|
959
962
|
};
|
|
@@ -1008,16 +1011,16 @@ var stacksApi = {
|
|
|
1008
1011
|
};
|
|
1009
1012
|
|
|
1010
1013
|
// src/stacks-rpc-api/smart-contracts/map-entry.ts
|
|
1011
|
-
var
|
|
1012
|
-
var mapEntryResponseSchema =
|
|
1014
|
+
var v13 = __toESM(require("valibot"), 1);
|
|
1015
|
+
var mapEntryResponseSchema = v13.object({
|
|
1013
1016
|
/**
|
|
1014
1017
|
* Hex-encoded string of clarity value. It is always an optional tuple.
|
|
1015
1018
|
*/
|
|
1016
|
-
data:
|
|
1019
|
+
data: v13.string(),
|
|
1017
1020
|
/**
|
|
1018
1021
|
* Hex-encoded string of the MARF proof for the data
|
|
1019
1022
|
*/
|
|
1020
|
-
proof:
|
|
1023
|
+
proof: v13.optional(v13.string())
|
|
1021
1024
|
});
|
|
1022
1025
|
async function mapEntry(args) {
|
|
1023
1026
|
const search = new URLSearchParams();
|
|
@@ -1057,7 +1060,7 @@ async function mapEntry(args) {
|
|
|
1057
1060
|
data: jsonError
|
|
1058
1061
|
});
|
|
1059
1062
|
}
|
|
1060
|
-
const validationResult =
|
|
1063
|
+
const validationResult = v13.safeParse(mapEntryResponseSchema, data);
|
|
1061
1064
|
if (!validationResult.success) {
|
|
1062
1065
|
return error({
|
|
1063
1066
|
name: "ValidateDataError",
|