Lookup and listpeers fix

clnrest-migration
ShahanaFarooqui 7 months ago
parent ebbb1dbd76
commit 8520322885

@ -12,12 +12,11 @@ export const listPeerChannels = (req, res, next) => {
return res.status(options.statusCode).json({ message: options.message, error: options.error }); return res.status(options.statusCode).json({ message: options.message, error: options.error });
} }
options.url = req.session.selectedNode.ln_server_url + '/v1/listpeerchannels'; options.url = req.session.selectedNode.ln_server_url + '/v1/listpeerchannels';
request.post(options).then((body) => { return request.post(options).then((body) => {
body.channels.forEach((channel) => { body.channels.forEach((channel) => {
const local = channel.to_us_msat || 0; const local = channel.to_us_msat || 0;
const remote = (channel.total_msat - local) || 0; const remote = (channel.total_msat - local) || 0;
const total = channel.total_msat || 0; const total = channel.total_msat || 0;
// return getAliasForChannel(channel).then(channelAlias => {
channel = { channel = {
peer_id: channel.peer_id, peer_id: channel.peer_id,
peer_connected: channel.peer_connected, peer_connected: channel.peer_connected,
@ -40,13 +39,13 @@ export const listPeerChannels = (req, res, next) => {
dust_limit_msat: channel.dust_limit_msat, dust_limit_msat: channel.dust_limit_msat,
htlcs: channel.htlcs, htlcs: channel.htlcs,
features: channel.features, features: channel.features,
alias: new Promise(getAlias(req.session.selectedNode, channel.peer_id)), alias: getAlias(req.session.selectedNode, channel.peer_id).then((callRes) => callRes),
to_them_msat: remote, to_them_msat: remote,
balancedness: (total === 0) ? 1 : (1 - Math.abs((local - remote) / total)).toFixed(3) balancedness: (total === 0) ? 1 : (1 - Math.abs((local - remote) / total)).toFixed(3)
}; };
}); });
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Peer Channels List Received', data: body.channels }); logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Peer Channels List Received', data: body.channels });
res.status(200).json(body.channels); return res.status(200).json(body.channels);
}).catch((errRes) => { }).catch((errRes) => {
const err = common.handleError(errRes, 'Channels', 'List Peer Channels Error', req.session.selectedNode); const err = common.handleError(errRes, 'Channels', 'List Peer Channels Error', req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.message, error: err.error }); return res.status(err.statusCode).json({ message: err.message, error: err.error });

@ -87,11 +87,13 @@ export const getAlias = (selNode, id) => {
return Promise.resolve(''); return Promise.resolve('');
} }
options.body = { id }; options.body = { id };
return request.post(options).then((body) => { return new Promise((resolve, reject) => {
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Network', msg: 'Peer Alias Finished', data: body }); request.post(options).then((body) => {
return body.nodes[0] ? body.nodes[0].alias : id.substring(0, 20); logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Network', msg: 'Peer Alias Finished', data: body });
}).catch((errRes) => { resolve(body.nodes[0] ? body.nodes[0].alias : id.substring(0, 20));
common.handleError(errRes, 'Network', 'Peer Alias Error', selNode); }).catch((errRes) => {
return id.substring(0, 20); common.handleError(errRes, 'Network', 'Peer Alias Error', selNode);
resolve(id.substring(0, 20));
});
}); });
}; };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -12,12 +12,11 @@ export const listPeerChannels = (req, res, next) => {
options = common.getOptions(req); options = common.getOptions(req);
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); } if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
options.url = req.session.selectedNode.ln_server_url + '/v1/listpeerchannels'; options.url = req.session.selectedNode.ln_server_url + '/v1/listpeerchannels';
request.post(options).then((body) => { return request.post(options).then((body) => {
body.channels.forEach((channel) => { body.channels.forEach((channel) => {
const local = channel.to_us_msat || 0; const local = channel.to_us_msat || 0;
const remote = (channel.total_msat - local) || 0; const remote = (channel.total_msat - local) || 0;
const total = channel.total_msat || 0; const total = channel.total_msat || 0;
// return getAliasForChannel(channel).then(channelAlias => {
channel = { channel = {
peer_id: channel.peer_id, peer_id: channel.peer_id,
peer_connected: channel.peer_connected, peer_connected: channel.peer_connected,
@ -40,13 +39,13 @@ export const listPeerChannels = (req, res, next) => {
dust_limit_msat: channel.dust_limit_msat, dust_limit_msat: channel.dust_limit_msat,
htlcs: channel.htlcs, htlcs: channel.htlcs,
features: channel.features, features: channel.features,
alias: new Promise(getAlias(req.session.selectedNode, channel.peer_id)), alias: getAlias(req.session.selectedNode, channel.peer_id).then((callRes: string) => callRes),
to_them_msat: remote, to_them_msat: remote,
balancedness: (total === 0) ? 1 : (1 - Math.abs((local - remote) / total)).toFixed(3) balancedness: (total === 0) ? 1 : (1 - Math.abs((local - remote) / total)).toFixed(3)
}; };
}); });
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Peer Channels List Received', data: body.channels }); logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Peer Channels List Received', data: body.channels });
res.status(200).json(body.channels); return res.status(200).json(body.channels);
}).catch((errRes) => { }).catch((errRes) => {
const err = common.handleError(errRes, 'Channels', 'List Peer Channels Error', req.session.selectedNode); const err = common.handleError(errRes, 'Channels', 'List Peer Channels Error', req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.message, error: err.error }); return res.status(err.statusCode).json({ message: err.message, error: err.error });

@ -86,11 +86,13 @@ export const getAlias = (selNode: CommonSelectedNode, id: string) => {
return Promise.resolve(''); return Promise.resolve('');
} }
options.body = { id }; options.body = { id };
return request.post(options).then((body) => { return new Promise((resolve, reject) => {
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Network', msg: 'Peer Alias Finished', data: body }); request.post(options).then((body) => {
return body.nodes[0] ? body.nodes[0].alias : id.substring(0, 20); logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Network', msg: 'Peer Alias Finished', data: body });
}).catch((errRes) => { resolve(body.nodes[0] ? body.nodes[0].alias : id.substring(0, 20));
common.handleError(errRes, 'Network', 'Peer Alias Error', selNode); }).catch((errRes) => {
return id.substring(0, 20); common.handleError(errRes, 'Network', 'Peer Alias Error', selNode);
resolve(id.substring(0, 20));
});
}); });
}; };

