thunderhub/server/helpers/getNodeFromChannel.ts
Anthony Potdevin f80492b80a
refactor: ♻️ server structure (#52)
* refactor: ♻️ change schema

* chore: 🔧 small changes

* chore: 🔧 cleanup

* chore: 🔧 cleanup types

* chore: 🔧 change to absolute imports

Co-authored-by: apotdevin <apotdevincab@gmail.com>
2020-06-01 08:36:33 +02:00

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,
};
};