mirror of
https://github.com/alexgo-io/brc20-indexer-contracts.git
synced 2026-01-12 22:21:46 +08:00
* feat: dev-stack & bootstrap Signed-off-by: bestmike007 <i@bestmike007.com> * chore: contract codegen Signed-off-by: bestmike007 <i@bestmike007.com> * chore: add depends_on Signed-off-by: bestmike007 <i@bestmike007.com> --------- Signed-off-by: bestmike007 <i@bestmike007.com>
34 lines
1005 B
TypeScript
34 lines
1005 B
TypeScript
import { CoreNodeInfoResponse } from '@stacks/stacks-blockchain-api-types';
|
|
import { STACKS_API_URL } from '../constants';
|
|
|
|
export function assertNever(x: never): never {
|
|
throw new Error('Unexpected object: ' + x);
|
|
}
|
|
|
|
export function assert(condition: unknown, message: string): asserts condition {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
|
|
export async function getCurrentInfo(): Promise<CoreNodeInfoResponse> {
|
|
return fetch(`${STACKS_API_URL()}/v2/info`).then(res => res.json());
|
|
}
|
|
|
|
export function isNotNull<T>(input: T | undefined | null): input is T {
|
|
return input != null;
|
|
}
|
|
|
|
export function sleep(ms: number): Promise<void> {
|
|
return new Promise(r => setTimeout(r, ms));
|
|
}
|
|
|
|
export async function repeatForever(fn: () => Promise<void>, interval: number) {
|
|
// noinspection InfiniteLoopJS
|
|
while (true) {
|
|
await fn().catch(e => console.error(e));
|
|
await sleep(interval);
|
|
}
|
|
}
|
|
export function random<T>(array: T[]): T {
|
|
return array[Math.floor(Math.random() * array.length)];
|
|
}
|