{"version":3,"file":"dcrdata.mjs","names":[],"sources":["../../src/providers/dcrdata.ts"],"sourcesContent":["import { getChain } from \"@agntn/chains\";\nimport { z } from \"zod\";\nimport { Provider } from \"../core/provider.js\";\nimport { normalizeBaseUrl } from \"../core/client.js\";\nimport { DCRDATA_INSIGHT_URL } from \"../core/endpoints.js\";\nimport { ExplorerError, UnsupportedChainError } from \"../core/errors.js\";\nimport { formatWei } from \"../core/types.js\";\nimport type {\n  Balance,\n  BlockInfo,\n  ChainKey,\n  ProviderCapabilities,\n  ProviderConfig,\n  Transaction,\n  TxHistoryOptions,\n} from \"../core/types.js\";\n\nfunction assertChain(chain: ChainKey): void {\n  if (chain !== \"decred\") throw new UnsupportedChainError(chain, Dcrdata.key);\n}\n\nfunction assertAddress(address: string): void {\n  try {\n    getChain(\"decred\").assertAddress(address);\n  } catch {\n    throw new ExplorerError(\"Invalid Decred mainnet address\", Dcrdata.key);\n  }\n}\n\nfunction hashSchema() {\n  return z.string().regex(/^[a-fA-F0-9]{64}$/);\n}\n\nfunction addressTextSchema() {\n  return z.string().regex(/^[1-9A-HJ-NP-Za-km-z]{1,54}$/);\n}\n\nfunction transactionSchema() {\n  return z\n    .object({\n      txid: hashSchema(),\n      blockheight: z.number().int().safe(),\n      confirmations: z.number().int().safe(),\n      blocktime: z.number().int().nonnegative().max(8_640_000_000_000).optional(),\n      time: z.number().int().nonnegative().max(8_640_000_000_000).optional(),\n      fees: z.number().optional(),\n      isCoinBase: z.boolean().optional(),\n      isTreasurybase: z.boolean().optional(),\n      vin: z.array(\n        z\n          .object({\n            addr: addressTextSchema().optional(),\n          })\n          .passthrough(),\n      ),\n      vout: z.array(\n        z\n          .object({\n            value: z.number().nonnegative().max(21_000_000),\n            scriptPubKey: z\n              .object({\n                addresses: z.array(addressTextSchema()).nullish(),\n                hex: z\n                  .string()\n                  .regex(/^(?:[a-fA-F0-9]{2})*$/)\n                  .optional(),\n                type: z.string().optional(),\n              })\n              .passthrough(),\n          })\n          .passthrough(),\n      ),\n    })\n    .passthrough();\n}\n\ntype InsightTransaction = z.infer<ReturnType<typeof transactionSchema>>;\n\n/**\n * Convert decimal spelling, including scientific notation, without multiplying floats.\n * @param {number} value - DCR amount returned by Insight.\n * @returns {string} Exact integer atoms.\n */\nfunction dcrToAtoms(value: number): string {\n  const match = /^(\\d+)(?:\\.(\\d+))?(?:e([+-]?\\d+))?$/.exec(String(value));\n  if (!match || value > 21_000_000) throw new ExplorerError(\"Invalid dcrdata amount\", Dcrdata.key);\n  const fraction = match[2] ?? \"\";\n  const shift = 8 + Number(match[3] ?? 0) - fraction.length;\n  if (shift < -16 || shift > 16) throw new ExplorerError(\"Invalid dcrdata amount\", Dcrdata.key);\n  const digits = BigInt(`${match[1]}${fraction}`);\n  if (shift >= 0) return (digits * 10n ** BigInt(shift)).toString();\n  const divisor = 10n ** BigInt(-shift);\n  if (digits % divisor !== 0n)\n    throw new ExplorerError(\"Fractional atom in dcrdata amount\", Dcrdata.key);\n  return (digits / divisor).toString();\n}\n\ninterface Output {\n  readonly value: number;\n  readonly scriptPubKey: {\n    readonly type?: string;\n    readonly hex?: string;\n    readonly addresses?: readonly string[] | null;\n  };\n}\n\nfunction outputAddress(output?: Output): string {\n  return output?.scriptPubKey.addresses?.[0] ?? \"\";\n}\n\nfunction isAddressedOutput(output: Output): boolean {\n  return (\n    output.scriptPubKey.type !== \"nulldata\" &&\n    !output.scriptPubKey.hex?.toLowerCase().startsWith(\"6a\") &&\n    outputAddress(output) !== \"\"\n  );\n}\n\nfunction selectTransfer(outputs: readonly Output[], address?: string, outgoing = false) {\n  const addressed = outputs.filter(isAddressedOutput);\n  const preferred =\n    address === undefined\n      ? undefined\n      : addressed.find(\n          (output) => Boolean(output.scriptPubKey.addresses?.includes(address)) !== outgoing,\n        );\n  const selected = preferred ?? addressed[0];\n  const to = !outgoing && address && preferred ? address : outputAddress(selected);\n  return { to, value: selected === undefined ? \"0\" : dcrToAtoms(selected.value) };\n}\n\nfunction transactionFee(\n  tx: Readonly<Pick<InsightTransaction, \"fees\" | \"isCoinBase\" | \"isTreasurybase\">>,\n) {\n  if (tx.isCoinBase || tx.isTreasurybase) return { fee: \"0\" };\n  return tx.fees === undefined ? {} : { fee: dcrToAtoms(tx.fees) };\n}\n\nfunction transactionPosition(confirmations: number, height: number, time?: number) {\n  const status = confirmations < 0 ? \"failed\" : confirmations === 0 ? \"pending\" : \"success\";\n  return {\n    status,\n    blockNumber: confirmations > 0 ? height : 0,\n    ...(time === undefined || time === 0 ? {} : { timestamp: new Date(time * 1000).toISOString() }),\n  } as const;\n}\n\n/* oxlint-disable-next-line typescript/prefer-readonly-parameter-types */\nfunction mapTransaction(tx: InsightTransaction, address?: string): Transaction {\n  const outgoing = address !== undefined && tx.vin.some((input) => input.addr === address);\n  const from = (outgoing ? address : tx.vin.find((input) => input.addr)?.addr) ?? \"\";\n  const transfer = selectTransfer(tx.vout, address, outgoing);\n  return {\n    hash: tx.txid,\n    from,\n    ...transfer,\n    valueFormatted: formatWei(transfer.value, 8),\n    ...transactionFee(tx),\n    ...transactionPosition(tx.confirmations, tx.blockheight, tx.blocktime ?? tx.time),\n    isContractInteraction: false,\n    tokenTransfers: [],\n    raw: { ...tx },\n  };\n}\n\nfunction historyWindow(options: Readonly<TxHistoryOptions>) {\n  const limit = options.limit ?? 100;\n  const page = options.page ?? 1;\n  const parsed = z\n    .object({\n      limit: z.number().int().min(1).max(250),\n      page: z.number().int().positive().safe(),\n    })\n    .safeParse({ limit, page });\n  if (!parsed.success || !Number.isSafeInteger(limit * page))\n    throw new ExplorerError(\n      \"dcrdata history requires limit 1 to 250 and a positive safe page window\",\n      Dcrdata.key,\n    );\n  if (options.startBlock !== undefined || options.endBlock !== undefined)\n    throw new ExplorerError(\"dcrdata Insight history does not support block filters\", Dcrdata.key);\n  return { limit, offset: (page - 1) * limit };\n}\n\n/** Decred balances, transactions and blocks from dcrdata's Insight API. */\nexport class Dcrdata extends Provider {\n  static readonly key = \"dcrdata\";\n  private readonly base: string;\n\n  constructor(config: Readonly<ProviderConfig> = {}) {\n    super(config);\n    this.base = normalizeBaseUrl(config.baseUrl ?? DCRDATA_INSIGHT_URL);\n  }\n\n  get capabilities(): ProviderCapabilities {\n    return {\n      balances: true,\n      txHistory: true,\n      txDetail: true,\n      utxos: false,\n      contractInfo: false,\n      tokenBalances: false,\n      tokenTransfers: false,\n      gasData: false,\n      blockInfo: true,\n    };\n  }\n\n  /**\n   * Balance and totals stay confirmed. The signed mempool delta goes to `unconfirmed`.\n   * @param {string} address - Decred mainnet address.\n   * @param {ChainKey} chain - Must be Decred.\n   * @returns {Promise<Balance>} Amounts in atoms, with no block snapshot from Insight.\n   */\n  async getBalance(address: string, chain: ChainKey = \"decred\"): Promise<Balance> {\n    assertChain(chain);\n    assertAddress(address);\n    const raw = await this.getJSON<unknown>(`${this.base}/addr/${address}?noTxList=1`);\n    const atoms = z.union([z.number().int().nonnegative().safe(), z.string().regex(/^\\d+$/)]);\n    const signedAtoms = z.union([z.number().int().safe(), z.string().regex(/^-?\\d+$/)]);\n    const parsed = z\n      .object({\n        addrStr: z.literal(address),\n        balanceSat: atoms,\n        totalReceivedSat: atoms,\n        totalSentSat: atoms,\n        unconfirmedBalanceSat: signedAtoms,\n      })\n      .safeParse(raw);\n    if (!parsed.success) throw new ExplorerError(\"Invalid dcrdata balance response\", this.name);\n    const data = parsed.data;\n    const balance = String(data.balanceSat);\n    return this.snapshotBalance({\n      address,\n      chain,\n      balance,\n      balanceFormatted: formatWei(balance, 8),\n      funded: String(data.totalReceivedSat),\n      spent: String(data.totalSentSat),\n      unconfirmed: BigInt(data.unconfirmedBalanceSat).toString(),\n      symbol: \"DCR\",\n    });\n  }\n\n  override async getTxDetail(hash: string, chain: ChainKey = \"decred\"): Promise<Transaction> {\n    assertChain(chain);\n    if (!hashSchema().safeParse(hash).success)\n      throw new ExplorerError(\"Invalid Decred transaction hash\", this.name);\n    const raw = await this.getJSON<unknown>(`${this.base}/tx/${hash}`);\n    const parsed = transactionSchema().safeParse(raw);\n    if (!parsed.success || parsed.data.txid.toLowerCase() !== hash.toLowerCase())\n      throw new ExplorerError(\"Invalid dcrdata transaction response\", this.name);\n    return mapTransaction(parsed.data);\n  }\n\n  private async historyPage(address: string, from: number, to: number) {\n    const raw = await this.getJSON<unknown>(\n      `${this.base}/addrs/${address}/txs?from=${from}&to=${to}`,\n    );\n    const parsed = z\n      .object({\n        totalItems: z.number().int().nonnegative().safe(),\n        from: z.number().int().nonnegative().safe(),\n        to: z.number().int().nonnegative().safe(),\n        items: z.array(transactionSchema()).max(to - from),\n      })\n      .safeParse(raw);\n    if (!parsed.success) throw new ExplorerError(\"Invalid dcrdata history response\", this.name);\n    const page = parsed.data;\n    const expectedFrom = page.totalItems === 0 ? from : Math.min(from, page.totalItems);\n    const expectedTo = page.totalItems === 0 ? to : Math.min(to, page.totalItems);\n    if (\n      page.from !== expectedFrom ||\n      page.to !== expectedTo ||\n      page.items.length !== Math.max(0, Math.min(to, page.totalItems) - from)\n    )\n      throw new ExplorerError(\"Incomplete dcrdata history page\", this.name);\n    return page;\n  }\n\n  async getTxHistory(\n    address: string,\n    chain: ChainKey = \"decred\",\n    options: Readonly<TxHistoryOptions> = {},\n  ): Promise<Transaction[]> {\n    assertChain(chain);\n    assertAddress(address);\n    const { limit, offset } = historyWindow(options);\n    if (options.sort !== \"asc\") {\n      const result = await this.historyPage(address, offset, offset + limit);\n      return result.items.map((tx) => mapTransaction(tx, address));\n    }\n    const first = await this.historyPage(address, 0, 1);\n    const to = Math.max(0, first.totalItems - offset);\n    if (to === 0) return [];\n    const result = await this.historyPage(address, Math.max(0, to - limit), to);\n    if (result.totalItems !== first.totalItems)\n      throw new ExplorerError(\"dcrdata history changed while paging; retry the read\", this.name);\n    return result.items.reverse().map((tx) => mapTransaction(tx, address));\n  }\n\n  override async getBlockInfo(blockNumber: number, chain: ChainKey = \"decred\"): Promise<BlockInfo> {\n    assertChain(chain);\n    if (!Number.isSafeInteger(blockNumber) || blockNumber < 0)\n      throw new ExplorerError(\"Decred block number must be a nonnegative safe integer\", this.name);\n    const raw = await this.getJSON<unknown>(`${this.base}/block/${blockNumber}`);\n    const parsed = z\n      .array(\n        z.object({\n          height: z.literal(blockNumber),\n          hash: hashSchema(),\n          previousblockhash: hashSchema(),\n          time: z.number().int().nonnegative().max(8_640_000_000_000),\n          tx: z.array(hashSchema()).optional(),\n        }),\n      )\n      .length(1)\n      .safeParse(raw);\n    const block = parsed.success ? parsed.data[0] : undefined;\n    if (!block) throw new ExplorerError(\"Invalid dcrdata block response\", this.name);\n    return {\n      number: block.height,\n      hash: block.hash,\n      parentHash: block.previousblockhash,\n      timestamp: new Date(block.time * 1000).toISOString(),\n      miner: \"\",\n      gasUsed: \"0\",\n      gasLimit: \"0\",\n      txCount: block.tx?.length ?? 0,\n    };\n  }\n}\n"],"mappings":";;;;;;AAiBA,SAAS,YAAY,OAAuB;CAC1C,IAAI,UAAU,UAAU,MAAM,IAAI,sBAAsB,OAAO,QAAQ,GAAG;AAC5E;AAEA,SAAS,cAAc,SAAuB;CAC5C,IAAI;EACF,SAAS,QAAQ,CAAC,CAAC,cAAc,OAAO;CAC1C,QAAQ;EACN,MAAM,IAAI,cAAc,kCAAkC,QAAQ,GAAG;CACvE;AACF;AAEA,SAAS,aAAa;CACpB,OAAO,EAAE,OAAO,CAAC,CAAC,MAAM,mBAAmB;AAC7C;AAEA,SAAS,oBAAoB;CAC3B,OAAO,EAAE,OAAO,CAAC,CAAC,MAAM,8BAA8B;AACxD;AAEA,SAAS,oBAAoB;CAC3B,OAAO,EACJ,OAAO;EACN,MAAM,WAAW;EACjB,aAAa,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK;EACnC,eAAe,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK;EACrC,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,IAAI,MAAiB,CAAC,CAAC,SAAS;EAC1E,MAAM,EAAE,OA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