@ -81,7 +81,7 @@ export const getForwardingHistory = createAction(CLNActions.GET_FORWARDING_HISTO
export const setForwardingHistory = createAction(CLNActions.SET_FORWARDING_HISTORY_CLN, props<{ payload: ListForwards }>()); export const setForwardingHistory = createAction(CLNActions.SET_FORWARDING_HISTORY_CLN, props<{ payload: ListForwards }>());
export const fetchInvoices = createAction(CLNActions.FETCH_INVOICES_CLN, props<{ payload: { num_max_invoices?: number, index_offset?: number, reversed?: boolean } }>()); export const fetchInvoices = createAction(CLNActions.FETCH_INVOICES_CLN);
export const setInvoices = createAction(CLNActions.SET_INVOICES_CLN, props<{ payload: ListInvoices }>()); export const setInvoices = createAction(CLNActions.SET_INVOICES_CLN, props<{ payload: ListInvoices }>());

@ -13,7 +13,7 @@ import { SessionService } from '../../shared/services/session.service';
import { WebSocketClientService } from '../../shared/services/web-socket.service'; import { WebSocketClientService } from '../../shared/services/web-socket.service';
import { ErrorMessageComponent } from '../../shared/components/data-modal/error-message/error-message.component'; import { ErrorMessageComponent } from '../../shared/components/data-modal/error-message/error-message.component';
import { CLNInvoiceInformationComponent } from '../transactions/invoices/invoice-information-modal/invoice-information.component'; import { CLNInvoiceInformationComponent } from '../transactions/invoices/invoice-information-modal/invoice-information.component';
import { GetInfo, Payment, FeeRates, ListInvoices, Invoice, Peer, OnChain, QueryRoutes, SaveChannel, GetNewAddress, DetachPeer, UpdateChannel, CloseChannel, SendPayment, GetQueryRoutes, ChannelLookup, FetchInvoices, Channel, OfferInvoice, Offer } from '../../shared/models/clnModels'; import { GetInfo, Payment, FeeRates, ListInvoices, Invoice, Peer, OnChain, QueryRoutes, SaveChannel, GetNewAddress, DetachPeer, UpdateChannel, CloseChannel, SendPayment, GetQueryRoutes, ChannelLookup, Channel, OfferInvoice, Offer } from '../../shared/models/clnModels';
import { API_URL, API_END_POINTS, AlertTypeEnum, APICallStatusEnum, UI_MESSAGES, CLNWSEventTypeEnum, CLNActions, RTLActions, CLNForwardingEventsStatusEnum } from '../../shared/services/consts-enums-functions'; import { API_URL, API_END_POINTS, AlertTypeEnum, APICallStatusEnum, UI_MESSAGES, CLNWSEventTypeEnum, CLNActions, RTLActions, CLNForwardingEventsStatusEnum } from '../../shared/services/consts-enums-functions';
import { closeAllDialogs, closeSpinner, logout, openAlert, openSnackBar, openSpinner, setApiUrl, setNodeData } from '../../store/rtl.actions'; import { closeAllDialogs, closeSpinner, logout, openAlert, openSnackBar, openSpinner, setApiUrl, setNodeData } from '../../store/rtl.actions';
@ -618,10 +618,7 @@ export class CLNEffects implements OnDestroy {
this.logger.info(postRes); this.logger.info(postRes);
this.store.dispatch(closeSpinner({ payload: UI_MESSAGES.DELETE_INVOICE })); this.store.dispatch(closeSpinner({ payload: UI_MESSAGES.DELETE_INVOICE }));
this.store.dispatch(openSnackBar({ payload: 'Invoices Deleted Successfully!' })); this.store.dispatch(openSnackBar({ payload: 'Invoices Deleted Successfully!' }));
return { return { type: CLNActions.FETCH_INVOICES_CLN };
type: CLNActions.FETCH_INVOICES_CLN,
payload: { num_max_invoices: 1000000, reversed: true }
};
}), }),
catchError((err: any) => { catchError((err: any) => {
this.handleErrorWithAlert('DeleteInvoices', UI_MESSAGES.DELETE_INVOICE, 'Delete Invoice Failed', this.CHILD_API_URL + API_END_POINTS.INVOICES_API, err); this.handleErrorWithAlert('DeleteInvoices', UI_MESSAGES.DELETE_INVOICE, 'Delete Invoice Failed', this.CHILD_API_URL + API_END_POINTS.INVOICES_API, err);
@ -705,26 +702,21 @@ export class CLNEffects implements OnDestroy {
invoicesFetchCL = createEffect(() => this.actions.pipe( invoicesFetchCL = createEffect(() => this.actions.pipe(
ofType(CLNActions.FETCH_INVOICES_CLN), ofType(CLNActions.FETCH_INVOICES_CLN),
mergeMap((action: { type: string, payload: FetchInvoices }) => { mergeMap(() => {
this.store.dispatch(updateCLNAPICallStatus({ payload: { action: 'FetchInvoices', status: APICallStatusEnum.INITIATED } })); this.store.dispatch(updateCLNAPICallStatus({ payload: { action: 'FetchInvoices', status: APICallStatusEnum.INITIATED } }));
const num_max_invoices = (action.payload.num_max_invoices) ? action.payload.num_max_invoices : 1000000; return this.httpClient.post<ListInvoices>(this.CHILD_API_URL + API_END_POINTS.INVOICES_API + '/lookup', null);
const index_offset = (action.payload.index_offset) ? action.payload.index_offset : 0; }),
const reversed = (action.payload.reversed) ? action.payload.reversed : true; map((res: ListInvoices) => {
return this.httpClient.post<ListInvoices>(this.CHILD_API_URL + API_END_POINTS.INVOICES_API + '/lookup', { num_max_invoices: num_max_invoices, index_offset: index_offset, reversed: reversed }). this.logger.info(res);
pipe( this.store.dispatch(updateCLNAPICallStatus({ payload: { action: 'FetchInvoices', status: APICallStatusEnum.COMPLETED } }));
map((res: ListInvoices) => { return {
this.logger.info(res); type: CLNActions.SET_INVOICES_CLN,
this.store.dispatch(updateCLNAPICallStatus({ payload: { action: 'FetchInvoices', status: APICallStatusEnum.COMPLETED } })); payload: res
return { };
type: CLNActions.SET_INVOICES_CLN, }),
payload: res catchError((err: any) => {
}; this.handleErrorWithoutAlert('FetchInvoices', UI_MESSAGES.NO_SPINNER, 'Fetching Invoices Failed.', err);
}), return of({ type: RTLActions.VOID });
catchError((err: any) => {
this.handleErrorWithoutAlert('FetchInvoices', UI_MESSAGES.NO_SPINNER, 'Fetching Invoices Failed.', err);
return of({ type: RTLActions.VOID });
})
);
}) })
)); ));
@ -925,7 +917,7 @@ export class CLNEffects implements OnDestroy {
newRoute = '/cln/home'; newRoute = '/cln/home';
} }
this.router.navigate([newRoute]); this.router.navigate([newRoute]);
this.store.dispatch(fetchInvoices({ payload: { num_max_invoices: 1000000, index_offset: 0, reversed: true } })); this.store.dispatch(fetchInvoices());
this.store.dispatch(fetchChannels()); this.store.dispatch(fetchChannels());
this.store.dispatch(fetchUTXOBalances()); this.store.dispatch(fetchUTXOBalances());
this.store.dispatch(fetchFeeRates({ payload: 'perkw' })); this.store.dispatch(fetchFeeRates({ payload: 'perkw' }));

@ -487,12 +487,6 @@ export interface ChannelLookup {
showError: boolean; showError: boolean;
} }
export interface FetchInvoices {
num_max_invoices?: number;
index_offset?: number;
reversed?: boolean;
}
export interface FunderPolicy { export interface FunderPolicy {
summary?: string; summary?: string;
policy?: string; policy?: string;

@ -76,18 +76,22 @@ export class DataService implements OnDestroy {
return this.lnImplementationUpdated.pipe(first(), mergeMap((updatedLnImplementation) => { return this.lnImplementationUpdated.pipe(first(), mergeMap((updatedLnImplementation) => {
let url = ''; let url = '';
let msg = ''; let msg = '';
let body = null;
if (updatedLnImplementation === 'ecl') { if (updatedLnImplementation === 'ecl') {
url = this.APIUrl + '/' + updatedLnImplementation + API_END_POINTS.PAYMENTS_API + '/getsentinfos'; url = this.APIUrl + '/' + updatedLnImplementation + API_END_POINTS.PAYMENTS_API + '/getsentinfos';
body = { payments: payments };
msg = UI_MESSAGES.GET_SENT_PAYMENTS; msg = UI_MESSAGES.GET_SENT_PAYMENTS;
} else if (updatedLnImplementation === 'cln') { } else if (updatedLnImplementation === 'cln') {
url = this.APIUrl + '/' + updatedLnImplementation + API_END_POINTS.UTILITY_API; url = this.APIUrl + '/' + updatedLnImplementation + API_END_POINTS.UTILITY_API + '/decode';
body = { string: payments };
msg = UI_MESSAGES.DECODE_PAYMENTS; msg = UI_MESSAGES.DECODE_PAYMENTS;
} else { } else {
url = this.APIUrl + '/' + updatedLnImplementation + API_END_POINTS.PAYMENTS_API; url = this.APIUrl + '/' + updatedLnImplementation + API_END_POINTS.PAYMENTS_API;
body = { payments: payments };
msg = UI_MESSAGES.DECODE_PAYMENTS; msg = UI_MESSAGES.DECODE_PAYMENTS;
} }
this.store.dispatch(openSpinner({ payload: msg })); this.store.dispatch(openSpinner({ payload: msg }));
return this.httpClient.post(url, { payments: payments }).pipe( return this.httpClient.post(url, body).pipe(
takeUntil(this.unSubs[1]), takeUntil(this.unSubs[1]),
map((res: any) => { map((res: any) => {
this.store.dispatch(closeSpinner({ payload: msg })); this.store.dispatch(closeSpinner({ payload: msg }));

Loading…
Cancel
Save