@secretkeylabs/stacks-tools 0.5.0 → 0.6.0-33dafd2
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 +480 -388
- package/dist/index.d.cts +457 -184
- package/dist/index.d.ts +457 -184
- package/dist/index.js +490 -388
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -29,37 +29,6 @@ function safeCall(fn) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// src/stacks-api/accounts/balances.ts
|
|
32
|
-
import * as v from "valibot";
|
|
33
|
-
var responseSchema = v.object({
|
|
34
|
-
stx: v.object({
|
|
35
|
-
balance: v.string(),
|
|
36
|
-
total_sent: v.string(),
|
|
37
|
-
total_received: v.string(),
|
|
38
|
-
total_fees_sent: v.string(),
|
|
39
|
-
total_miner_rewards_received: v.string(),
|
|
40
|
-
lock_tx_id: v.string(),
|
|
41
|
-
locked: v.string(),
|
|
42
|
-
lock_height: v.number(),
|
|
43
|
-
burnchain_lock_height: v.number(),
|
|
44
|
-
burnchain_unlock_height: v.number()
|
|
45
|
-
}),
|
|
46
|
-
fungible_tokens: v.record(
|
|
47
|
-
v.string(),
|
|
48
|
-
v.object({
|
|
49
|
-
balance: v.string(),
|
|
50
|
-
total_sent: v.string(),
|
|
51
|
-
total_received: v.string()
|
|
52
|
-
})
|
|
53
|
-
),
|
|
54
|
-
non_fungible_tokens: v.record(
|
|
55
|
-
v.string(),
|
|
56
|
-
v.object({
|
|
57
|
-
count: v.string(),
|
|
58
|
-
total_sent: v.string(),
|
|
59
|
-
total_received: v.string()
|
|
60
|
-
})
|
|
61
|
-
)
|
|
62
|
-
});
|
|
63
32
|
async function balances(opts) {
|
|
64
33
|
const search = new URLSearchParams();
|
|
65
34
|
if (opts.unanchored) search.append("unanchored", "true");
|
|
@@ -79,7 +48,7 @@ async function balances(opts) {
|
|
|
79
48
|
data: {
|
|
80
49
|
status: res.status,
|
|
81
50
|
statusText: res.statusText,
|
|
82
|
-
|
|
51
|
+
bodyText: await safePromise(res.text())
|
|
83
52
|
}
|
|
84
53
|
});
|
|
85
54
|
}
|
|
@@ -91,25 +60,17 @@ async function balances(opts) {
|
|
|
91
60
|
data: jsonError
|
|
92
61
|
});
|
|
93
62
|
}
|
|
94
|
-
|
|
95
|
-
if (!validationResult.success) {
|
|
96
|
-
return error({
|
|
97
|
-
name: "ValidateDataError",
|
|
98
|
-
message: "Failed to validate data.",
|
|
99
|
-
data: validationResult
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return success(validationResult.output);
|
|
63
|
+
return success(data);
|
|
103
64
|
}
|
|
104
65
|
|
|
105
66
|
// src/stacks-api/accounts/latest-nonce.ts
|
|
106
|
-
import * as
|
|
107
|
-
var
|
|
108
|
-
last_mempool_tx_nonce:
|
|
109
|
-
last_executed_tx_nonce:
|
|
110
|
-
possible_next_nonce:
|
|
111
|
-
detected_missing_nonces:
|
|
112
|
-
detected_mempool_nonces:
|
|
67
|
+
import * as v from "valibot";
|
|
68
|
+
var responseSchema = v.object({
|
|
69
|
+
last_mempool_tx_nonce: v.nullable(v.number()),
|
|
70
|
+
last_executed_tx_nonce: v.nullable(v.number()),
|
|
71
|
+
possible_next_nonce: v.number(),
|
|
72
|
+
detected_missing_nonces: v.array(v.number()),
|
|
73
|
+
detected_mempool_nonces: v.array(v.number())
|
|
113
74
|
});
|
|
114
75
|
async function latestNonce(opts) {
|
|
115
76
|
const init = {};
|
|
@@ -128,7 +89,7 @@ async function latestNonce(opts) {
|
|
|
128
89
|
endpoint,
|
|
129
90
|
status: res.status,
|
|
130
91
|
statusText: res.statusText,
|
|
131
|
-
|
|
92
|
+
bodyText: await safePromise(res.text())
|
|
132
93
|
}
|
|
133
94
|
});
|
|
134
95
|
}
|
|
@@ -140,7 +101,7 @@ async function latestNonce(opts) {
|
|
|
140
101
|
data: jsonError
|
|
141
102
|
});
|
|
142
103
|
}
|
|
143
|
-
const validationResult =
|
|
104
|
+
const validationResult = v.safeParse(responseSchema, data);
|
|
144
105
|
if (!validationResult.success) {
|
|
145
106
|
return error({
|
|
146
107
|
name: "ValidateDataError",
|
|
@@ -158,36 +119,36 @@ var accounts = {
|
|
|
158
119
|
};
|
|
159
120
|
|
|
160
121
|
// src/stacks-api/types.ts
|
|
161
|
-
import * as
|
|
162
|
-
var baseListResponseSchema =
|
|
163
|
-
limit:
|
|
164
|
-
offset:
|
|
165
|
-
total:
|
|
166
|
-
results:
|
|
122
|
+
import * as v2 from "valibot";
|
|
123
|
+
var baseListResponseSchema = v2.object({
|
|
124
|
+
limit: v2.number(),
|
|
125
|
+
offset: v2.number(),
|
|
126
|
+
total: v2.number(),
|
|
127
|
+
results: v2.array(v2.unknown())
|
|
167
128
|
});
|
|
168
129
|
|
|
169
130
|
// src/stacks-api/blocks/get-block.ts
|
|
170
|
-
import * as
|
|
171
|
-
var
|
|
172
|
-
canonical:
|
|
173
|
-
height:
|
|
174
|
-
hash:
|
|
175
|
-
block_time:
|
|
176
|
-
block_time_iso:
|
|
177
|
-
index_block_hash:
|
|
178
|
-
parent_block_hash:
|
|
179
|
-
parent_index_block_hash:
|
|
180
|
-
burn_block_time:
|
|
181
|
-
burn_block_time_iso:
|
|
182
|
-
burn_block_hash:
|
|
183
|
-
burn_block_height:
|
|
184
|
-
miner_txid:
|
|
185
|
-
tx_count:
|
|
186
|
-
execution_cost_read_count:
|
|
187
|
-
execution_cost_read_length:
|
|
188
|
-
execution_cost_runtime:
|
|
189
|
-
execution_cost_write_count:
|
|
190
|
-
execution_cost_write_length:
|
|
131
|
+
import * as v3 from "valibot";
|
|
132
|
+
var responseSchema2 = v3.object({
|
|
133
|
+
canonical: v3.boolean(),
|
|
134
|
+
height: v3.number(),
|
|
135
|
+
hash: v3.string(),
|
|
136
|
+
block_time: v3.number(),
|
|
137
|
+
block_time_iso: v3.string(),
|
|
138
|
+
index_block_hash: v3.string(),
|
|
139
|
+
parent_block_hash: v3.string(),
|
|
140
|
+
parent_index_block_hash: v3.string(),
|
|
141
|
+
burn_block_time: v3.number(),
|
|
142
|
+
burn_block_time_iso: v3.string(),
|
|
143
|
+
burn_block_hash: v3.string(),
|
|
144
|
+
burn_block_height: v3.number(),
|
|
145
|
+
miner_txid: v3.string(),
|
|
146
|
+
tx_count: v3.number(),
|
|
147
|
+
execution_cost_read_count: v3.number(),
|
|
148
|
+
execution_cost_read_length: v3.number(),
|
|
149
|
+
execution_cost_runtime: v3.number(),
|
|
150
|
+
execution_cost_write_count: v3.number(),
|
|
151
|
+
execution_cost_write_length: v3.number()
|
|
191
152
|
});
|
|
192
153
|
async function getBlock(opts) {
|
|
193
154
|
const init = {};
|
|
@@ -207,7 +168,7 @@ async function getBlock(opts) {
|
|
|
207
168
|
data: {
|
|
208
169
|
status: res.status,
|
|
209
170
|
statusText: res.statusText,
|
|
210
|
-
|
|
171
|
+
bodyText: await safePromise(res.text())
|
|
211
172
|
}
|
|
212
173
|
});
|
|
213
174
|
}
|
|
@@ -219,7 +180,7 @@ async function getBlock(opts) {
|
|
|
219
180
|
data: jsonError
|
|
220
181
|
});
|
|
221
182
|
}
|
|
222
|
-
const validationResult =
|
|
183
|
+
const validationResult = v3.safeParse(responseSchema2, data);
|
|
223
184
|
if (!validationResult.success) {
|
|
224
185
|
return error({
|
|
225
186
|
name: "ValidateDataError",
|
|
@@ -256,7 +217,7 @@ async function stx(opts) {
|
|
|
256
217
|
data: {
|
|
257
218
|
status: res.status,
|
|
258
219
|
statusText: res.statusText,
|
|
259
|
-
|
|
220
|
+
bodyText: await safePromise(res.text())
|
|
260
221
|
}
|
|
261
222
|
});
|
|
262
223
|
}
|
|
@@ -277,22 +238,22 @@ var faucets = {
|
|
|
277
238
|
};
|
|
278
239
|
|
|
279
240
|
// src/stacks-api/info/core-api.ts
|
|
280
|
-
import * as
|
|
281
|
-
var CoreApiResponseSchema =
|
|
282
|
-
peer_version:
|
|
283
|
-
pox_consensus:
|
|
284
|
-
burn_block_height:
|
|
285
|
-
stable_pox_consensus:
|
|
286
|
-
stable_burn_block_height:
|
|
287
|
-
server_version:
|
|
288
|
-
network_id:
|
|
289
|
-
parent_network_id:
|
|
290
|
-
stacks_tip_height:
|
|
291
|
-
stacks_tip:
|
|
292
|
-
stacks_tip_consensus_hash:
|
|
293
|
-
unanchored_tip:
|
|
294
|
-
unanchored_seq:
|
|
295
|
-
exit_at_block_height:
|
|
241
|
+
import * as v4 from "valibot";
|
|
242
|
+
var CoreApiResponseSchema = v4.object({
|
|
243
|
+
peer_version: v4.number(),
|
|
244
|
+
pox_consensus: v4.string(),
|
|
245
|
+
burn_block_height: v4.number(),
|
|
246
|
+
stable_pox_consensus: v4.string(),
|
|
247
|
+
stable_burn_block_height: v4.number(),
|
|
248
|
+
server_version: v4.string(),
|
|
249
|
+
network_id: v4.number(),
|
|
250
|
+
parent_network_id: v4.number(),
|
|
251
|
+
stacks_tip_height: v4.number(),
|
|
252
|
+
stacks_tip: v4.string(),
|
|
253
|
+
stacks_tip_consensus_hash: v4.string(),
|
|
254
|
+
unanchored_tip: v4.nullable(v4.string()),
|
|
255
|
+
unanchored_seq: v4.nullable(v4.string()),
|
|
256
|
+
exit_at_block_height: v4.nullable(v4.number())
|
|
296
257
|
});
|
|
297
258
|
async function coreApi(apiOpts) {
|
|
298
259
|
const init = {};
|
|
@@ -309,7 +270,7 @@ async function coreApi(apiOpts) {
|
|
|
309
270
|
data: {
|
|
310
271
|
status: res.status,
|
|
311
272
|
statusText: res.statusText,
|
|
312
|
-
|
|
273
|
+
bodyText: await safePromise(res.text())
|
|
313
274
|
}
|
|
314
275
|
});
|
|
315
276
|
}
|
|
@@ -321,7 +282,7 @@ async function coreApi(apiOpts) {
|
|
|
321
282
|
data: parseBodyError
|
|
322
283
|
});
|
|
323
284
|
}
|
|
324
|
-
const validationResult =
|
|
285
|
+
const validationResult = v4.safeParse(CoreApiResponseSchema, data);
|
|
325
286
|
if (!validationResult.success) {
|
|
326
287
|
return error({
|
|
327
288
|
name: "ValidateDataError",
|
|
@@ -332,117 +293,20 @@ async function coreApi(apiOpts) {
|
|
|
332
293
|
return success(validationResult.output);
|
|
333
294
|
}
|
|
334
295
|
|
|
335
|
-
// src/stacks-api/info/pox-details.ts
|
|
336
|
-
import * as v6 from "valibot";
|
|
337
|
-
var poxDetailsResponseSchema = v6.object({
|
|
338
|
-
contract_id: v6.string(),
|
|
339
|
-
pox_activation_threshold_ustx: v6.number(),
|
|
340
|
-
first_burnchain_block_height: v6.number(),
|
|
341
|
-
current_burnchain_block_height: v6.number(),
|
|
342
|
-
prepare_phase_block_length: v6.number(),
|
|
343
|
-
reward_phase_block_length: v6.number(),
|
|
344
|
-
reward_slots: v6.number(),
|
|
345
|
-
rejection_fraction: v6.null(),
|
|
346
|
-
total_liquid_supply_ustx: v6.number(),
|
|
347
|
-
current_cycle: v6.object({
|
|
348
|
-
id: v6.number(),
|
|
349
|
-
min_threshold_ustx: v6.number(),
|
|
350
|
-
stacked_ustx: v6.number(),
|
|
351
|
-
is_pox_active: v6.boolean()
|
|
352
|
-
}),
|
|
353
|
-
next_cycle: v6.object({
|
|
354
|
-
id: v6.number(),
|
|
355
|
-
min_threshold_ustx: v6.number(),
|
|
356
|
-
min_increment_ustx: v6.number(),
|
|
357
|
-
stacked_ustx: v6.number(),
|
|
358
|
-
prepare_phase_start_block_height: v6.number(),
|
|
359
|
-
blocks_until_prepare_phase: v6.number(),
|
|
360
|
-
reward_phase_start_block_height: v6.number(),
|
|
361
|
-
blocks_until_reward_phase: v6.number(),
|
|
362
|
-
ustx_until_pox_rejection: v6.null()
|
|
363
|
-
}),
|
|
364
|
-
epochs: v6.array(
|
|
365
|
-
v6.object({
|
|
366
|
-
epoch_id: v6.string(),
|
|
367
|
-
start_height: v6.number(),
|
|
368
|
-
end_height: v6.number(),
|
|
369
|
-
block_limit: v6.object({
|
|
370
|
-
write_length: v6.number(),
|
|
371
|
-
write_count: v6.number(),
|
|
372
|
-
read_length: v6.number(),
|
|
373
|
-
read_count: v6.number(),
|
|
374
|
-
runtime: v6.number()
|
|
375
|
-
}),
|
|
376
|
-
network_epoch: v6.number()
|
|
377
|
-
})
|
|
378
|
-
),
|
|
379
|
-
min_amount_ustx: v6.number(),
|
|
380
|
-
prepare_cycle_length: v6.number(),
|
|
381
|
-
reward_cycle_id: v6.number(),
|
|
382
|
-
reward_cycle_length: v6.number(),
|
|
383
|
-
rejection_votes_left_required: v6.null(),
|
|
384
|
-
next_reward_cycle_in: v6.number(),
|
|
385
|
-
contract_versions: v6.array(
|
|
386
|
-
v6.object({
|
|
387
|
-
contract_id: v6.string(),
|
|
388
|
-
activation_burnchain_block_height: v6.number(),
|
|
389
|
-
first_reward_cycle_id: v6.number()
|
|
390
|
-
})
|
|
391
|
-
)
|
|
392
|
-
});
|
|
393
|
-
async function poxDetails(args) {
|
|
394
|
-
const init = {};
|
|
395
|
-
if (args.apiKeyConfig) {
|
|
396
|
-
init.headers = {
|
|
397
|
-
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
const res = await fetch(`${args.baseUrl}/v2/pox`, init);
|
|
401
|
-
if (!res.ok) {
|
|
402
|
-
return error({
|
|
403
|
-
name: "FetchPoxDetailsError",
|
|
404
|
-
message: "Failed to fetch pox details.",
|
|
405
|
-
data: {
|
|
406
|
-
status: res.status,
|
|
407
|
-
statusText: res.statusText,
|
|
408
|
-
bodyParseResult: await safePromise(res.json())
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
const [jsonParseError, data] = await safePromise(res.json());
|
|
413
|
-
if (jsonParseError) {
|
|
414
|
-
return error({
|
|
415
|
-
name: "ParseBodyError",
|
|
416
|
-
message: "Failed to parse pox details response.",
|
|
417
|
-
data: jsonParseError
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
const validationResult = v6.safeParse(poxDetailsResponseSchema, data);
|
|
421
|
-
if (!validationResult.success) {
|
|
422
|
-
return error({
|
|
423
|
-
name: "ValidateDataError",
|
|
424
|
-
message: "Failed to parse pox details response.",
|
|
425
|
-
data: validationResult
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
return success(validationResult.output);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
296
|
// src/stacks-api/info/index.ts
|
|
432
297
|
var info = {
|
|
433
|
-
coreApi
|
|
434
|
-
poxDetails
|
|
298
|
+
coreApi
|
|
435
299
|
};
|
|
436
300
|
|
|
437
301
|
// src/stacks-api/proof-of-transfer/cycle.ts
|
|
438
|
-
import * as
|
|
439
|
-
var
|
|
440
|
-
block_height:
|
|
441
|
-
index_block_hash:
|
|
442
|
-
cycle_number:
|
|
443
|
-
total_weight:
|
|
444
|
-
total_stacked_amount:
|
|
445
|
-
total_signers:
|
|
302
|
+
import * as v5 from "valibot";
|
|
303
|
+
var responseSchema3 = v5.object({
|
|
304
|
+
block_height: v5.number(),
|
|
305
|
+
index_block_hash: v5.string(),
|
|
306
|
+
cycle_number: v5.number(),
|
|
307
|
+
total_weight: v5.number(),
|
|
308
|
+
total_stacked_amount: v5.string(),
|
|
309
|
+
total_signers: v5.number()
|
|
446
310
|
});
|
|
447
311
|
async function cycle(opts) {
|
|
448
312
|
const init = {};
|
|
@@ -461,7 +325,7 @@ async function cycle(opts) {
|
|
|
461
325
|
endpoint,
|
|
462
326
|
status: res.status,
|
|
463
327
|
statusText: res.statusText,
|
|
464
|
-
|
|
328
|
+
bodyText: await safePromise(res.text())
|
|
465
329
|
}
|
|
466
330
|
});
|
|
467
331
|
}
|
|
@@ -473,7 +337,7 @@ async function cycle(opts) {
|
|
|
473
337
|
data: jsonError
|
|
474
338
|
});
|
|
475
339
|
}
|
|
476
|
-
const validationResult =
|
|
340
|
+
const validationResult = v5.safeParse(responseSchema3, data);
|
|
477
341
|
if (!validationResult.success) {
|
|
478
342
|
return error({
|
|
479
343
|
name: "ValidateDataError",
|
|
@@ -485,17 +349,17 @@ async function cycle(opts) {
|
|
|
485
349
|
}
|
|
486
350
|
|
|
487
351
|
// src/stacks-api/proof-of-transfer/cycles.ts
|
|
488
|
-
import * as
|
|
489
|
-
var cycleInfoSchema =
|
|
490
|
-
block_height:
|
|
491
|
-
index_block_hash:
|
|
492
|
-
cycle_number:
|
|
493
|
-
total_weight:
|
|
494
|
-
total_stacked_amount:
|
|
495
|
-
total_signers:
|
|
352
|
+
import * as v6 from "valibot";
|
|
353
|
+
var cycleInfoSchema = v6.object({
|
|
354
|
+
block_height: v6.number(),
|
|
355
|
+
index_block_hash: v6.string(),
|
|
356
|
+
cycle_number: v6.number(),
|
|
357
|
+
total_weight: v6.number(),
|
|
358
|
+
total_stacked_amount: v6.string(),
|
|
359
|
+
total_signers: v6.number()
|
|
496
360
|
});
|
|
497
|
-
var resultsSchema =
|
|
498
|
-
var cyclesResponseSchema =
|
|
361
|
+
var resultsSchema = v6.array(cycleInfoSchema);
|
|
362
|
+
var cyclesResponseSchema = v6.object({
|
|
499
363
|
...baseListResponseSchema.entries,
|
|
500
364
|
results: resultsSchema
|
|
501
365
|
});
|
|
@@ -519,7 +383,7 @@ async function cycles(args) {
|
|
|
519
383
|
endpoint,
|
|
520
384
|
status: res.status,
|
|
521
385
|
statusText: res.statusText,
|
|
522
|
-
|
|
386
|
+
bodyText: await safePromise(res.text())
|
|
523
387
|
}
|
|
524
388
|
});
|
|
525
389
|
}
|
|
@@ -531,7 +395,7 @@ async function cycles(args) {
|
|
|
531
395
|
data: jsonError
|
|
532
396
|
});
|
|
533
397
|
}
|
|
534
|
-
const validationResult =
|
|
398
|
+
const validationResult = v6.safeParse(cyclesResponseSchema, data);
|
|
535
399
|
if (!validationResult.success) {
|
|
536
400
|
return error({
|
|
537
401
|
name: "ValidateDataError",
|
|
@@ -543,16 +407,16 @@ async function cycles(args) {
|
|
|
543
407
|
}
|
|
544
408
|
|
|
545
409
|
// src/stacks-api/proof-of-transfer/signer-in-cycle.ts
|
|
546
|
-
import * as
|
|
547
|
-
var signerInCycleResponseSchema =
|
|
548
|
-
signing_key:
|
|
549
|
-
signer_address:
|
|
550
|
-
weight:
|
|
551
|
-
stacked_amount:
|
|
552
|
-
weight_percent:
|
|
553
|
-
stacked_amount_percent:
|
|
554
|
-
solo_stacker_count:
|
|
555
|
-
pooled_stacker_count:
|
|
410
|
+
import * as v7 from "valibot";
|
|
411
|
+
var signerInCycleResponseSchema = v7.object({
|
|
412
|
+
signing_key: v7.string(),
|
|
413
|
+
signer_address: v7.string(),
|
|
414
|
+
weight: v7.number(),
|
|
415
|
+
stacked_amount: v7.string(),
|
|
416
|
+
weight_percent: v7.number(),
|
|
417
|
+
stacked_amount_percent: v7.number(),
|
|
418
|
+
solo_stacker_count: v7.number(),
|
|
419
|
+
pooled_stacker_count: v7.number()
|
|
556
420
|
});
|
|
557
421
|
async function signerInCycle(args) {
|
|
558
422
|
const init = {};
|
|
@@ -588,7 +452,7 @@ async function signerInCycle(args) {
|
|
|
588
452
|
}
|
|
589
453
|
});
|
|
590
454
|
}
|
|
591
|
-
const validationResult =
|
|
455
|
+
const validationResult = v7.safeParse(signerInCycleResponseSchema, data);
|
|
592
456
|
if (!validationResult.success) {
|
|
593
457
|
return error({
|
|
594
458
|
name: "ValidateDataError",
|
|
@@ -600,19 +464,19 @@ async function signerInCycle(args) {
|
|
|
600
464
|
}
|
|
601
465
|
|
|
602
466
|
// src/stacks-api/proof-of-transfer/signers-in-cycle.ts
|
|
603
|
-
import * as
|
|
604
|
-
var signerSchema =
|
|
605
|
-
signing_key:
|
|
606
|
-
signer_address:
|
|
607
|
-
weight:
|
|
608
|
-
stacked_amount:
|
|
609
|
-
weight_percent:
|
|
610
|
-
stacked_amount_percent:
|
|
611
|
-
pooled_stacker_count:
|
|
612
|
-
solo_stacker_count:
|
|
467
|
+
import * as v8 from "valibot";
|
|
468
|
+
var signerSchema = v8.object({
|
|
469
|
+
signing_key: v8.string(),
|
|
470
|
+
signer_address: v8.string(),
|
|
471
|
+
weight: v8.number(),
|
|
472
|
+
stacked_amount: v8.string(),
|
|
473
|
+
weight_percent: v8.number(),
|
|
474
|
+
stacked_amount_percent: v8.number(),
|
|
475
|
+
pooled_stacker_count: v8.number(),
|
|
476
|
+
solo_stacker_count: v8.number()
|
|
613
477
|
});
|
|
614
|
-
var resultsSchema2 =
|
|
615
|
-
var signersResponseSchema =
|
|
478
|
+
var resultsSchema2 = v8.array(signerSchema);
|
|
479
|
+
var signersResponseSchema = v8.object({
|
|
616
480
|
...baseListResponseSchema.entries,
|
|
617
481
|
results: resultsSchema2
|
|
618
482
|
});
|
|
@@ -636,7 +500,7 @@ async function signersInCycle(args) {
|
|
|
636
500
|
endpoint,
|
|
637
501
|
status: res.status,
|
|
638
502
|
statusText: res.statusText,
|
|
639
|
-
|
|
503
|
+
bodyText: await safePromise(res.text())
|
|
640
504
|
}
|
|
641
505
|
});
|
|
642
506
|
}
|
|
@@ -651,7 +515,7 @@ async function signersInCycle(args) {
|
|
|
651
515
|
}
|
|
652
516
|
});
|
|
653
517
|
}
|
|
654
|
-
const validationResult =
|
|
518
|
+
const validationResult = v8.safeParse(signersResponseSchema, data);
|
|
655
519
|
if (!validationResult.success) {
|
|
656
520
|
return error({
|
|
657
521
|
name: "ValidateDataError",
|
|
@@ -663,15 +527,15 @@ async function signersInCycle(args) {
|
|
|
663
527
|
}
|
|
664
528
|
|
|
665
529
|
// src/stacks-api/proof-of-transfer/stackers-for-signer-in-cycle.ts
|
|
666
|
-
import * as
|
|
667
|
-
var stackerInfoSchema =
|
|
668
|
-
stacker_address:
|
|
669
|
-
stacked_amount:
|
|
670
|
-
pox_address:
|
|
671
|
-
stacker_type:
|
|
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")])
|
|
672
536
|
});
|
|
673
|
-
var resultsSchema3 =
|
|
674
|
-
var stackersForSignerInCycleResponseSchema =
|
|
537
|
+
var resultsSchema3 = v9.array(stackerInfoSchema);
|
|
538
|
+
var stackersForSignerInCycleResponseSchema = v9.object({
|
|
675
539
|
...baseListResponseSchema.entries,
|
|
676
540
|
results: resultsSchema3
|
|
677
541
|
});
|
|
@@ -696,7 +560,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
696
560
|
endpoint,
|
|
697
561
|
status: res.status,
|
|
698
562
|
statusText: res.statusText,
|
|
699
|
-
|
|
563
|
+
bodyText: await safePromise(res.text())
|
|
700
564
|
}
|
|
701
565
|
});
|
|
702
566
|
}
|
|
@@ -708,7 +572,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
708
572
|
data: jsonError
|
|
709
573
|
});
|
|
710
574
|
}
|
|
711
|
-
const validationResult =
|
|
575
|
+
const validationResult = v9.safeParse(
|
|
712
576
|
stackersForSignerInCycleResponseSchema,
|
|
713
577
|
data
|
|
714
578
|
);
|
|
@@ -732,20 +596,20 @@ var proofOfTransfer = {
|
|
|
732
596
|
};
|
|
733
597
|
|
|
734
598
|
// src/stacks-api/stacking-pool/members.ts
|
|
735
|
-
import * as
|
|
736
|
-
var memberSchema =
|
|
737
|
-
stacker:
|
|
738
|
-
pox_addr:
|
|
739
|
-
amount_ustx:
|
|
740
|
-
burn_block_unlock_height:
|
|
741
|
-
block_height:
|
|
742
|
-
tx_id:
|
|
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()
|
|
743
607
|
});
|
|
744
|
-
var membersResponseSchema =
|
|
745
|
-
limit:
|
|
746
|
-
offset:
|
|
747
|
-
total:
|
|
748
|
-
results:
|
|
608
|
+
var membersResponseSchema = v10.object({
|
|
609
|
+
limit: v10.number(),
|
|
610
|
+
offset: v10.number(),
|
|
611
|
+
total: v10.number(),
|
|
612
|
+
results: v10.array(memberSchema)
|
|
749
613
|
});
|
|
750
614
|
async function members(args) {
|
|
751
615
|
const search = new URLSearchParams();
|
|
@@ -768,7 +632,7 @@ async function members(args) {
|
|
|
768
632
|
data: {
|
|
769
633
|
status: res.status,
|
|
770
634
|
statusText: res.statusText,
|
|
771
|
-
|
|
635
|
+
bodyText: await safePromise(res.text())
|
|
772
636
|
}
|
|
773
637
|
});
|
|
774
638
|
}
|
|
@@ -780,7 +644,7 @@ async function members(args) {
|
|
|
780
644
|
data: jsonParseError
|
|
781
645
|
});
|
|
782
646
|
}
|
|
783
|
-
const validationResult =
|
|
647
|
+
const validationResult = v10.safeParse(membersResponseSchema, data);
|
|
784
648
|
if (!validationResult.success) {
|
|
785
649
|
return error({
|
|
786
650
|
name: "ValidateDataError",
|
|
@@ -797,120 +661,120 @@ var stackingPool = {
|
|
|
797
661
|
};
|
|
798
662
|
|
|
799
663
|
// src/stacks-api/transactions/schemas.ts
|
|
800
|
-
import * as
|
|
801
|
-
var baseTransactionSchema =
|
|
802
|
-
tx_id:
|
|
803
|
-
nonce:
|
|
804
|
-
fee_rate:
|
|
805
|
-
sender_address:
|
|
806
|
-
sponsored:
|
|
807
|
-
post_condition_mode:
|
|
808
|
-
post_conditions:
|
|
809
|
-
anchor_mode:
|
|
810
|
-
is_unanchored:
|
|
811
|
-
block_hash:
|
|
812
|
-
parent_block_hash:
|
|
813
|
-
block_height:
|
|
814
|
-
block_time:
|
|
815
|
-
block_time_iso:
|
|
816
|
-
burn_block_height:
|
|
817
|
-
burn_block_time:
|
|
818
|
-
burn_block_time_iso:
|
|
819
|
-
parent_burn_block_time:
|
|
820
|
-
parent_burn_block_time_iso:
|
|
821
|
-
canonical:
|
|
822
|
-
tx_index:
|
|
823
|
-
tx_status:
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
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")
|
|
827
691
|
]),
|
|
828
|
-
tx_result:
|
|
829
|
-
hex:
|
|
830
|
-
repr:
|
|
692
|
+
tx_result: v11.object({
|
|
693
|
+
hex: v11.string(),
|
|
694
|
+
repr: v11.string()
|
|
831
695
|
}),
|
|
832
|
-
microblock_hash:
|
|
833
|
-
microblock_sequence:
|
|
834
|
-
microblock_canonical:
|
|
835
|
-
event_count:
|
|
836
|
-
events:
|
|
837
|
-
execution_cost_read_count:
|
|
838
|
-
execution_cost_read_length:
|
|
839
|
-
execution_cost_runtime:
|
|
840
|
-
execution_cost_write_count:
|
|
841
|
-
execution_cost_write_length:
|
|
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()
|
|
842
706
|
});
|
|
843
|
-
var contractCallTransactionSchema =
|
|
844
|
-
tx_type:
|
|
845
|
-
contract_call:
|
|
846
|
-
contract_id:
|
|
847
|
-
function_name:
|
|
848
|
-
function_signature:
|
|
849
|
-
function_args:
|
|
850
|
-
|
|
851
|
-
hex:
|
|
852
|
-
repr:
|
|
853
|
-
name:
|
|
854
|
-
type:
|
|
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()
|
|
855
719
|
})
|
|
856
720
|
)
|
|
857
721
|
}),
|
|
858
722
|
...baseTransactionSchema.entries
|
|
859
723
|
});
|
|
860
|
-
var smartContractTransactionSchema =
|
|
861
|
-
tx_type:
|
|
862
|
-
smart_contract:
|
|
724
|
+
var smartContractTransactionSchema = v11.object({
|
|
725
|
+
tx_type: v11.literal("smart_contract"),
|
|
726
|
+
smart_contract: v11.object({
|
|
863
727
|
/**
|
|
864
728
|
* NOTE: The types may be wrong, not sure what type of value is used when
|
|
865
729
|
* the version is not `null`.
|
|
866
730
|
*/
|
|
867
|
-
clarity_version:
|
|
868
|
-
contract_id:
|
|
869
|
-
source_code:
|
|
731
|
+
clarity_version: v11.union([v11.null(), v11.number()]),
|
|
732
|
+
contract_id: v11.string(),
|
|
733
|
+
source_code: v11.string()
|
|
870
734
|
}),
|
|
871
735
|
...baseTransactionSchema.entries
|
|
872
736
|
});
|
|
873
|
-
var tokenTransferSchema =
|
|
874
|
-
tx_type:
|
|
875
|
-
token_transfer:
|
|
876
|
-
recipient_address:
|
|
877
|
-
amount:
|
|
878
|
-
memo:
|
|
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()
|
|
879
743
|
}),
|
|
880
744
|
...baseTransactionSchema.entries
|
|
881
745
|
});
|
|
882
|
-
var transactionSchema =
|
|
746
|
+
var transactionSchema = v11.variant("tx_type", [
|
|
883
747
|
contractCallTransactionSchema,
|
|
884
748
|
smartContractTransactionSchema,
|
|
885
749
|
tokenTransferSchema
|
|
886
750
|
]);
|
|
887
751
|
|
|
888
752
|
// src/stacks-api/transactions/address-transactions.ts
|
|
889
|
-
import * as
|
|
890
|
-
var resultSchema =
|
|
753
|
+
import * as v12 from "valibot";
|
|
754
|
+
var resultSchema = v12.object({
|
|
891
755
|
tx: transactionSchema,
|
|
892
|
-
stx_sent:
|
|
893
|
-
stx_received:
|
|
894
|
-
events:
|
|
895
|
-
stx:
|
|
896
|
-
transfer:
|
|
897
|
-
mint:
|
|
898
|
-
burn:
|
|
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()
|
|
899
763
|
}),
|
|
900
|
-
ft:
|
|
901
|
-
transfer:
|
|
902
|
-
mint:
|
|
903
|
-
burn:
|
|
764
|
+
ft: v12.object({
|
|
765
|
+
transfer: v12.number(),
|
|
766
|
+
mint: v12.number(),
|
|
767
|
+
burn: v12.number()
|
|
904
768
|
}),
|
|
905
|
-
nft:
|
|
906
|
-
transfer:
|
|
907
|
-
mint:
|
|
908
|
-
burn:
|
|
769
|
+
nft: v12.object({
|
|
770
|
+
transfer: v12.number(),
|
|
771
|
+
mint: v12.number(),
|
|
772
|
+
burn: v12.number()
|
|
909
773
|
})
|
|
910
774
|
})
|
|
911
775
|
});
|
|
912
|
-
var resultsSchema4 =
|
|
913
|
-
var addressTransactionsResponseSchema =
|
|
776
|
+
var resultsSchema4 = v12.array(resultSchema);
|
|
777
|
+
var addressTransactionsResponseSchema = v12.object({
|
|
914
778
|
...baseListResponseSchema.entries,
|
|
915
779
|
results: resultsSchema4
|
|
916
780
|
});
|
|
@@ -935,7 +799,7 @@ async function addressTransactions(args) {
|
|
|
935
799
|
data: {
|
|
936
800
|
status: res.status,
|
|
937
801
|
statusText: res.statusText,
|
|
938
|
-
|
|
802
|
+
bodyText: await safePromise(res.text())
|
|
939
803
|
}
|
|
940
804
|
});
|
|
941
805
|
}
|
|
@@ -947,7 +811,7 @@ async function addressTransactions(args) {
|
|
|
947
811
|
data: jsonParseError
|
|
948
812
|
});
|
|
949
813
|
}
|
|
950
|
-
const validationResult =
|
|
814
|
+
const validationResult = v12.safeParse(addressTransactionsResponseSchema, data);
|
|
951
815
|
if (!validationResult.success) {
|
|
952
816
|
return error({
|
|
953
817
|
name: "ValidateDataError",
|
|
@@ -959,7 +823,7 @@ async function addressTransactions(args) {
|
|
|
959
823
|
}
|
|
960
824
|
|
|
961
825
|
// src/stacks-api/transactions/get-transaction.ts
|
|
962
|
-
import * as
|
|
826
|
+
import * as v13 from "valibot";
|
|
963
827
|
async function getTransaction(args) {
|
|
964
828
|
const init = {};
|
|
965
829
|
if (args.apiKeyConfig) {
|
|
@@ -976,7 +840,7 @@ async function getTransaction(args) {
|
|
|
976
840
|
response: {
|
|
977
841
|
status: res.status,
|
|
978
842
|
statusText: res.statusText,
|
|
979
|
-
|
|
843
|
+
bodyText: await safePromise(res.text())
|
|
980
844
|
}
|
|
981
845
|
});
|
|
982
846
|
}
|
|
@@ -988,7 +852,7 @@ async function getTransaction(args) {
|
|
|
988
852
|
error: jsonParseError
|
|
989
853
|
});
|
|
990
854
|
}
|
|
991
|
-
const validationResult =
|
|
855
|
+
const validationResult = v13.safeParse(transactionSchema, data);
|
|
992
856
|
if (!validationResult.success) {
|
|
993
857
|
return error({
|
|
994
858
|
name: "ValidateDataError",
|
|
@@ -999,10 +863,91 @@ async function getTransaction(args) {
|
|
|
999
863
|
return success(validationResult.output);
|
|
1000
864
|
}
|
|
1001
865
|
|
|
866
|
+
// src/stacks-api/transactions/mempool-transactions.ts
|
|
867
|
+
async function mempoolTransactions(args) {
|
|
868
|
+
const search = new URLSearchParams();
|
|
869
|
+
if (args.limit) search.append("limit", args.limit.toString());
|
|
870
|
+
if (args.offset) search.append("offset", args.offset.toString());
|
|
871
|
+
if (args.senderAddress) search.append("sender_address", args.senderAddress);
|
|
872
|
+
if (args.recipientAddress)
|
|
873
|
+
search.append("recipient_address", args.recipientAddress);
|
|
874
|
+
if (args.address) search.append("address", args.address);
|
|
875
|
+
if (args.orderBy) search.append("order_by", args.orderBy);
|
|
876
|
+
if (args.order) search.append("order", args.order);
|
|
877
|
+
const init = {};
|
|
878
|
+
if (args.apiKeyConfig) {
|
|
879
|
+
init.headers = {
|
|
880
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
const res = await fetch(
|
|
884
|
+
`${args.baseUrl}/extended/v1/tx/mempool?${search}`,
|
|
885
|
+
init
|
|
886
|
+
);
|
|
887
|
+
if (!res.ok) {
|
|
888
|
+
return error({
|
|
889
|
+
name: "FetchMempoolTransactionsError",
|
|
890
|
+
message: "Failed to fetch mempool transactions.",
|
|
891
|
+
data: {
|
|
892
|
+
status: res.status,
|
|
893
|
+
statusText: res.statusText,
|
|
894
|
+
bodyText: await safePromise(res.text())
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
const [jsonParseError, data] = await safePromise(res.json());
|
|
899
|
+
if (jsonParseError) {
|
|
900
|
+
return error({
|
|
901
|
+
name: "ParseBodyError",
|
|
902
|
+
message: "Failed to parse response body.",
|
|
903
|
+
data: jsonParseError
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
return success(data);
|
|
907
|
+
}
|
|
908
|
+
|
|
1002
909
|
// src/stacks-api/transactions/index.ts
|
|
1003
910
|
var transactions = {
|
|
1004
911
|
addressTransactions,
|
|
1005
|
-
getTransaction
|
|
912
|
+
getTransaction,
|
|
913
|
+
mempoolTransactions
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
// src/stacks-api/mempool/transaction-fee-priorities.ts
|
|
917
|
+
async function transactionFeePriorities(opts) {
|
|
918
|
+
const init = {};
|
|
919
|
+
if (opts.apiKeyConfig) {
|
|
920
|
+
init.headers = {
|
|
921
|
+
[opts.apiKeyConfig.header]: opts.apiKeyConfig.key
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
const endpoint = `${opts.baseUrl}/extended/v2/mempool/fees`;
|
|
925
|
+
const res = await fetch(endpoint, init);
|
|
926
|
+
if (!res.ok) {
|
|
927
|
+
return error({
|
|
928
|
+
name: "FetchFeePrioritiesError",
|
|
929
|
+
message: "Failed to fetch transaction fee priorities.",
|
|
930
|
+
data: {
|
|
931
|
+
status: res.status,
|
|
932
|
+
statusText: res.statusText,
|
|
933
|
+
bodyParseResult: await safePromise(res.text())
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
const [jsonError, data] = await safePromise(res.json());
|
|
938
|
+
if (jsonError) {
|
|
939
|
+
return error({
|
|
940
|
+
name: "ParseBodyError",
|
|
941
|
+
message: "Failed to parse response body as JSON.",
|
|
942
|
+
data: jsonError
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
return success(data);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/stacks-api/mempool/index.ts
|
|
949
|
+
var mempool = {
|
|
950
|
+
transactionFeePriorities
|
|
1006
951
|
};
|
|
1007
952
|
|
|
1008
953
|
// src/stacks-api/index.ts
|
|
@@ -1011,22 +956,23 @@ var stacksApi = {
|
|
|
1011
956
|
blocks,
|
|
1012
957
|
faucets,
|
|
1013
958
|
info,
|
|
959
|
+
mempool,
|
|
1014
960
|
proofOfTransfer,
|
|
1015
961
|
stackingPool,
|
|
1016
962
|
transactions
|
|
1017
963
|
};
|
|
1018
964
|
|
|
1019
965
|
// src/stacks-rpc-api/smart-contracts/map-entry.ts
|
|
1020
|
-
import * as
|
|
1021
|
-
var mapEntryResponseSchema =
|
|
966
|
+
import * as v14 from "valibot";
|
|
967
|
+
var mapEntryResponseSchema = v14.object({
|
|
1022
968
|
/**
|
|
1023
969
|
* Hex-encoded string of clarity value. It is always an optional tuple.
|
|
1024
970
|
*/
|
|
1025
|
-
data:
|
|
971
|
+
data: v14.string(),
|
|
1026
972
|
/**
|
|
1027
973
|
* Hex-encoded string of the MARF proof for the data
|
|
1028
974
|
*/
|
|
1029
|
-
proof:
|
|
975
|
+
proof: v14.optional(v14.string())
|
|
1030
976
|
});
|
|
1031
977
|
async function mapEntry(args) {
|
|
1032
978
|
const search = new URLSearchParams();
|
|
@@ -1054,7 +1000,7 @@ async function mapEntry(args) {
|
|
|
1054
1000
|
status: res.status,
|
|
1055
1001
|
statusText: res.statusText,
|
|
1056
1002
|
endpoint,
|
|
1057
|
-
|
|
1003
|
+
bodyText: await safePromise(res.text())
|
|
1058
1004
|
}
|
|
1059
1005
|
});
|
|
1060
1006
|
}
|
|
@@ -1066,7 +1012,7 @@ async function mapEntry(args) {
|
|
|
1066
1012
|
data: jsonError
|
|
1067
1013
|
});
|
|
1068
1014
|
}
|
|
1069
|
-
const validationResult =
|
|
1015
|
+
const validationResult = v14.safeParse(mapEntryResponseSchema, data);
|
|
1070
1016
|
if (!validationResult.success) {
|
|
1071
1017
|
return error({
|
|
1072
1018
|
name: "ValidateDataError",
|
|
@@ -1078,20 +1024,6 @@ async function mapEntry(args) {
|
|
|
1078
1024
|
}
|
|
1079
1025
|
|
|
1080
1026
|
// 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
1027
|
async function readOnly(args) {
|
|
1096
1028
|
const headers = {
|
|
1097
1029
|
"Content-Type": "application/json"
|
|
@@ -1116,7 +1048,7 @@ async function readOnly(args) {
|
|
|
1116
1048
|
data: {
|
|
1117
1049
|
status: res.status,
|
|
1118
1050
|
statusText: res.statusText,
|
|
1119
|
-
|
|
1051
|
+
bodyText: await safePromise(res.text())
|
|
1120
1052
|
}
|
|
1121
1053
|
});
|
|
1122
1054
|
}
|
|
@@ -1128,15 +1060,7 @@ async function readOnly(args) {
|
|
|
1128
1060
|
data: error
|
|
1129
1061
|
});
|
|
1130
1062
|
}
|
|
1131
|
-
|
|
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);
|
|
1063
|
+
return success(data);
|
|
1140
1064
|
}
|
|
1141
1065
|
|
|
1142
1066
|
// src/stacks-rpc-api/smart-contracts/index.ts
|
|
@@ -1145,8 +1069,45 @@ var smartContracts = {
|
|
|
1145
1069
|
readOnly
|
|
1146
1070
|
};
|
|
1147
1071
|
|
|
1072
|
+
// src/stacks-rpc-api/pox/pox-details.ts
|
|
1073
|
+
async function poxDetails(args) {
|
|
1074
|
+
const init = {};
|
|
1075
|
+
if (args.apiKeyConfig) {
|
|
1076
|
+
init.headers = {
|
|
1077
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
const res = await fetch(`${args.baseUrl}/v2/pox`, init);
|
|
1081
|
+
if (!res.ok) {
|
|
1082
|
+
return error({
|
|
1083
|
+
name: "FetchPoxDetailsError",
|
|
1084
|
+
message: "Failed to fetch pox details.",
|
|
1085
|
+
data: {
|
|
1086
|
+
status: res.status,
|
|
1087
|
+
statusText: res.statusText,
|
|
1088
|
+
bodyText: await safePromise(res.text())
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
const [jsonParseError, data] = await safePromise(res.json());
|
|
1093
|
+
if (jsonParseError) {
|
|
1094
|
+
return error({
|
|
1095
|
+
name: "ParseBodyError",
|
|
1096
|
+
message: "Failed to parse pox details response.",
|
|
1097
|
+
data: jsonParseError
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
return success(data);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// src/stacks-rpc-api/pox/index.ts
|
|
1104
|
+
var pox = {
|
|
1105
|
+
poxDetails
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1148
1108
|
// src/stacks-rpc-api/index.ts
|
|
1149
1109
|
var stacksRpcApi = {
|
|
1110
|
+
pox,
|
|
1150
1111
|
smartContracts
|
|
1151
1112
|
};
|
|
1152
1113
|
|
|
@@ -1245,9 +1206,150 @@ async function getSignerStackedAmount(args) {
|
|
|
1245
1206
|
var queries = {
|
|
1246
1207
|
getSignerStackedAmount
|
|
1247
1208
|
};
|
|
1209
|
+
|
|
1210
|
+
// src/pox4-api/maps/stacking-state.ts
|
|
1211
|
+
import {
|
|
1212
|
+
cvToHex,
|
|
1213
|
+
hexToCV
|
|
1214
|
+
} from "@stacks/transactions";
|
|
1215
|
+
|
|
1216
|
+
// src/pox4-api/constants.ts
|
|
1217
|
+
var netValueMap = {
|
|
1218
|
+
mainnet: {
|
|
1219
|
+
pox4ContractAddress: "SP000000000000000000002Q6VF78",
|
|
1220
|
+
pox4ContractName: "pox-4"
|
|
1221
|
+
},
|
|
1222
|
+
testnet: {
|
|
1223
|
+
pox4ContractAddress: "ST000000000000000000002AMW42H",
|
|
1224
|
+
pox4ContractName: "pox-4"
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
function networkDependentValues(network) {
|
|
1228
|
+
return netValueMap[network];
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// src/pox4-api/maps/stacking-state.ts
|
|
1232
|
+
async function stackingState({
|
|
1233
|
+
key,
|
|
1234
|
+
network,
|
|
1235
|
+
baseUrl,
|
|
1236
|
+
apiKeyConfig,
|
|
1237
|
+
proof,
|
|
1238
|
+
tip
|
|
1239
|
+
}) {
|
|
1240
|
+
const [mapEntryError, mapEntryData] = await mapEntry({
|
|
1241
|
+
contractAddress: networkDependentValues(network).pox4ContractAddress,
|
|
1242
|
+
contractName: networkDependentValues(network).pox4ContractName,
|
|
1243
|
+
mapKey: cvToHex(key),
|
|
1244
|
+
mapName: "stacking-state",
|
|
1245
|
+
apiKeyConfig,
|
|
1246
|
+
proof,
|
|
1247
|
+
tip,
|
|
1248
|
+
baseUrl
|
|
1249
|
+
});
|
|
1250
|
+
if (mapEntryError)
|
|
1251
|
+
return error({
|
|
1252
|
+
name: "FetchStackingStateError",
|
|
1253
|
+
message: "Failed to fetch stacking state.",
|
|
1254
|
+
data: mapEntryError
|
|
1255
|
+
});
|
|
1256
|
+
return success({
|
|
1257
|
+
data: hexToCV(mapEntryData.data),
|
|
1258
|
+
proof: mapEntryData.proof
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// src/pox4-api/maps/index.ts
|
|
1263
|
+
var maps = { stackingState };
|
|
1264
|
+
|
|
1265
|
+
// src/pox4-api/read-only/get-stacker-info.ts
|
|
1266
|
+
import {
|
|
1267
|
+
cvToHex as cvToHex2,
|
|
1268
|
+
hexToCV as hexToCV2,
|
|
1269
|
+
principalCV
|
|
1270
|
+
} from "@stacks/transactions";
|
|
1271
|
+
async function getStackerInfo({
|
|
1272
|
+
principal,
|
|
1273
|
+
network,
|
|
1274
|
+
baseUrl,
|
|
1275
|
+
apiKeyConfig
|
|
1276
|
+
}) {
|
|
1277
|
+
const [readOnlyError, readOnlyData] = await stacksRpcApi.smartContracts.readOnly({
|
|
1278
|
+
contractAddress: networkDependentValues(network).pox4ContractAddress,
|
|
1279
|
+
contractName: networkDependentValues(network).pox4ContractName,
|
|
1280
|
+
functionName: "get-stacker-info",
|
|
1281
|
+
arguments: [cvToHex2(principalCV(principal))],
|
|
1282
|
+
baseUrl,
|
|
1283
|
+
apiKeyConfig,
|
|
1284
|
+
sender: principal
|
|
1285
|
+
});
|
|
1286
|
+
if (readOnlyError) {
|
|
1287
|
+
return error({
|
|
1288
|
+
name: "GetStackerInfoError",
|
|
1289
|
+
message: "Failed to get stacker info.",
|
|
1290
|
+
data: readOnlyError
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
if (!readOnlyData.okay) {
|
|
1294
|
+
return error({
|
|
1295
|
+
name: "GetStackerInfoFunctionCallError",
|
|
1296
|
+
message: "Call to `get-stacker-info` failed.",
|
|
1297
|
+
data: readOnlyData
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
return success(hexToCV2(readOnlyData.result));
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
// src/pox4-api/read-only/get-check-delegation.ts
|
|
1304
|
+
import {
|
|
1305
|
+
cvToHex as cvToHex3,
|
|
1306
|
+
hexToCV as hexToCV3,
|
|
1307
|
+
principalCV as principalCV2
|
|
1308
|
+
} from "@stacks/transactions";
|
|
1309
|
+
async function getCheckDelegation({
|
|
1310
|
+
principal,
|
|
1311
|
+
network,
|
|
1312
|
+
baseUrl,
|
|
1313
|
+
apiKeyConfig
|
|
1314
|
+
}) {
|
|
1315
|
+
const [readOnlyError, readOnlyData] = await stacksRpcApi.smartContracts.readOnly({
|
|
1316
|
+
contractAddress: networkDependentValues(network).pox4ContractAddress,
|
|
1317
|
+
contractName: networkDependentValues(network).pox4ContractName,
|
|
1318
|
+
functionName: "get-check-delegation",
|
|
1319
|
+
arguments: [cvToHex3(principalCV2(principal))],
|
|
1320
|
+
baseUrl,
|
|
1321
|
+
apiKeyConfig,
|
|
1322
|
+
sender: principal
|
|
1323
|
+
});
|
|
1324
|
+
if (readOnlyError) {
|
|
1325
|
+
return error({
|
|
1326
|
+
name: "GetCheckDelegationError",
|
|
1327
|
+
message: "Failed to get check delegation.",
|
|
1328
|
+
data: readOnlyError
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
if (!readOnlyData.okay) {
|
|
1332
|
+
return error({
|
|
1333
|
+
name: "GetCheckDelegationFunctionCallError",
|
|
1334
|
+
message: "Call to `get-check-delegation` failed.",
|
|
1335
|
+
data: readOnlyData
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
return success(hexToCV3(readOnlyData.result));
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// src/pox4-api/read-only/index.ts
|
|
1342
|
+
var readOnly2 = {
|
|
1343
|
+
getStackerInfo,
|
|
1344
|
+
getCheckDelegation
|
|
1345
|
+
};
|
|
1346
|
+
|
|
1347
|
+
// src/pox4-api/index.ts
|
|
1348
|
+
var pox4Api = { maps, readOnly: readOnly2 };
|
|
1248
1349
|
export {
|
|
1249
1350
|
callRateLimitedApi,
|
|
1250
1351
|
error,
|
|
1352
|
+
pox4Api,
|
|
1251
1353
|
queries,
|
|
1252
1354
|
safeCall,
|
|
1253
1355
|
safeCallRateLimitedApi,
|