@secretkeylabs/stacks-tools 0.4.0 → 0.5.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/index.cjs +391 -194
- package/dist/index.d.cts +202 -127
- package/dist/index.d.ts +202 -127
- package/dist/index.js +389 -194
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -151,6 +151,12 @@ async function latestNonce(opts) {
|
|
|
151
151
|
return success(validationResult.output);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
// src/stacks-api/accounts/index.ts
|
|
155
|
+
var accounts = {
|
|
156
|
+
balances,
|
|
157
|
+
latestNonce
|
|
158
|
+
};
|
|
159
|
+
|
|
154
160
|
// src/stacks-api/types.ts
|
|
155
161
|
import * as v3 from "valibot";
|
|
156
162
|
var baseListResponseSchema = v3.object({
|
|
@@ -224,6 +230,52 @@ async function getBlock(opts) {
|
|
|
224
230
|
return success(validationResult.output);
|
|
225
231
|
}
|
|
226
232
|
|
|
233
|
+
// src/stacks-api/blocks/index.ts
|
|
234
|
+
var blocks = {
|
|
235
|
+
getBlock
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// src/stacks-api/faucets/stx.ts
|
|
239
|
+
async function stx(opts) {
|
|
240
|
+
const search = new URLSearchParams();
|
|
241
|
+
search.append("address", opts.address);
|
|
242
|
+
if (opts.stacking) search.append("stacking", "true");
|
|
243
|
+
const init = {};
|
|
244
|
+
if (opts.apiKeyConfig) {
|
|
245
|
+
init.headers = {
|
|
246
|
+
[opts.apiKeyConfig.header]: opts.apiKeyConfig.key
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
init.method = "POST";
|
|
250
|
+
const endpoint = `${opts.baseUrl}/extended/v1/faucets/stx?${search}`;
|
|
251
|
+
const res = await fetch(endpoint, init);
|
|
252
|
+
if (!res.ok) {
|
|
253
|
+
return error({
|
|
254
|
+
name: "FetchStxError",
|
|
255
|
+
message: "Failed to fetch STX.",
|
|
256
|
+
data: {
|
|
257
|
+
status: res.status,
|
|
258
|
+
statusText: res.statusText,
|
|
259
|
+
bodyParseResult: await safePromise(res.json())
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
const [jsonError, data] = await safePromise(res.json());
|
|
264
|
+
if (jsonError) {
|
|
265
|
+
return error({
|
|
266
|
+
name: "ParseBodyError",
|
|
267
|
+
message: "Failed to parse response body as JSON.",
|
|
268
|
+
data: jsonError
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return success(data);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/stacks-api/faucets/index.ts
|
|
275
|
+
var faucets = {
|
|
276
|
+
stx
|
|
277
|
+
};
|
|
278
|
+
|
|
227
279
|
// src/stacks-api/info/core-api.ts
|
|
228
280
|
import * as v5 from "valibot";
|
|
229
281
|
var CoreApiResponseSchema = v5.object({
|
|
@@ -376,6 +428,12 @@ async function poxDetails(args) {
|
|
|
376
428
|
return success(validationResult.output);
|
|
377
429
|
}
|
|
378
430
|
|
|
431
|
+
// src/stacks-api/info/index.ts
|
|
432
|
+
var info = {
|
|
433
|
+
coreApi,
|
|
434
|
+
poxDetails
|
|
435
|
+
};
|
|
436
|
+
|
|
379
437
|
// src/stacks-api/proof-of-transfer/cycle.ts
|
|
380
438
|
import * as v7 from "valibot";
|
|
381
439
|
var responseSchema4 = v7.object({
|
|
@@ -664,100 +722,45 @@ async function stackersForSignerInCycle(opts) {
|
|
|
664
722
|
return success(validationResult.output);
|
|
665
723
|
}
|
|
666
724
|
|
|
667
|
-
// src/stacks-api/
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
result: v12.string()
|
|
676
|
-
}),
|
|
677
|
-
v12.object({
|
|
678
|
-
okay: v12.literal(false),
|
|
679
|
-
cause: v12.unknown()
|
|
680
|
-
})
|
|
681
|
-
]);
|
|
682
|
-
async function readOnly(args) {
|
|
683
|
-
const headers = {
|
|
684
|
-
"Content-Type": "application/json"
|
|
685
|
-
};
|
|
686
|
-
if (args.apiKeyConfig) {
|
|
687
|
-
headers[args.apiKeyConfig.header] = args.apiKeyConfig.key;
|
|
688
|
-
}
|
|
689
|
-
const init = {
|
|
690
|
-
method: "POST",
|
|
691
|
-
body: JSON.stringify({
|
|
692
|
-
sender: args.sender,
|
|
693
|
-
arguments: args.arguments
|
|
694
|
-
}),
|
|
695
|
-
headers
|
|
696
|
-
};
|
|
697
|
-
const endpoint = `${args.baseUrl}/v2/contracts/call-read/${args.contractAddress}/${args.contractName}/${args.functionName}`;
|
|
698
|
-
const res = await fetch(endpoint, init);
|
|
699
|
-
if (!res.ok) {
|
|
700
|
-
return error({
|
|
701
|
-
name: "FetchReadOnlyError",
|
|
702
|
-
message: "Failed to fetch.",
|
|
703
|
-
data: {
|
|
704
|
-
status: res.status,
|
|
705
|
-
statusText: res.statusText,
|
|
706
|
-
bodyParseResult: await safePromise(res.json())
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
const [jsonError, data] = await safePromise(res.json());
|
|
711
|
-
if (jsonError) {
|
|
712
|
-
return error({
|
|
713
|
-
name: "ParseBodyError",
|
|
714
|
-
message: "Failed to parse response body as JSON.",
|
|
715
|
-
data: error
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
const validationResult = v12.safeParse(readOnlyResponseSchema, data);
|
|
719
|
-
if (!validationResult.success) {
|
|
720
|
-
return error({
|
|
721
|
-
name: "ValidateDataError",
|
|
722
|
-
message: "Failed to validate data.",
|
|
723
|
-
data: validationResult
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
return success(validationResult.output);
|
|
727
|
-
}
|
|
725
|
+
// src/stacks-api/proof-of-transfer/index.ts
|
|
726
|
+
var proofOfTransfer = {
|
|
727
|
+
cycle,
|
|
728
|
+
cycles,
|
|
729
|
+
signerInCycle,
|
|
730
|
+
signersInCycle,
|
|
731
|
+
stackersForSignerInCycle
|
|
732
|
+
};
|
|
728
733
|
|
|
729
734
|
// src/stacks-api/stacking-pool/members.ts
|
|
730
|
-
import * as
|
|
731
|
-
var memberSchema =
|
|
732
|
-
stacker:
|
|
733
|
-
pox_addr:
|
|
734
|
-
amount_ustx:
|
|
735
|
-
burn_block_unlock_height:
|
|
736
|
-
block_height:
|
|
737
|
-
tx_id:
|
|
735
|
+
import * as v12 from "valibot";
|
|
736
|
+
var memberSchema = v12.object({
|
|
737
|
+
stacker: v12.string(),
|
|
738
|
+
pox_addr: v12.optional(v12.string()),
|
|
739
|
+
amount_ustx: v12.string(),
|
|
740
|
+
burn_block_unlock_height: v12.optional(v12.number()),
|
|
741
|
+
block_height: v12.number(),
|
|
742
|
+
tx_id: v12.string()
|
|
738
743
|
});
|
|
739
|
-
var membersResponseSchema =
|
|
740
|
-
limit:
|
|
741
|
-
offset:
|
|
742
|
-
total:
|
|
743
|
-
results:
|
|
744
|
+
var membersResponseSchema = v12.object({
|
|
745
|
+
limit: v12.number(),
|
|
746
|
+
offset: v12.number(),
|
|
747
|
+
total: v12.number(),
|
|
748
|
+
results: v12.array(memberSchema)
|
|
744
749
|
});
|
|
745
|
-
async function members(
|
|
750
|
+
async function members(args) {
|
|
746
751
|
const search = new URLSearchParams();
|
|
747
|
-
if (
|
|
748
|
-
if (
|
|
749
|
-
if (
|
|
750
|
-
if (
|
|
752
|
+
if (args.afterBlock) search.append("after_block", args.afterBlock.toString());
|
|
753
|
+
if (args.unanchored) search.append("unanchored", "true");
|
|
754
|
+
if (args.limit) search.append("limit", args.limit.toString());
|
|
755
|
+
if (args.offset) search.append("offset", args.offset.toString());
|
|
751
756
|
const init = {};
|
|
752
|
-
if (
|
|
757
|
+
if (args.apiKeyConfig) {
|
|
753
758
|
init.headers = {
|
|
754
|
-
[
|
|
759
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
755
760
|
};
|
|
756
761
|
}
|
|
757
|
-
const
|
|
758
|
-
|
|
759
|
-
init
|
|
760
|
-
);
|
|
762
|
+
const endpoint = `${args.baseUrl}/extended/v1/pox4/${args.poolPrincipal}/delegations?${search}`;
|
|
763
|
+
const res = await fetch(endpoint, init);
|
|
761
764
|
if (!res.ok) {
|
|
762
765
|
return error({
|
|
763
766
|
name: "FetchMembersError",
|
|
@@ -777,7 +780,7 @@ async function members(opts, apiOpts) {
|
|
|
777
780
|
data: jsonParseError
|
|
778
781
|
});
|
|
779
782
|
}
|
|
780
|
-
const validationResult =
|
|
783
|
+
const validationResult = v12.safeParse(membersResponseSchema, data);
|
|
781
784
|
if (!validationResult.success) {
|
|
782
785
|
return error({
|
|
783
786
|
name: "ValidateDataError",
|
|
@@ -788,121 +791,126 @@ async function members(opts, apiOpts) {
|
|
|
788
791
|
return success(validationResult.output);
|
|
789
792
|
}
|
|
790
793
|
|
|
794
|
+
// src/stacks-api/stacking-pool/index.ts
|
|
795
|
+
var stackingPool = {
|
|
796
|
+
members
|
|
797
|
+
};
|
|
798
|
+
|
|
791
799
|
// src/stacks-api/transactions/schemas.ts
|
|
792
|
-
import * as
|
|
793
|
-
var baseTransactionSchema =
|
|
794
|
-
tx_id:
|
|
795
|
-
nonce:
|
|
796
|
-
fee_rate:
|
|
797
|
-
sender_address:
|
|
798
|
-
sponsored:
|
|
799
|
-
post_condition_mode:
|
|
800
|
-
post_conditions:
|
|
801
|
-
anchor_mode:
|
|
802
|
-
is_unanchored:
|
|
803
|
-
block_hash:
|
|
804
|
-
parent_block_hash:
|
|
805
|
-
block_height:
|
|
806
|
-
block_time:
|
|
807
|
-
block_time_iso:
|
|
808
|
-
burn_block_height:
|
|
809
|
-
burn_block_time:
|
|
810
|
-
burn_block_time_iso:
|
|
811
|
-
parent_burn_block_time:
|
|
812
|
-
parent_burn_block_time_iso:
|
|
813
|
-
canonical:
|
|
814
|
-
tx_index:
|
|
815
|
-
tx_status:
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
800
|
+
import * as v13 from "valibot";
|
|
801
|
+
var baseTransactionSchema = v13.object({
|
|
802
|
+
tx_id: v13.string(),
|
|
803
|
+
nonce: v13.number(),
|
|
804
|
+
fee_rate: v13.string(),
|
|
805
|
+
sender_address: v13.string(),
|
|
806
|
+
sponsored: v13.boolean(),
|
|
807
|
+
post_condition_mode: v13.string(),
|
|
808
|
+
post_conditions: v13.array(v13.unknown()),
|
|
809
|
+
anchor_mode: v13.string(),
|
|
810
|
+
is_unanchored: v13.boolean(),
|
|
811
|
+
block_hash: v13.string(),
|
|
812
|
+
parent_block_hash: v13.string(),
|
|
813
|
+
block_height: v13.number(),
|
|
814
|
+
block_time: v13.number(),
|
|
815
|
+
block_time_iso: v13.string(),
|
|
816
|
+
burn_block_height: v13.number(),
|
|
817
|
+
burn_block_time: v13.number(),
|
|
818
|
+
burn_block_time_iso: v13.string(),
|
|
819
|
+
parent_burn_block_time: v13.number(),
|
|
820
|
+
parent_burn_block_time_iso: v13.string(),
|
|
821
|
+
canonical: v13.boolean(),
|
|
822
|
+
tx_index: v13.number(),
|
|
823
|
+
tx_status: v13.union([
|
|
824
|
+
v13.literal("success"),
|
|
825
|
+
v13.literal("abort_by_response"),
|
|
826
|
+
v13.literal("abort_by_post_condition")
|
|
819
827
|
]),
|
|
820
|
-
tx_result:
|
|
821
|
-
hex:
|
|
822
|
-
repr:
|
|
828
|
+
tx_result: v13.object({
|
|
829
|
+
hex: v13.string(),
|
|
830
|
+
repr: v13.string()
|
|
823
831
|
}),
|
|
824
|
-
microblock_hash:
|
|
825
|
-
microblock_sequence:
|
|
826
|
-
microblock_canonical:
|
|
827
|
-
event_count:
|
|
828
|
-
events:
|
|
829
|
-
execution_cost_read_count:
|
|
830
|
-
execution_cost_read_length:
|
|
831
|
-
execution_cost_runtime:
|
|
832
|
-
execution_cost_write_count:
|
|
833
|
-
execution_cost_write_length:
|
|
832
|
+
microblock_hash: v13.string(),
|
|
833
|
+
microblock_sequence: v13.number(),
|
|
834
|
+
microblock_canonical: v13.boolean(),
|
|
835
|
+
event_count: v13.number(),
|
|
836
|
+
events: v13.array(v13.unknown()),
|
|
837
|
+
execution_cost_read_count: v13.number(),
|
|
838
|
+
execution_cost_read_length: v13.number(),
|
|
839
|
+
execution_cost_runtime: v13.number(),
|
|
840
|
+
execution_cost_write_count: v13.number(),
|
|
841
|
+
execution_cost_write_length: v13.number()
|
|
834
842
|
});
|
|
835
|
-
var contractCallTransactionSchema =
|
|
836
|
-
tx_type:
|
|
837
|
-
contract_call:
|
|
838
|
-
contract_id:
|
|
839
|
-
function_name:
|
|
840
|
-
function_signature:
|
|
841
|
-
function_args:
|
|
842
|
-
|
|
843
|
-
hex:
|
|
844
|
-
repr:
|
|
845
|
-
name:
|
|
846
|
-
type:
|
|
843
|
+
var contractCallTransactionSchema = v13.object({
|
|
844
|
+
tx_type: v13.literal("contract_call"),
|
|
845
|
+
contract_call: v13.object({
|
|
846
|
+
contract_id: v13.string(),
|
|
847
|
+
function_name: v13.string(),
|
|
848
|
+
function_signature: v13.string(),
|
|
849
|
+
function_args: v13.array(
|
|
850
|
+
v13.object({
|
|
851
|
+
hex: v13.string(),
|
|
852
|
+
repr: v13.string(),
|
|
853
|
+
name: v13.string(),
|
|
854
|
+
type: v13.string()
|
|
847
855
|
})
|
|
848
856
|
)
|
|
849
857
|
}),
|
|
850
858
|
...baseTransactionSchema.entries
|
|
851
859
|
});
|
|
852
|
-
var smartContractTransactionSchema =
|
|
853
|
-
tx_type:
|
|
854
|
-
smart_contract:
|
|
860
|
+
var smartContractTransactionSchema = v13.object({
|
|
861
|
+
tx_type: v13.literal("smart_contract"),
|
|
862
|
+
smart_contract: v13.object({
|
|
855
863
|
/**
|
|
856
864
|
* NOTE: The types may be wrong, not sure what type of value is used when
|
|
857
865
|
* the version is not `null`.
|
|
858
866
|
*/
|
|
859
|
-
clarity_version:
|
|
860
|
-
contract_id:
|
|
861
|
-
source_code:
|
|
867
|
+
clarity_version: v13.union([v13.null(), v13.number()]),
|
|
868
|
+
contract_id: v13.string(),
|
|
869
|
+
source_code: v13.string()
|
|
862
870
|
}),
|
|
863
871
|
...baseTransactionSchema.entries
|
|
864
872
|
});
|
|
865
|
-
var tokenTransferSchema =
|
|
866
|
-
tx_type:
|
|
867
|
-
token_transfer:
|
|
868
|
-
recipient_address:
|
|
869
|
-
amount:
|
|
870
|
-
memo:
|
|
873
|
+
var tokenTransferSchema = v13.object({
|
|
874
|
+
tx_type: v13.literal("token_transfer"),
|
|
875
|
+
token_transfer: v13.object({
|
|
876
|
+
recipient_address: v13.string(),
|
|
877
|
+
amount: v13.string(),
|
|
878
|
+
memo: v13.string()
|
|
871
879
|
}),
|
|
872
880
|
...baseTransactionSchema.entries
|
|
873
881
|
});
|
|
874
|
-
var transactionSchema =
|
|
882
|
+
var transactionSchema = v13.variant("tx_type", [
|
|
875
883
|
contractCallTransactionSchema,
|
|
876
884
|
smartContractTransactionSchema,
|
|
877
885
|
tokenTransferSchema
|
|
878
886
|
]);
|
|
879
887
|
|
|
880
888
|
// src/stacks-api/transactions/address-transactions.ts
|
|
881
|
-
import * as
|
|
882
|
-
var resultSchema =
|
|
889
|
+
import * as v14 from "valibot";
|
|
890
|
+
var resultSchema = v14.object({
|
|
883
891
|
tx: transactionSchema,
|
|
884
|
-
stx_sent:
|
|
885
|
-
stx_received:
|
|
886
|
-
events:
|
|
887
|
-
stx:
|
|
888
|
-
transfer:
|
|
889
|
-
mint:
|
|
890
|
-
burn:
|
|
892
|
+
stx_sent: v14.string(),
|
|
893
|
+
stx_received: v14.string(),
|
|
894
|
+
events: v14.object({
|
|
895
|
+
stx: v14.object({
|
|
896
|
+
transfer: v14.number(),
|
|
897
|
+
mint: v14.number(),
|
|
898
|
+
burn: v14.number()
|
|
891
899
|
}),
|
|
892
|
-
ft:
|
|
893
|
-
transfer:
|
|
894
|
-
mint:
|
|
895
|
-
burn:
|
|
900
|
+
ft: v14.object({
|
|
901
|
+
transfer: v14.number(),
|
|
902
|
+
mint: v14.number(),
|
|
903
|
+
burn: v14.number()
|
|
896
904
|
}),
|
|
897
|
-
nft:
|
|
898
|
-
transfer:
|
|
899
|
-
mint:
|
|
900
|
-
burn:
|
|
905
|
+
nft: v14.object({
|
|
906
|
+
transfer: v14.number(),
|
|
907
|
+
mint: v14.number(),
|
|
908
|
+
burn: v14.number()
|
|
901
909
|
})
|
|
902
910
|
})
|
|
903
911
|
});
|
|
904
|
-
var resultsSchema4 =
|
|
905
|
-
var addressTransactionsResponseSchema =
|
|
912
|
+
var resultsSchema4 = v14.array(resultSchema);
|
|
913
|
+
var addressTransactionsResponseSchema = v14.object({
|
|
906
914
|
...baseListResponseSchema.entries,
|
|
907
915
|
results: resultsSchema4
|
|
908
916
|
});
|
|
@@ -939,7 +947,7 @@ async function addressTransactions(args) {
|
|
|
939
947
|
data: jsonParseError
|
|
940
948
|
});
|
|
941
949
|
}
|
|
942
|
-
const validationResult =
|
|
950
|
+
const validationResult = v14.safeParse(addressTransactionsResponseSchema, data);
|
|
943
951
|
if (!validationResult.success) {
|
|
944
952
|
return error({
|
|
945
953
|
name: "ValidateDataError",
|
|
@@ -951,7 +959,7 @@ async function addressTransactions(args) {
|
|
|
951
959
|
}
|
|
952
960
|
|
|
953
961
|
// src/stacks-api/transactions/get-transaction.ts
|
|
954
|
-
import * as
|
|
962
|
+
import * as v15 from "valibot";
|
|
955
963
|
async function getTransaction(args) {
|
|
956
964
|
const init = {};
|
|
957
965
|
if (args.apiKeyConfig) {
|
|
@@ -980,7 +988,7 @@ async function getTransaction(args) {
|
|
|
980
988
|
error: jsonParseError
|
|
981
989
|
});
|
|
982
990
|
}
|
|
983
|
-
const validationResult =
|
|
991
|
+
const validationResult = v15.safeParse(transactionSchema, data);
|
|
984
992
|
if (!validationResult.success) {
|
|
985
993
|
return error({
|
|
986
994
|
name: "ValidateDataError",
|
|
@@ -991,20 +999,156 @@ async function getTransaction(args) {
|
|
|
991
999
|
return success(validationResult.output);
|
|
992
1000
|
}
|
|
993
1001
|
|
|
1002
|
+
// src/stacks-api/transactions/index.ts
|
|
1003
|
+
var transactions = {
|
|
1004
|
+
addressTransactions,
|
|
1005
|
+
getTransaction
|
|
1006
|
+
};
|
|
1007
|
+
|
|
994
1008
|
// src/stacks-api/index.ts
|
|
995
|
-
var
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1009
|
+
var stacksApi = {
|
|
1010
|
+
accounts,
|
|
1011
|
+
blocks,
|
|
1012
|
+
faucets,
|
|
1013
|
+
info,
|
|
1014
|
+
proofOfTransfer,
|
|
1015
|
+
stackingPool,
|
|
1016
|
+
transactions
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
// src/stacks-rpc-api/smart-contracts/map-entry.ts
|
|
1020
|
+
import * as v16 from "valibot";
|
|
1021
|
+
var mapEntryResponseSchema = v16.object({
|
|
1022
|
+
/**
|
|
1023
|
+
* Hex-encoded string of clarity value. It is always an optional tuple.
|
|
1024
|
+
*/
|
|
1025
|
+
data: v16.string(),
|
|
1026
|
+
/**
|
|
1027
|
+
* Hex-encoded string of the MARF proof for the data
|
|
1028
|
+
*/
|
|
1029
|
+
proof: v16.optional(v16.string())
|
|
1030
|
+
});
|
|
1031
|
+
async function mapEntry(args) {
|
|
1032
|
+
const search = new URLSearchParams();
|
|
1033
|
+
if (args.proof === 0) search.append("proof", "0");
|
|
1034
|
+
if (args.tip) search.append("tip", args.tip);
|
|
1035
|
+
const init = {};
|
|
1036
|
+
if (args.apiKeyConfig) {
|
|
1037
|
+
init.headers = {
|
|
1038
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
init.method = "POST";
|
|
1042
|
+
init.body = JSON.stringify(
|
|
1043
|
+
args.mapKey.startsWith("0x") ? args.mapKey : `0x${args.mapKey}`
|
|
1044
|
+
);
|
|
1045
|
+
init.headers = { ...init.headers, "Content-Type": "application/json" };
|
|
1046
|
+
const endpoint = `${args.baseUrl}/v2/map_entry/${args.contractAddress}/${args.contractName}/${args.mapName}?${search}`;
|
|
1047
|
+
const res = await fetch(endpoint, init);
|
|
1048
|
+
if (!res.ok) {
|
|
1049
|
+
return error({
|
|
1050
|
+
name: "FetchMapEntryError",
|
|
1051
|
+
message: "Failed to fetch map entry.",
|
|
1052
|
+
data: {
|
|
1053
|
+
init,
|
|
1054
|
+
status: res.status,
|
|
1055
|
+
statusText: res.statusText,
|
|
1056
|
+
endpoint,
|
|
1057
|
+
bodyParseResult: await safePromise(res.text())
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
const [jsonError, data] = await safePromise(res.json());
|
|
1062
|
+
if (jsonError) {
|
|
1063
|
+
return error({
|
|
1064
|
+
name: "ParseBodyError",
|
|
1065
|
+
message: "Failed to parse response body as JSON.",
|
|
1066
|
+
data: jsonError
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
const validationResult = v16.safeParse(mapEntryResponseSchema, data);
|
|
1070
|
+
if (!validationResult.success) {
|
|
1071
|
+
return error({
|
|
1072
|
+
name: "ValidateDataError",
|
|
1073
|
+
message: "Failed to validate response data.",
|
|
1074
|
+
data: validationResult
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
return success(validationResult.output);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// src/stacks-rpc-api/smart-contracts/read-only.ts
|
|
1081
|
+
import * as v17 from "valibot";
|
|
1082
|
+
var readOnlyResponseSchema = v17.variant("okay", [
|
|
1083
|
+
v17.object({
|
|
1084
|
+
okay: v17.literal(true),
|
|
1085
|
+
/**
|
|
1086
|
+
* A Clarity value as a hex-encoded string.
|
|
1087
|
+
*/
|
|
1088
|
+
result: v17.string()
|
|
1089
|
+
}),
|
|
1090
|
+
v17.object({
|
|
1091
|
+
okay: v17.literal(false),
|
|
1092
|
+
cause: v17.unknown()
|
|
1093
|
+
})
|
|
1094
|
+
]);
|
|
1095
|
+
async function readOnly(args) {
|
|
1096
|
+
const headers = {
|
|
1097
|
+
"Content-Type": "application/json"
|
|
1098
|
+
};
|
|
1099
|
+
if (args.apiKeyConfig) {
|
|
1100
|
+
headers[args.apiKeyConfig.header] = args.apiKeyConfig.key;
|
|
1101
|
+
}
|
|
1102
|
+
const init = {
|
|
1103
|
+
method: "POST",
|
|
1104
|
+
body: JSON.stringify({
|
|
1105
|
+
sender: args.sender,
|
|
1106
|
+
arguments: args.arguments
|
|
1107
|
+
}),
|
|
1108
|
+
headers
|
|
1109
|
+
};
|
|
1110
|
+
const endpoint = `${args.baseUrl}/v2/contracts/call-read/${args.contractAddress}/${args.contractName}/${args.functionName}`;
|
|
1111
|
+
const res = await fetch(endpoint, init);
|
|
1112
|
+
if (!res.ok) {
|
|
1113
|
+
return error({
|
|
1114
|
+
name: "FetchReadOnlyError",
|
|
1115
|
+
message: "Failed to fetch.",
|
|
1116
|
+
data: {
|
|
1117
|
+
status: res.status,
|
|
1118
|
+
statusText: res.statusText,
|
|
1119
|
+
bodyParseResult: await safePromise(res.json())
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
const [jsonError, data] = await safePromise(res.json());
|
|
1124
|
+
if (jsonError) {
|
|
1125
|
+
return error({
|
|
1126
|
+
name: "ParseBodyError",
|
|
1127
|
+
message: "Failed to parse response body as JSON.",
|
|
1128
|
+
data: error
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
const validationResult = v17.safeParse(readOnlyResponseSchema, data);
|
|
1132
|
+
if (!validationResult.success) {
|
|
1133
|
+
return error({
|
|
1134
|
+
name: "ValidateDataError",
|
|
1135
|
+
message: "Failed to validate data.",
|
|
1136
|
+
data: validationResult
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
return success(validationResult.output);
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// src/stacks-rpc-api/smart-contracts/index.ts
|
|
1143
|
+
var smartContracts = {
|
|
1144
|
+
mapEntry,
|
|
1145
|
+
readOnly
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
// src/stacks-rpc-api/index.ts
|
|
1149
|
+
var stacksRpcApi = {
|
|
1150
|
+
smartContracts
|
|
1004
1151
|
};
|
|
1005
|
-
var smartContracts = { readOnly };
|
|
1006
|
-
var stackingPool = { members };
|
|
1007
|
-
var transactions = { addressTransactions, getTransaction };
|
|
1008
1152
|
|
|
1009
1153
|
// src/utils/call-rate-limited-api.ts
|
|
1010
1154
|
import { backOff } from "exponential-backoff";
|
|
@@ -1042,22 +1186,73 @@ async function safeCallRateLimitedApi(fn, options) {
|
|
|
1042
1186
|
}
|
|
1043
1187
|
}
|
|
1044
1188
|
|
|
1045
|
-
// src/
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1189
|
+
// src/queries/get-signer-stacked-amount.ts
|
|
1190
|
+
async function getSignerStackedAmount(args) {
|
|
1191
|
+
let totalLocked = 0n;
|
|
1192
|
+
const { identifier, ...rest } = args;
|
|
1193
|
+
let hasMore = true;
|
|
1194
|
+
let offset = 0;
|
|
1195
|
+
let found = false;
|
|
1196
|
+
const limit = 200;
|
|
1197
|
+
while (hasMore && !found) {
|
|
1198
|
+
const [error2, data] = await safeCallRateLimitedApi(
|
|
1199
|
+
() => signersInCycle({
|
|
1200
|
+
...rest,
|
|
1201
|
+
limit
|
|
1202
|
+
})
|
|
1203
|
+
);
|
|
1204
|
+
if (error2) {
|
|
1205
|
+
return error({
|
|
1206
|
+
name: "GetSignerTotalLockedError",
|
|
1207
|
+
message: "Failed to get signer total locked.",
|
|
1208
|
+
data: {
|
|
1209
|
+
error: error2
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
for (const signer of data.results) {
|
|
1214
|
+
if (identifier.type === "address") {
|
|
1215
|
+
if (signer.signer_address === identifier.signerAddress) {
|
|
1216
|
+
totalLocked = BigInt(signer.stacked_amount);
|
|
1217
|
+
found = true;
|
|
1218
|
+
break;
|
|
1219
|
+
}
|
|
1220
|
+
} else {
|
|
1221
|
+
if (signer.signing_key === identifier.signerPublicKey) {
|
|
1222
|
+
totalLocked = BigInt(signer.stacked_amount);
|
|
1223
|
+
found = true;
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
offset += data.results.length;
|
|
1229
|
+
hasMore = offset < data.total;
|
|
1230
|
+
}
|
|
1231
|
+
if (!found) {
|
|
1232
|
+
return error({
|
|
1233
|
+
name: "SignerNotFound",
|
|
1234
|
+
message: "Signer not found.",
|
|
1235
|
+
data: {
|
|
1236
|
+
identifier,
|
|
1237
|
+
cycle: args.cycleNumber
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
return success(totalLocked);
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// src/queries/index.ts
|
|
1245
|
+
var queries = {
|
|
1246
|
+
getSignerStackedAmount
|
|
1054
1247
|
};
|
|
1055
1248
|
export {
|
|
1056
1249
|
callRateLimitedApi,
|
|
1057
1250
|
error,
|
|
1251
|
+
queries,
|
|
1058
1252
|
safeCall,
|
|
1059
1253
|
safeCallRateLimitedApi,
|
|
1060
1254
|
safePromise,
|
|
1061
1255
|
stacksApi,
|
|
1256
|
+
stacksRpcApi,
|
|
1062
1257
|
success
|
|
1063
1258
|
};
|