mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-22 06:21:37 +01:00
* refactor: ♻️ change schema * chore: 🔧 small changes * chore: 🔧 cleanup * chore: 🔧 cleanup types * chore: 🔧 change to absolute imports Co-authored-by: apotdevin <apotdevincab@gmail.com>
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { getNode, getChannel } from 'ln-service';
|
|
import { logger } from 'server/helpers/logger';
|
|
import { toWithError } from 'server/helpers/async';
|
|
|
|
const errorNode = {
|
|
alias: 'Partner node not found',
|
|
color: '#000000',
|
|
};
|
|
|
|
export const getNodeFromChannel = async (
|
|
id: string,
|
|
publicKey: string,
|
|
lnd
|
|
) => {
|
|
const [channelInfo, channelError] = await toWithError(
|
|
getChannel({
|
|
lnd,
|
|
id,
|
|
})
|
|
);
|
|
|
|
if (channelError) {
|
|
logger.verbose(`Error getting channel with id ${id}: %o`, channelError);
|
|
return errorNode;
|
|
}
|
|
|
|
const partnerPublicKey =
|
|
channelInfo.policies[0].public_key !== publicKey
|
|
? channelInfo.policies[0].public_key
|
|
: channelInfo.policies[1].public_key;
|
|
|
|
const [nodeInfo, nodeError] = await toWithError(
|
|
getNode({
|
|
lnd,
|
|
is_omitting_channels: true,
|
|
public_key: partnerPublicKey,
|
|
})
|
|
);
|
|
|
|
if (nodeError) {
|
|
logger.verbose(
|
|
`Error getting node with public key ${partnerPublicKey}: %o`,
|
|
nodeError
|
|
);
|
|
return errorNode;
|
|
}
|
|
|
|
return {
|
|
alias: nodeInfo.alias,
|
|
color: nodeInfo.color,
|
|
};
|
|
};
|