// Generated, do not edit. sha256:bf0605d21f5259254ae5ab85694c9ae241adda242e38f4332cc0db1ae9405d9d import { CONFIG } from '../../shared/config.js'; import { t } from '../i18n/index.js'; import { serverFoutTekst } from '../data/_rpc.js'; async function api(path, { method = 'GET', body = null } = {}) { const ctl = new AbortController(); const timer = setTimeout(() => ctl.abort(), CONFIG.LND.CLIENT_TIMEOUT_MS); try { const res = await fetch(path, { method, signal: ctl.signal, ...(body ? { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}), }); const json = await res.json().catch(() => null); if (!res.ok) throw new Error(serverFoutTekst(json) || `HTTP ${res.status}`); return json; } catch (e) { if (e.name === 'AbortError') throw new Error(t('common.backendSilent', { s: CONFIG.LND.CLIENT_TIMEOUT_MS / 1000 })); throw e; } finally { clearTimeout(timer); } } export const status = id => api(`/api/lnd/status?connection=${encodeURIComponent(id)}`); export const setConfig = (id, { url, macaroon, tls_cert }) => api('/api/lnd/config', { method: 'POST', body: { connection: id, url, macaroon, tls_cert } }); export const purgeConfig = id => api('/api/lnd/delete', { method: 'POST', body: { connection: id } }); export const call = (id, endpoint, { query = null, body = null } = {}) => api('/api/lnd/call', { method: 'POST', body: { connection: id, endpoint, query, body } }); export const getInfo = id => call(id, 'getinfo'); export const channelBalance = id => call(id, 'balance_channels'); export const blockchainBalance = id => call(id, 'balance_blockchain'); export const listChannels = id => call(id, 'channels'); export const listClosedChannels = id => call(id, 'channels_closed'); export const listPayments = (id, query = {}) => call(id, 'payments', { query }); export const listInvoices = (id, query = {}) => call(id, 'invoices', { query }); export const forwardingHistory = (id, body = {}) => call(id, 'forwarding', { body }); export async function testLnd(id) { const info = await getInfo(id); return { alias: info.alias || null, synced: !!info.synced_to_chain, blockHeight: Number(info.block_height) || 0, }; }