@secretkeylabs/stacks-tools 0.3.0 → 0.4.0-13a5f23
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 +497 -284
- package/dist/index.d.cts +893 -41
- package/dist/index.d.ts +893 -41
- package/dist/index.js +489 -283
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,6 +16,17 @@ async function safePromise(promise) {
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
function safeCall(fn) {
|
|
20
|
+
try {
|
|
21
|
+
return success(fn());
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return error({
|
|
24
|
+
name: "SafeCallError",
|
|
25
|
+
message: "Safe call failed.",
|
|
26
|
+
data: e
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
19
30
|
|
|
20
31
|
// src/stacks-api/accounts/balances.ts
|
|
21
32
|
import * as v from "valibot";
|
|
@@ -91,42 +102,92 @@ async function balances(opts) {
|
|
|
91
102
|
return success(validationResult.output);
|
|
92
103
|
}
|
|
93
104
|
|
|
105
|
+
// src/stacks-api/accounts/latest-nonce.ts
|
|
106
|
+
import * as v2 from "valibot";
|
|
107
|
+
var responseSchema2 = v2.object({
|
|
108
|
+
last_mempool_tx_nonce: v2.nullable(v2.number()),
|
|
109
|
+
last_executed_tx_nonce: v2.nullable(v2.number()),
|
|
110
|
+
possible_next_nonce: v2.number(),
|
|
111
|
+
detected_missing_nonces: v2.array(v2.number()),
|
|
112
|
+
detected_mempool_nonces: v2.array(v2.number())
|
|
113
|
+
});
|
|
114
|
+
async function latestNonce(opts) {
|
|
115
|
+
const init = {};
|
|
116
|
+
if (opts.apiKeyConfig) {
|
|
117
|
+
init.headers = {
|
|
118
|
+
[opts.apiKeyConfig.header]: opts.apiKeyConfig.key
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const endpoint = `${opts.baseUrl}/extended/v1/address/${opts.principal}/nonces`;
|
|
122
|
+
const res = await fetch(endpoint, init);
|
|
123
|
+
if (!res.ok) {
|
|
124
|
+
return error({
|
|
125
|
+
name: "FetchLatestNonceError",
|
|
126
|
+
message: "Failed to fetch latest nonce.",
|
|
127
|
+
data: {
|
|
128
|
+
endpoint,
|
|
129
|
+
status: res.status,
|
|
130
|
+
statusText: res.statusText,
|
|
131
|
+
bodyParseResult: await safePromise(res.json())
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const [jsonError, data] = await safePromise(res.json());
|
|
136
|
+
if (jsonError) {
|
|
137
|
+
return error({
|
|
138
|
+
name: "ParseBodyError",
|
|
139
|
+
message: "Failed to parse response body as JSON.",
|
|
140
|
+
data: jsonError
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const validationResult = v2.safeParse(responseSchema2, data);
|
|
144
|
+
if (!validationResult.success) {
|
|
145
|
+
return error({
|
|
146
|
+
name: "ValidateDataError",
|
|
147
|
+
message: "Failed to validate data.",
|
|
148
|
+
data: validationResult
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return success(validationResult.output);
|
|
152
|
+
}
|
|
153
|
+
|
|
94
154
|
// src/stacks-api/accounts/index.ts
|
|
95
155
|
var accounts = {
|
|
96
|
-
balances
|
|
156
|
+
balances,
|
|
157
|
+
latestNonce
|
|
97
158
|
};
|
|
98
159
|
|
|
99
160
|
// src/stacks-api/types.ts
|
|
100
|
-
import * as
|
|
101
|
-
var baseListResponseSchema =
|
|
102
|
-
limit:
|
|
103
|
-
offset:
|
|
104
|
-
total:
|
|
105
|
-
results:
|
|
161
|
+
import * as v3 from "valibot";
|
|
162
|
+
var baseListResponseSchema = v3.object({
|
|
163
|
+
limit: v3.number(),
|
|
164
|
+
offset: v3.number(),
|
|
165
|
+
total: v3.number(),
|
|
166
|
+
results: v3.array(v3.unknown())
|
|
106
167
|
});
|
|
107
168
|
|
|
108
169
|
// src/stacks-api/blocks/get-block.ts
|
|
109
|
-
import * as
|
|
110
|
-
var
|
|
111
|
-
canonical:
|
|
112
|
-
height:
|
|
113
|
-
hash:
|
|
114
|
-
block_time:
|
|
115
|
-
block_time_iso:
|
|
116
|
-
index_block_hash:
|
|
117
|
-
parent_block_hash:
|
|
118
|
-
parent_index_block_hash:
|
|
119
|
-
burn_block_time:
|
|
120
|
-
burn_block_time_iso:
|
|
121
|
-
burn_block_hash:
|
|
122
|
-
burn_block_height:
|
|
123
|
-
miner_txid:
|
|
124
|
-
tx_count:
|
|
125
|
-
execution_cost_read_count:
|
|
126
|
-
execution_cost_read_length:
|
|
127
|
-
execution_cost_runtime:
|
|
128
|
-
execution_cost_write_count:
|
|
129
|
-
execution_cost_write_length:
|
|
170
|
+
import * as v4 from "valibot";
|
|
171
|
+
var responseSchema3 = v4.object({
|
|
172
|
+
canonical: v4.boolean(),
|
|
173
|
+
height: v4.number(),
|
|
174
|
+
hash: v4.string(),
|
|
175
|
+
block_time: v4.number(),
|
|
176
|
+
block_time_iso: v4.string(),
|
|
177
|
+
index_block_hash: v4.string(),
|
|
178
|
+
parent_block_hash: v4.string(),
|
|
179
|
+
parent_index_block_hash: v4.string(),
|
|
180
|
+
burn_block_time: v4.number(),
|
|
181
|
+
burn_block_time_iso: v4.string(),
|
|
182
|
+
burn_block_hash: v4.string(),
|
|
183
|
+
burn_block_height: v4.number(),
|
|
184
|
+
miner_txid: v4.string(),
|
|
185
|
+
tx_count: v4.number(),
|
|
186
|
+
execution_cost_read_count: v4.number(),
|
|
187
|
+
execution_cost_read_length: v4.number(),
|
|
188
|
+
execution_cost_runtime: v4.number(),
|
|
189
|
+
execution_cost_write_count: v4.number(),
|
|
190
|
+
execution_cost_write_length: v4.number()
|
|
130
191
|
});
|
|
131
192
|
async function getBlock(opts) {
|
|
132
193
|
const init = {};
|
|
@@ -158,7 +219,7 @@ async function getBlock(opts) {
|
|
|
158
219
|
data: jsonError
|
|
159
220
|
});
|
|
160
221
|
}
|
|
161
|
-
const validationResult =
|
|
222
|
+
const validationResult = v4.safeParse(responseSchema3, data);
|
|
162
223
|
if (!validationResult.success) {
|
|
163
224
|
return error({
|
|
164
225
|
name: "ValidateDataError",
|
|
@@ -174,22 +235,64 @@ var blocks = {
|
|
|
174
235
|
getBlock
|
|
175
236
|
};
|
|
176
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
|
+
|
|
177
279
|
// src/stacks-api/info/core-api.ts
|
|
178
|
-
import * as
|
|
179
|
-
var CoreApiResponseSchema =
|
|
180
|
-
peer_version:
|
|
181
|
-
pox_consensus:
|
|
182
|
-
burn_block_height:
|
|
183
|
-
stable_pox_consensus:
|
|
184
|
-
stable_burn_block_height:
|
|
185
|
-
server_version:
|
|
186
|
-
network_id:
|
|
187
|
-
parent_network_id:
|
|
188
|
-
stacks_tip_height:
|
|
189
|
-
stacks_tip:
|
|
190
|
-
stacks_tip_consensus_hash:
|
|
191
|
-
unanchored_tip:
|
|
192
|
-
|
|
280
|
+
import * as v5 from "valibot";
|
|
281
|
+
var CoreApiResponseSchema = v5.object({
|
|
282
|
+
peer_version: v5.number(),
|
|
283
|
+
pox_consensus: v5.string(),
|
|
284
|
+
burn_block_height: v5.number(),
|
|
285
|
+
stable_pox_consensus: v5.string(),
|
|
286
|
+
stable_burn_block_height: v5.number(),
|
|
287
|
+
server_version: v5.string(),
|
|
288
|
+
network_id: v5.number(),
|
|
289
|
+
parent_network_id: v5.number(),
|
|
290
|
+
stacks_tip_height: v5.number(),
|
|
291
|
+
stacks_tip: v5.string(),
|
|
292
|
+
stacks_tip_consensus_hash: v5.string(),
|
|
293
|
+
unanchored_tip: v5.nullable(v5.string()),
|
|
294
|
+
unanchored_seq: v5.nullable(v5.string()),
|
|
295
|
+
exit_at_block_height: v5.nullable(v5.number())
|
|
193
296
|
});
|
|
194
297
|
async function coreApi(apiOpts) {
|
|
195
298
|
const init = {};
|
|
@@ -218,7 +321,7 @@ async function coreApi(apiOpts) {
|
|
|
218
321
|
data: parseBodyError
|
|
219
322
|
});
|
|
220
323
|
}
|
|
221
|
-
const validationResult =
|
|
324
|
+
const validationResult = v5.safeParse(CoreApiResponseSchema, data);
|
|
222
325
|
if (!validationResult.success) {
|
|
223
326
|
return error({
|
|
224
327
|
name: "ValidateDataError",
|
|
@@ -230,60 +333,60 @@ async function coreApi(apiOpts) {
|
|
|
230
333
|
}
|
|
231
334
|
|
|
232
335
|
// src/stacks-api/info/pox-details.ts
|
|
233
|
-
import * as
|
|
234
|
-
var poxDetailsResponseSchema =
|
|
235
|
-
contract_id:
|
|
236
|
-
pox_activation_threshold_ustx:
|
|
237
|
-
first_burnchain_block_height:
|
|
238
|
-
current_burnchain_block_height:
|
|
239
|
-
prepare_phase_block_length:
|
|
240
|
-
reward_phase_block_length:
|
|
241
|
-
reward_slots:
|
|
242
|
-
rejection_fraction:
|
|
243
|
-
total_liquid_supply_ustx:
|
|
244
|
-
current_cycle:
|
|
245
|
-
id:
|
|
246
|
-
min_threshold_ustx:
|
|
247
|
-
stacked_ustx:
|
|
248
|
-
is_pox_active:
|
|
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()
|
|
249
352
|
}),
|
|
250
|
-
next_cycle:
|
|
251
|
-
id:
|
|
252
|
-
min_threshold_ustx:
|
|
253
|
-
min_increment_ustx:
|
|
254
|
-
stacked_ustx:
|
|
255
|
-
prepare_phase_start_block_height:
|
|
256
|
-
blocks_until_prepare_phase:
|
|
257
|
-
reward_phase_start_block_height:
|
|
258
|
-
blocks_until_reward_phase:
|
|
259
|
-
ustx_until_pox_rejection:
|
|
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()
|
|
260
363
|
}),
|
|
261
|
-
epochs:
|
|
262
|
-
|
|
263
|
-
epoch_id:
|
|
264
|
-
start_height:
|
|
265
|
-
end_height:
|
|
266
|
-
block_limit:
|
|
267
|
-
write_length:
|
|
268
|
-
write_count:
|
|
269
|
-
read_length:
|
|
270
|
-
read_count:
|
|
271
|
-
runtime:
|
|
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()
|
|
272
375
|
}),
|
|
273
|
-
network_epoch:
|
|
376
|
+
network_epoch: v6.number()
|
|
274
377
|
})
|
|
275
378
|
),
|
|
276
|
-
min_amount_ustx:
|
|
277
|
-
prepare_cycle_length:
|
|
278
|
-
reward_cycle_id:
|
|
279
|
-
reward_cycle_length:
|
|
280
|
-
rejection_votes_left_required:
|
|
281
|
-
next_reward_cycle_in:
|
|
282
|
-
contract_versions:
|
|
283
|
-
|
|
284
|
-
contract_id:
|
|
285
|
-
activation_burnchain_block_height:
|
|
286
|
-
first_reward_cycle_id:
|
|
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()
|
|
287
390
|
})
|
|
288
391
|
)
|
|
289
392
|
});
|
|
@@ -314,7 +417,7 @@ async function poxDetails(args) {
|
|
|
314
417
|
data: jsonParseError
|
|
315
418
|
});
|
|
316
419
|
}
|
|
317
|
-
const validationResult =
|
|
420
|
+
const validationResult = v6.safeParse(poxDetailsResponseSchema, data);
|
|
318
421
|
if (!validationResult.success) {
|
|
319
422
|
return error({
|
|
320
423
|
name: "ValidateDataError",
|
|
@@ -332,14 +435,14 @@ var info = {
|
|
|
332
435
|
};
|
|
333
436
|
|
|
334
437
|
// src/stacks-api/proof-of-transfer/cycle.ts
|
|
335
|
-
import * as
|
|
336
|
-
var
|
|
337
|
-
block_height:
|
|
338
|
-
index_block_hash:
|
|
339
|
-
cycle_number:
|
|
340
|
-
total_weight:
|
|
341
|
-
total_stacked_amount:
|
|
342
|
-
total_signers:
|
|
438
|
+
import * as v7 from "valibot";
|
|
439
|
+
var responseSchema4 = v7.object({
|
|
440
|
+
block_height: v7.number(),
|
|
441
|
+
index_block_hash: v7.string(),
|
|
442
|
+
cycle_number: v7.number(),
|
|
443
|
+
total_weight: v7.number(),
|
|
444
|
+
total_stacked_amount: v7.string(),
|
|
445
|
+
total_signers: v7.number()
|
|
343
446
|
});
|
|
344
447
|
async function cycle(opts) {
|
|
345
448
|
const init = {};
|
|
@@ -370,7 +473,7 @@ async function cycle(opts) {
|
|
|
370
473
|
data: jsonError
|
|
371
474
|
});
|
|
372
475
|
}
|
|
373
|
-
const validationResult =
|
|
476
|
+
const validationResult = v7.safeParse(responseSchema4, data);
|
|
374
477
|
if (!validationResult.success) {
|
|
375
478
|
return error({
|
|
376
479
|
name: "ValidateDataError",
|
|
@@ -382,17 +485,17 @@ async function cycle(opts) {
|
|
|
382
485
|
}
|
|
383
486
|
|
|
384
487
|
// src/stacks-api/proof-of-transfer/cycles.ts
|
|
385
|
-
import * as
|
|
386
|
-
var cycleInfoSchema =
|
|
387
|
-
block_height:
|
|
388
|
-
index_block_hash:
|
|
389
|
-
cycle_number:
|
|
390
|
-
total_weight:
|
|
391
|
-
total_stacked_amount:
|
|
392
|
-
total_signers:
|
|
488
|
+
import * as v8 from "valibot";
|
|
489
|
+
var cycleInfoSchema = v8.object({
|
|
490
|
+
block_height: v8.number(),
|
|
491
|
+
index_block_hash: v8.string(),
|
|
492
|
+
cycle_number: v8.number(),
|
|
493
|
+
total_weight: v8.number(),
|
|
494
|
+
total_stacked_amount: v8.string(),
|
|
495
|
+
total_signers: v8.number()
|
|
393
496
|
});
|
|
394
|
-
var resultsSchema =
|
|
395
|
-
var cyclesResponseSchema =
|
|
497
|
+
var resultsSchema = v8.array(cycleInfoSchema);
|
|
498
|
+
var cyclesResponseSchema = v8.object({
|
|
396
499
|
...baseListResponseSchema.entries,
|
|
397
500
|
results: resultsSchema
|
|
398
501
|
});
|
|
@@ -428,7 +531,7 @@ async function cycles(args) {
|
|
|
428
531
|
data: jsonError
|
|
429
532
|
});
|
|
430
533
|
}
|
|
431
|
-
const validationResult =
|
|
534
|
+
const validationResult = v8.safeParse(cyclesResponseSchema, data);
|
|
432
535
|
if (!validationResult.success) {
|
|
433
536
|
return error({
|
|
434
537
|
name: "ValidateDataError",
|
|
@@ -440,16 +543,16 @@ async function cycles(args) {
|
|
|
440
543
|
}
|
|
441
544
|
|
|
442
545
|
// src/stacks-api/proof-of-transfer/signer-in-cycle.ts
|
|
443
|
-
import * as
|
|
444
|
-
var signerInCycleResponseSchema =
|
|
445
|
-
signing_key:
|
|
446
|
-
signer_address:
|
|
447
|
-
weight:
|
|
448
|
-
stacked_amount:
|
|
449
|
-
weight_percent:
|
|
450
|
-
stacked_amount_percent:
|
|
451
|
-
solo_stacker_count:
|
|
452
|
-
pooled_stacker_count:
|
|
546
|
+
import * as v9 from "valibot";
|
|
547
|
+
var signerInCycleResponseSchema = v9.object({
|
|
548
|
+
signing_key: v9.string(),
|
|
549
|
+
signer_address: v9.string(),
|
|
550
|
+
weight: v9.number(),
|
|
551
|
+
stacked_amount: v9.string(),
|
|
552
|
+
weight_percent: v9.number(),
|
|
553
|
+
stacked_amount_percent: v9.number(),
|
|
554
|
+
solo_stacker_count: v9.number(),
|
|
555
|
+
pooled_stacker_count: v9.number()
|
|
453
556
|
});
|
|
454
557
|
async function signerInCycle(args) {
|
|
455
558
|
const init = {};
|
|
@@ -485,7 +588,7 @@ async function signerInCycle(args) {
|
|
|
485
588
|
}
|
|
486
589
|
});
|
|
487
590
|
}
|
|
488
|
-
const validationResult =
|
|
591
|
+
const validationResult = v9.safeParse(signerInCycleResponseSchema, data);
|
|
489
592
|
if (!validationResult.success) {
|
|
490
593
|
return error({
|
|
491
594
|
name: "ValidateDataError",
|
|
@@ -497,19 +600,19 @@ async function signerInCycle(args) {
|
|
|
497
600
|
}
|
|
498
601
|
|
|
499
602
|
// src/stacks-api/proof-of-transfer/signers-in-cycle.ts
|
|
500
|
-
import * as
|
|
501
|
-
var signerSchema =
|
|
502
|
-
signing_key:
|
|
503
|
-
signer_address:
|
|
504
|
-
weight:
|
|
505
|
-
stacked_amount:
|
|
506
|
-
weight_percent:
|
|
507
|
-
stacked_amount_percent:
|
|
508
|
-
pooled_stacker_count:
|
|
509
|
-
solo_stacker_count:
|
|
603
|
+
import * as v10 from "valibot";
|
|
604
|
+
var signerSchema = v10.object({
|
|
605
|
+
signing_key: v10.string(),
|
|
606
|
+
signer_address: v10.string(),
|
|
607
|
+
weight: v10.number(),
|
|
608
|
+
stacked_amount: v10.string(),
|
|
609
|
+
weight_percent: v10.number(),
|
|
610
|
+
stacked_amount_percent: v10.number(),
|
|
611
|
+
pooled_stacker_count: v10.number(),
|
|
612
|
+
solo_stacker_count: v10.number()
|
|
510
613
|
});
|
|
511
|
-
var resultsSchema2 =
|
|
512
|
-
var signersResponseSchema =
|
|
614
|
+
var resultsSchema2 = v10.array(signerSchema);
|
|
615
|
+
var signersResponseSchema = v10.object({
|
|
513
616
|
...baseListResponseSchema.entries,
|
|
514
617
|
results: resultsSchema2
|
|
515
618
|
});
|
|
@@ -548,7 +651,7 @@ async function signersInCycle(args) {
|
|
|
548
651
|
}
|
|
549
652
|
});
|
|
550
653
|
}
|
|
551
|
-
const validationResult =
|
|
654
|
+
const validationResult = v10.safeParse(signersResponseSchema, data);
|
|
552
655
|
if (!validationResult.success) {
|
|
553
656
|
return error({
|
|
554
657
|
name: "ValidateDataError",
|
|
@@ -560,15 +663,15 @@ async function signersInCycle(args) {
|
|
|
560
663
|
}
|
|
561
664
|
|
|
562
665
|
// src/stacks-api/proof-of-transfer/stackers-for-signer-in-cycle.ts
|
|
563
|
-
import * as
|
|
564
|
-
var stackerInfoSchema =
|
|
565
|
-
stacker_address:
|
|
566
|
-
stacked_amount:
|
|
567
|
-
pox_address:
|
|
568
|
-
stacker_type:
|
|
666
|
+
import * as v11 from "valibot";
|
|
667
|
+
var stackerInfoSchema = v11.object({
|
|
668
|
+
stacker_address: v11.string(),
|
|
669
|
+
stacked_amount: v11.string(),
|
|
670
|
+
pox_address: v11.string(),
|
|
671
|
+
stacker_type: v11.union([v11.literal("pooled"), v11.literal("solo")])
|
|
569
672
|
});
|
|
570
|
-
var resultsSchema3 =
|
|
571
|
-
var stackersForSignerInCycleResponseSchema =
|
|
673
|
+
var resultsSchema3 = v11.array(stackerInfoSchema);
|
|
674
|
+
var stackersForSignerInCycleResponseSchema = v11.object({
|
|
572
675
|
...baseListResponseSchema.entries,
|
|
573
676
|
results: resultsSchema3
|
|
574
677
|
});
|
|
@@ -582,7 +685,8 @@ async function stackersForSignerInCycle(opts) {
|
|
|
582
685
|
[opts.apiKeyConfig.header]: opts.apiKeyConfig.key
|
|
583
686
|
};
|
|
584
687
|
}
|
|
585
|
-
const
|
|
688
|
+
const signerPublicKeyPathParam = opts.signerPublicKey.startsWith("0x") ? opts.signerPublicKey : `0x${opts.signerPublicKey}`;
|
|
689
|
+
const endpoint = `${opts.baseUrl}/extended/v2/pox/cycles/${opts.cycleNumber}/signers/${signerPublicKeyPathParam}/stackers?${search}`;
|
|
586
690
|
const res = await fetch(endpoint, init);
|
|
587
691
|
if (!res.ok) {
|
|
588
692
|
return error({
|
|
@@ -604,7 +708,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
604
708
|
data: jsonError
|
|
605
709
|
});
|
|
606
710
|
}
|
|
607
|
-
const validationResult =
|
|
711
|
+
const validationResult = v11.safeParse(
|
|
608
712
|
stackersForSignerInCycleResponseSchema,
|
|
609
713
|
data
|
|
610
714
|
);
|
|
@@ -628,28 +732,37 @@ var proofOfTransfer = {
|
|
|
628
732
|
};
|
|
629
733
|
|
|
630
734
|
// src/stacks-api/smart-contracts/read-only.ts
|
|
631
|
-
import * as
|
|
632
|
-
var readOnlyResponseSchema =
|
|
633
|
-
|
|
634
|
-
okay:
|
|
635
|
-
|
|
735
|
+
import * as v12 from "valibot";
|
|
736
|
+
var readOnlyResponseSchema = v12.variant("okay", [
|
|
737
|
+
v12.object({
|
|
738
|
+
okay: v12.literal(true),
|
|
739
|
+
/**
|
|
740
|
+
* A Clarity value as a hex-encoded string.
|
|
741
|
+
*/
|
|
742
|
+
result: v12.string()
|
|
636
743
|
}),
|
|
637
|
-
|
|
638
|
-
okay:
|
|
639
|
-
cause:
|
|
744
|
+
v12.object({
|
|
745
|
+
okay: v12.literal(false),
|
|
746
|
+
cause: v12.unknown()
|
|
640
747
|
})
|
|
641
748
|
]);
|
|
642
|
-
async function readOnly(
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
749
|
+
async function readOnly(args) {
|
|
750
|
+
const headers = {
|
|
751
|
+
"Content-Type": "application/json"
|
|
752
|
+
};
|
|
753
|
+
if (args.apiKeyConfig) {
|
|
754
|
+
headers[args.apiKeyConfig.header] = args.apiKeyConfig.key;
|
|
648
755
|
}
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
756
|
+
const init = {
|
|
757
|
+
method: "POST",
|
|
758
|
+
body: JSON.stringify({
|
|
759
|
+
sender: args.sender,
|
|
760
|
+
arguments: args.arguments
|
|
761
|
+
}),
|
|
762
|
+
headers
|
|
763
|
+
};
|
|
764
|
+
const endpoint = `${args.baseUrl}/v2/contracts/call-read/${args.contractAddress}/${args.contractName}/${args.functionName}`;
|
|
765
|
+
const res = await fetch(endpoint, init);
|
|
653
766
|
if (!res.ok) {
|
|
654
767
|
return error({
|
|
655
768
|
name: "FetchReadOnlyError",
|
|
@@ -669,7 +782,7 @@ async function readOnly(opts, apiOpts) {
|
|
|
669
782
|
data: error
|
|
670
783
|
});
|
|
671
784
|
}
|
|
672
|
-
const validationResult =
|
|
785
|
+
const validationResult = v12.safeParse(readOnlyResponseSchema, data);
|
|
673
786
|
if (!validationResult.success) {
|
|
674
787
|
return error({
|
|
675
788
|
name: "ValidateDataError",
|
|
@@ -686,37 +799,35 @@ var smartContracts = {
|
|
|
686
799
|
};
|
|
687
800
|
|
|
688
801
|
// src/stacks-api/stacking-pool/members.ts
|
|
689
|
-
import * as
|
|
690
|
-
var memberSchema =
|
|
691
|
-
stacker:
|
|
692
|
-
pox_addr:
|
|
693
|
-
amount_ustx:
|
|
694
|
-
burn_block_unlock_height:
|
|
695
|
-
block_height:
|
|
696
|
-
tx_id:
|
|
802
|
+
import * as v13 from "valibot";
|
|
803
|
+
var memberSchema = v13.object({
|
|
804
|
+
stacker: v13.string(),
|
|
805
|
+
pox_addr: v13.optional(v13.string()),
|
|
806
|
+
amount_ustx: v13.string(),
|
|
807
|
+
burn_block_unlock_height: v13.optional(v13.number()),
|
|
808
|
+
block_height: v13.number(),
|
|
809
|
+
tx_id: v13.string()
|
|
697
810
|
});
|
|
698
|
-
var membersResponseSchema =
|
|
699
|
-
limit:
|
|
700
|
-
offset:
|
|
701
|
-
total:
|
|
702
|
-
results:
|
|
811
|
+
var membersResponseSchema = v13.object({
|
|
812
|
+
limit: v13.number(),
|
|
813
|
+
offset: v13.number(),
|
|
814
|
+
total: v13.number(),
|
|
815
|
+
results: v13.array(memberSchema)
|
|
703
816
|
});
|
|
704
|
-
async function members(
|
|
817
|
+
async function members(args) {
|
|
705
818
|
const search = new URLSearchParams();
|
|
706
|
-
if (
|
|
707
|
-
if (
|
|
708
|
-
if (
|
|
709
|
-
if (
|
|
819
|
+
if (args.afterBlock) search.append("after_block", args.afterBlock.toString());
|
|
820
|
+
if (args.unanchored) search.append("unanchored", "true");
|
|
821
|
+
if (args.limit) search.append("limit", args.limit.toString());
|
|
822
|
+
if (args.offset) search.append("offset", args.offset.toString());
|
|
710
823
|
const init = {};
|
|
711
|
-
if (
|
|
824
|
+
if (args.apiKeyConfig) {
|
|
712
825
|
init.headers = {
|
|
713
|
-
[
|
|
826
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
714
827
|
};
|
|
715
828
|
}
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
init
|
|
719
|
-
);
|
|
829
|
+
const endpoint = `${args.baseUrl}/extended/v1/pox4/${args.poolPrincipal}/delegations?${search}`;
|
|
830
|
+
const res = await fetch(endpoint, init);
|
|
720
831
|
if (!res.ok) {
|
|
721
832
|
return error({
|
|
722
833
|
name: "FetchMembersError",
|
|
@@ -736,7 +847,7 @@ async function members(opts, apiOpts) {
|
|
|
736
847
|
data: jsonParseError
|
|
737
848
|
});
|
|
738
849
|
}
|
|
739
|
-
const validationResult =
|
|
850
|
+
const validationResult = v13.safeParse(membersResponseSchema, data);
|
|
740
851
|
if (!validationResult.success) {
|
|
741
852
|
return error({
|
|
742
853
|
name: "ValidateDataError",
|
|
@@ -753,116 +864,120 @@ var stackingPool = {
|
|
|
753
864
|
};
|
|
754
865
|
|
|
755
866
|
// src/stacks-api/transactions/schemas.ts
|
|
756
|
-
import * as
|
|
757
|
-
var baseTransactionSchema =
|
|
758
|
-
tx_id:
|
|
759
|
-
nonce:
|
|
760
|
-
fee_rate:
|
|
761
|
-
sender_address:
|
|
762
|
-
sponsored:
|
|
763
|
-
post_condition_mode:
|
|
764
|
-
post_conditions:
|
|
765
|
-
anchor_mode:
|
|
766
|
-
is_unanchored:
|
|
767
|
-
block_hash:
|
|
768
|
-
parent_block_hash:
|
|
769
|
-
block_height:
|
|
770
|
-
block_time:
|
|
771
|
-
block_time_iso:
|
|
772
|
-
burn_block_height:
|
|
773
|
-
burn_block_time:
|
|
774
|
-
burn_block_time_iso:
|
|
775
|
-
parent_burn_block_time:
|
|
776
|
-
parent_burn_block_time_iso:
|
|
777
|
-
canonical:
|
|
778
|
-
tx_index:
|
|
779
|
-
tx_status:
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
867
|
+
import * as v14 from "valibot";
|
|
868
|
+
var baseTransactionSchema = v14.object({
|
|
869
|
+
tx_id: v14.string(),
|
|
870
|
+
nonce: v14.number(),
|
|
871
|
+
fee_rate: v14.string(),
|
|
872
|
+
sender_address: v14.string(),
|
|
873
|
+
sponsored: v14.boolean(),
|
|
874
|
+
post_condition_mode: v14.string(),
|
|
875
|
+
post_conditions: v14.array(v14.unknown()),
|
|
876
|
+
anchor_mode: v14.string(),
|
|
877
|
+
is_unanchored: v14.boolean(),
|
|
878
|
+
block_hash: v14.string(),
|
|
879
|
+
parent_block_hash: v14.string(),
|
|
880
|
+
block_height: v14.number(),
|
|
881
|
+
block_time: v14.number(),
|
|
882
|
+
block_time_iso: v14.string(),
|
|
883
|
+
burn_block_height: v14.number(),
|
|
884
|
+
burn_block_time: v14.number(),
|
|
885
|
+
burn_block_time_iso: v14.string(),
|
|
886
|
+
parent_burn_block_time: v14.number(),
|
|
887
|
+
parent_burn_block_time_iso: v14.string(),
|
|
888
|
+
canonical: v14.boolean(),
|
|
889
|
+
tx_index: v14.number(),
|
|
890
|
+
tx_status: v14.union([
|
|
891
|
+
v14.literal("success"),
|
|
892
|
+
v14.literal("abort_by_response"),
|
|
893
|
+
v14.literal("abort_by_post_condition")
|
|
894
|
+
]),
|
|
895
|
+
tx_result: v14.object({
|
|
896
|
+
hex: v14.string(),
|
|
897
|
+
repr: v14.string()
|
|
783
898
|
}),
|
|
784
|
-
microblock_hash:
|
|
785
|
-
microblock_sequence:
|
|
786
|
-
microblock_canonical:
|
|
787
|
-
event_count:
|
|
788
|
-
events:
|
|
789
|
-
execution_cost_read_count:
|
|
790
|
-
execution_cost_read_length:
|
|
791
|
-
execution_cost_runtime:
|
|
792
|
-
execution_cost_write_count:
|
|
793
|
-
execution_cost_write_length:
|
|
899
|
+
microblock_hash: v14.string(),
|
|
900
|
+
microblock_sequence: v14.number(),
|
|
901
|
+
microblock_canonical: v14.boolean(),
|
|
902
|
+
event_count: v14.number(),
|
|
903
|
+
events: v14.array(v14.unknown()),
|
|
904
|
+
execution_cost_read_count: v14.number(),
|
|
905
|
+
execution_cost_read_length: v14.number(),
|
|
906
|
+
execution_cost_runtime: v14.number(),
|
|
907
|
+
execution_cost_write_count: v14.number(),
|
|
908
|
+
execution_cost_write_length: v14.number()
|
|
794
909
|
});
|
|
795
|
-
var contractCallTransactionSchema =
|
|
796
|
-
tx_type:
|
|
797
|
-
contract_call:
|
|
798
|
-
contract_id:
|
|
799
|
-
function_name:
|
|
800
|
-
function_signature:
|
|
801
|
-
function_args:
|
|
802
|
-
|
|
803
|
-
hex:
|
|
804
|
-
repr:
|
|
805
|
-
name:
|
|
806
|
-
type:
|
|
910
|
+
var contractCallTransactionSchema = v14.object({
|
|
911
|
+
tx_type: v14.literal("contract_call"),
|
|
912
|
+
contract_call: v14.object({
|
|
913
|
+
contract_id: v14.string(),
|
|
914
|
+
function_name: v14.string(),
|
|
915
|
+
function_signature: v14.string(),
|
|
916
|
+
function_args: v14.array(
|
|
917
|
+
v14.object({
|
|
918
|
+
hex: v14.string(),
|
|
919
|
+
repr: v14.string(),
|
|
920
|
+
name: v14.string(),
|
|
921
|
+
type: v14.string()
|
|
807
922
|
})
|
|
808
923
|
)
|
|
809
924
|
}),
|
|
810
925
|
...baseTransactionSchema.entries
|
|
811
926
|
});
|
|
812
|
-
var smartContractTransactionSchema =
|
|
813
|
-
tx_type:
|
|
814
|
-
smart_contract:
|
|
927
|
+
var smartContractTransactionSchema = v14.object({
|
|
928
|
+
tx_type: v14.literal("smart_contract"),
|
|
929
|
+
smart_contract: v14.object({
|
|
815
930
|
/**
|
|
816
931
|
* NOTE: The types may be wrong, not sure what type of value is used when
|
|
817
932
|
* the version is not `null`.
|
|
818
933
|
*/
|
|
819
|
-
clarity_version:
|
|
820
|
-
contract_id:
|
|
821
|
-
source_code:
|
|
934
|
+
clarity_version: v14.union([v14.null(), v14.number()]),
|
|
935
|
+
contract_id: v14.string(),
|
|
936
|
+
source_code: v14.string()
|
|
822
937
|
}),
|
|
823
938
|
...baseTransactionSchema.entries
|
|
824
939
|
});
|
|
825
|
-
var tokenTransferSchema =
|
|
826
|
-
tx_type:
|
|
827
|
-
token_transfer:
|
|
828
|
-
recipient_address:
|
|
829
|
-
amount:
|
|
830
|
-
memo:
|
|
940
|
+
var tokenTransferSchema = v14.object({
|
|
941
|
+
tx_type: v14.literal("token_transfer"),
|
|
942
|
+
token_transfer: v14.object({
|
|
943
|
+
recipient_address: v14.string(),
|
|
944
|
+
amount: v14.string(),
|
|
945
|
+
memo: v14.string()
|
|
831
946
|
}),
|
|
832
947
|
...baseTransactionSchema.entries
|
|
833
948
|
});
|
|
834
|
-
var transactionSchema =
|
|
949
|
+
var transactionSchema = v14.variant("tx_type", [
|
|
835
950
|
contractCallTransactionSchema,
|
|
836
951
|
smartContractTransactionSchema,
|
|
837
952
|
tokenTransferSchema
|
|
838
953
|
]);
|
|
839
954
|
|
|
840
955
|
// src/stacks-api/transactions/address-transactions.ts
|
|
841
|
-
import * as
|
|
842
|
-
var resultSchema =
|
|
956
|
+
import * as v15 from "valibot";
|
|
957
|
+
var resultSchema = v15.object({
|
|
843
958
|
tx: transactionSchema,
|
|
844
|
-
stx_sent:
|
|
845
|
-
stx_received:
|
|
846
|
-
events:
|
|
847
|
-
stx:
|
|
848
|
-
transfer:
|
|
849
|
-
mint:
|
|
850
|
-
burn:
|
|
959
|
+
stx_sent: v15.string(),
|
|
960
|
+
stx_received: v15.string(),
|
|
961
|
+
events: v15.object({
|
|
962
|
+
stx: v15.object({
|
|
963
|
+
transfer: v15.number(),
|
|
964
|
+
mint: v15.number(),
|
|
965
|
+
burn: v15.number()
|
|
851
966
|
}),
|
|
852
|
-
ft:
|
|
853
|
-
transfer:
|
|
854
|
-
mint:
|
|
855
|
-
burn:
|
|
967
|
+
ft: v15.object({
|
|
968
|
+
transfer: v15.number(),
|
|
969
|
+
mint: v15.number(),
|
|
970
|
+
burn: v15.number()
|
|
856
971
|
}),
|
|
857
|
-
nft:
|
|
858
|
-
transfer:
|
|
859
|
-
mint:
|
|
860
|
-
burn:
|
|
972
|
+
nft: v15.object({
|
|
973
|
+
transfer: v15.number(),
|
|
974
|
+
mint: v15.number(),
|
|
975
|
+
burn: v15.number()
|
|
861
976
|
})
|
|
862
977
|
})
|
|
863
978
|
});
|
|
864
|
-
var resultsSchema4 =
|
|
865
|
-
var addressTransactionsResponseSchema =
|
|
979
|
+
var resultsSchema4 = v15.array(resultSchema);
|
|
980
|
+
var addressTransactionsResponseSchema = v15.object({
|
|
866
981
|
...baseListResponseSchema.entries,
|
|
867
982
|
results: resultsSchema4
|
|
868
983
|
});
|
|
@@ -899,7 +1014,7 @@ async function addressTransactions(args) {
|
|
|
899
1014
|
data: jsonParseError
|
|
900
1015
|
});
|
|
901
1016
|
}
|
|
902
|
-
const validationResult =
|
|
1017
|
+
const validationResult = v15.safeParse(addressTransactionsResponseSchema, data);
|
|
903
1018
|
if (!validationResult.success) {
|
|
904
1019
|
return error({
|
|
905
1020
|
name: "ValidateDataError",
|
|
@@ -911,7 +1026,7 @@ async function addressTransactions(args) {
|
|
|
911
1026
|
}
|
|
912
1027
|
|
|
913
1028
|
// src/stacks-api/transactions/get-transaction.ts
|
|
914
|
-
import * as
|
|
1029
|
+
import * as v16 from "valibot";
|
|
915
1030
|
async function getTransaction(args) {
|
|
916
1031
|
const init = {};
|
|
917
1032
|
if (args.apiKeyConfig) {
|
|
@@ -940,7 +1055,7 @@ async function getTransaction(args) {
|
|
|
940
1055
|
error: jsonParseError
|
|
941
1056
|
});
|
|
942
1057
|
}
|
|
943
|
-
const validationResult =
|
|
1058
|
+
const validationResult = v16.safeParse(transactionSchema, data);
|
|
944
1059
|
if (!validationResult.success) {
|
|
945
1060
|
return error({
|
|
946
1061
|
name: "ValidateDataError",
|
|
@@ -961,6 +1076,7 @@ var transactions = {
|
|
|
961
1076
|
var stacksApi = {
|
|
962
1077
|
accounts,
|
|
963
1078
|
blocks,
|
|
1079
|
+
faucets,
|
|
964
1080
|
info,
|
|
965
1081
|
proofOfTransfer,
|
|
966
1082
|
smartContracts,
|
|
@@ -968,14 +1084,97 @@ var stacksApi = {
|
|
|
968
1084
|
transactions
|
|
969
1085
|
};
|
|
970
1086
|
|
|
1087
|
+
// src/stacks-rpc-api/smart-contracts/map-entry.ts
|
|
1088
|
+
import * as v17 from "valibot";
|
|
1089
|
+
var mapEntryResponseSchema = v17.object({
|
|
1090
|
+
/**
|
|
1091
|
+
* Hex-encoded string of clarity value. It is always an optional tuple.
|
|
1092
|
+
*/
|
|
1093
|
+
data: v17.string(),
|
|
1094
|
+
/**
|
|
1095
|
+
* Hex-encoded string of the MARF proof for the data
|
|
1096
|
+
*/
|
|
1097
|
+
proof: v17.optional(v17.string())
|
|
1098
|
+
});
|
|
1099
|
+
async function mapEntry(args) {
|
|
1100
|
+
const search = new URLSearchParams();
|
|
1101
|
+
if (args.proof === 0) search.append("proof", "0");
|
|
1102
|
+
if (args.tip) search.append("tip", args.tip);
|
|
1103
|
+
const init = {};
|
|
1104
|
+
if (args.apiKeyConfig) {
|
|
1105
|
+
init.headers = {
|
|
1106
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
init.method = "POST";
|
|
1110
|
+
init.body = args.mapKey;
|
|
1111
|
+
const endpoint = `${args.baseUrl}/v2/map_entry/${args.contractAddress}/${args.contractName}/${args.mapName}?${search}`;
|
|
1112
|
+
const res = await fetch(endpoint, init);
|
|
1113
|
+
if (!res.ok) {
|
|
1114
|
+
return error({
|
|
1115
|
+
name: "FetchMapEntryError",
|
|
1116
|
+
message: "Failed to fetch map entry.",
|
|
1117
|
+
data: {
|
|
1118
|
+
status: res.status,
|
|
1119
|
+
statusText: res.statusText,
|
|
1120
|
+
bodyParseResult: await safePromise(res.json())
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
const [jsonError, data] = await safePromise(res.json());
|
|
1125
|
+
if (jsonError) {
|
|
1126
|
+
return error({
|
|
1127
|
+
name: "ParseBodyError",
|
|
1128
|
+
message: "Failed to parse response body as JSON.",
|
|
1129
|
+
data: jsonError
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
const validationResult = v17.safeParse(mapEntryResponseSchema, data);
|
|
1133
|
+
if (!validationResult.success) {
|
|
1134
|
+
return error({
|
|
1135
|
+
name: "ValidateDataError",
|
|
1136
|
+
message: "Failed to validate response data.",
|
|
1137
|
+
data: validationResult
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
return success(validationResult.output);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// src/stacks-rpc-api/smart-contracts/index.ts
|
|
1144
|
+
var smartContracts2 = {
|
|
1145
|
+
mapEntry
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
// src/stacks-rpc-api/index.ts
|
|
1149
|
+
var stacksRpcApi = {
|
|
1150
|
+
smartContracts: smartContracts2
|
|
1151
|
+
};
|
|
1152
|
+
|
|
971
1153
|
// src/utils/call-rate-limited-api.ts
|
|
972
1154
|
import { backOff } from "exponential-backoff";
|
|
1155
|
+
var defaultStartingDelay = 15e3;
|
|
1156
|
+
var defaultNumOfAttempts = 5;
|
|
1157
|
+
function callRateLimitedApi(fn, options) {
|
|
1158
|
+
return backOff(fn, {
|
|
1159
|
+
startingDelay: options?.startingDelay ?? defaultStartingDelay,
|
|
1160
|
+
numOfAttempts: options?.numOfAttempts ?? defaultNumOfAttempts
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
973
1163
|
async function safeCallRateLimitedApi(fn, options) {
|
|
974
1164
|
try {
|
|
975
|
-
return await backOff(
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1165
|
+
return await backOff(
|
|
1166
|
+
async () => {
|
|
1167
|
+
const [error2, data] = await fn();
|
|
1168
|
+
if (error2) {
|
|
1169
|
+
throw error2;
|
|
1170
|
+
}
|
|
1171
|
+
return success(data);
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
startingDelay: options?.startingDelay ?? 15e3,
|
|
1175
|
+
numOfAttempts: options?.numOfAttempts ?? 5
|
|
1176
|
+
}
|
|
1177
|
+
);
|
|
979
1178
|
} catch (error2) {
|
|
980
1179
|
return error({
|
|
981
1180
|
name: "MaxRetriesExceeded",
|
|
@@ -1026,7 +1225,7 @@ async function getSignerStackedAmount(args) {
|
|
|
1026
1225
|
}
|
|
1027
1226
|
}
|
|
1028
1227
|
}
|
|
1029
|
-
offset +=
|
|
1228
|
+
offset += data.results.length;
|
|
1030
1229
|
hasMore = offset < data.total;
|
|
1031
1230
|
}
|
|
1032
1231
|
if (!found) {
|
|
@@ -1047,6 +1246,13 @@ var queries = {
|
|
|
1047
1246
|
getSignerStackedAmount
|
|
1048
1247
|
};
|
|
1049
1248
|
export {
|
|
1249
|
+
callRateLimitedApi,
|
|
1250
|
+
error,
|
|
1050
1251
|
queries,
|
|
1051
|
-
|
|
1252
|
+
safeCall,
|
|
1253
|
+
safeCallRateLimitedApi,
|
|
1254
|
+
safePromise,
|
|
1255
|
+
stacksApi,
|
|
1256
|
+
stacksRpcApi,
|
|
1257
|
+
success
|
|
1052
1258
|
};
|