46 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-04-18 18:22:00 +04:00
import { AbstractLightningApi } from '../lightning-api-abstract-factory';
import { ILightningApi } from '../lightning-api.interface';
import * as fs from 'fs';
import { authenticatedLndGrpc, getWalletInfo, getNetworkGraph, getNetworkInfo } from 'lightning';
import config from '../../../config';
import logger from '../../../logger';
2022-04-18 18:22:00 +04:00
class LndApi implements AbstractLightningApi {
private lnd: any;
constructor() {
if (!config.LIGHTNING.ENABLED) {
return;
}
2022-04-18 18:22:00 +04:00
try {
2022-07-06 13:55:21 +02:00
const tls = fs.readFileSync(config.LND.TLS_CERT_PATH).toString('base64');
const macaroon = fs.readFileSync(config.LND.MACAROON_PATH).toString('base64');
2022-04-18 18:22:00 +04:00
const { lnd } = authenticatedLndGrpc({
2022-07-03 20:07:54 +02:00
cert: tls,
2022-04-18 18:22:00 +04:00
macaroon: macaroon,
2022-07-06 13:55:21 +02:00
socket: config.LND.SOCKET,
2022-04-18 18:22:00 +04:00
});
this.lnd = lnd;
} catch (e) {
logger.err('Could not initiate the LND service handler: ' + (e instanceof Error ? e.message : e));
process.exit(1);
}
}
2022-04-24 01:33:38 +04:00
async $getNetworkInfo(): Promise<ILightningApi.NetworkInfo> {
return await getNetworkInfo({ lnd: this.lnd });
2022-04-18 18:22:00 +04:00
}
async $getInfo(): Promise<ILightningApi.Info> {
// @ts-ignore
return await getWalletInfo({ lnd: this.lnd });
2022-04-18 18:22:00 +04:00
}
2022-04-24 01:33:38 +04:00
async $getNetworkGraph(): Promise<ILightningApi.NetworkGraph> {
return await getNetworkGraph({ lnd: this.lnd });
2022-04-24 01:33:38 +04:00
}
2022-04-18 18:22:00 +04:00
}
export default LndApi;