import "../_dnt.polyfills.js"; import { hex } from "../crypto/mod.js" import * as $ from "../deps/scale.js" import { WsConnection } from "../rpc/mod.js" import { withSignal } from "../util/mod.js" export interface NetProps { targets?: Record } export abstract class NetSpec implements NetProps { name!: string // set by `resolveNets.ts` targets abstract connection(name: string): ConnectionSpec abstract metadata(signal: AbortSignal, tempDir: string): Promise constructor({ targets }: NetProps) { this.targets = targets } } export function getMetadataFromWsUrl(url: string) { return withSignal(async (signal) => { const connection = WsConnection.connect(url, signal) const response = await connection.call("state_getMetadata", []) if (response.error) throw new Error("Error getting metadata") return hex.decode(response.result as string) }) } export type ConnectionSpec = $.Output export const $connectionSpec = $.taggedUnion("type", [ $.variant("WsConnection", $.field("discovery", $.str)), $.variant("DevnetConnection", $.field("discovery", $.str)), ])