Replacing ln-service library and wait for graph sync.

This commit is contained in:
softsimon
2022-07-06 21:43:47 +02:00
parent 1f2254681a
commit 73c4a934ce
7 changed files with 73 additions and 35 deletions

View File

@@ -3,5 +3,5 @@ import { ILightningApi } from './lightning-api.interface';
export interface AbstractLightningApi {
$getNetworkInfo(): Promise<ILightningApi.NetworkInfo>;
$getNetworkGraph(): Promise<ILightningApi.NetworkGraph>;
$getChanInfo(id: string): Promise<ILightningApi.Channel>;
$getInfo(): Promise<ILightningApi.Info>;
}

View File

@@ -21,17 +21,17 @@ export namespace ILightningApi {
policies: Policy[];
transaction_id: string;
transaction_vout: number;
updated_at: string;
updated_at?: string;
}
interface Policy {
public_key: string;
base_fee_mtokens?: number;
base_fee_mtokens?: string;
cltv_delta?: number;
fee_rate?: number;
is_disabled?: boolean;
max_htlc_mtokens?: number;
min_htlc_mtokens?: number;
max_htlc_mtokens?: string;
min_htlc_mtokens?: string;
updated_at?: string;
}
@@ -41,13 +41,31 @@ export namespace ILightningApi {
features: Feature[];
public_key: string;
sockets: string[];
updated_at: string;
updated_at?: string;
}
interface Feature {
export interface Info {
chains: string[];
color: string;
active_channels_count: number;
alias: string;
current_block_hash: string;
current_block_height: number;
features: Feature[];
is_synced_to_chain: boolean;
is_synced_to_graph: boolean;
latest_block_at: string;
peers_count: number;
pending_channels_count: number;
public_key: string;
uris: any[];
version: string;
}
export interface Feature {
bit: number;
is_known: boolean;
is_required: boolean;
type: string;
type?: string;
}
}

View File

@@ -1,7 +1,7 @@
import { AbstractLightningApi } from '../lightning-api-abstract-factory';
import { ILightningApi } from '../lightning-api.interface';
import * as fs from 'fs';
import * as lnService from 'ln-service';
import { authenticatedLndGrpc, getWalletInfo, getNetworkGraph, getNetworkInfo } from 'lightning';
import config from '../../../config';
import logger from '../../../logger';
@@ -15,7 +15,7 @@ class LndApi implements AbstractLightningApi {
const tls = fs.readFileSync(config.LND.TLS_CERT_PATH).toString('base64');
const macaroon = fs.readFileSync(config.LND.MACAROON_PATH).toString('base64');
const { lnd } = lnService.authenticatedLndGrpc({
const { lnd } = authenticatedLndGrpc({
cert: tls,
macaroon: macaroon,
socket: config.LND.SOCKET,
@@ -29,15 +29,16 @@ class LndApi implements AbstractLightningApi {
}
async $getNetworkInfo(): Promise<ILightningApi.NetworkInfo> {
return await lnService.getNetworkInfo({ lnd: this.lnd });
return await getNetworkInfo({ lnd: this.lnd });
}
async $getInfo(): Promise<ILightningApi.Info> {
// @ts-ignore
return await getWalletInfo({ lnd: this.lnd });
}
async $getNetworkGraph(): Promise<ILightningApi.NetworkGraph> {
return await lnService.getNetworkGraph({ lnd: this.lnd });
}
async $getChanInfo(id: string): Promise<ILightningApi.Channel> {
return await lnService.getChannel({ lnd: this.lnd, id });
return await getNetworkGraph({ lnd: this.lnd });
}
}