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 * as lnService from 'ln-service';
|
2022-04-27 02:52:23 +04:00
|
|
|
import config from '../../../config';
|
|
|
|
import logger from '../../../logger';
|
2022-04-18 18:22:00 +04:00
|
|
|
|
|
|
|
class LndApi implements AbstractLightningApi {
|
|
|
|
private lnd: any;
|
|
|
|
constructor() {
|
|
|
|
try {
|
2022-07-03 16:39:06 +02:00
|
|
|
const tsl = fs.readFileSync(config.LN_NODE_AUTH.TLS_CERT_PATH).toString('base64');
|
2022-04-18 18:22:00 +04:00
|
|
|
const macaroon = fs.readFileSync(config.LN_NODE_AUTH.MACAROON_PATH).toString('base64');
|
|
|
|
|
|
|
|
const { lnd } = lnService.authenticatedLndGrpc({
|
|
|
|
cert: tsl,
|
|
|
|
macaroon: macaroon,
|
|
|
|
socket: 'localhost:10009',
|
|
|
|
});
|
|
|
|
|
|
|
|
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> {
|
2022-04-18 18:22:00 +04:00
|
|
|
return await lnService.getNetworkInfo({ lnd: this.lnd });
|
|
|
|
}
|
|
|
|
|
2022-04-24 01:33:38 +04:00
|
|
|
async $getNetworkGraph(): Promise<ILightningApi.NetworkGraph> {
|
2022-04-18 18:22:00 +04:00
|
|
|
return await lnService.getNetworkGraph({ lnd: this.lnd });
|
|
|
|
}
|
2022-04-24 01:33:38 +04:00
|
|
|
|
|
|
|
async $getChanInfo(id: string): Promise<ILightningApi.Channel> {
|
|
|
|
return await lnService.getChannel({ lnd: this.lnd, id });
|
|
|
|
}
|
2022-04-18 18:22:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default LndApi;
|