thunderhub/server/helpers/getNodeFromChannel.ts
Anthony Potdevin 581185e6b0
chore: 🔧 remove client (#111)
* chore: 🔧 remove client

* chore: 🔧 change cookie name

* chore: 🔧 remove auth param

* chore: 🔧 remove auth components

* chore: 🔧 add getaccount query

* fix: 🐛 tests

* chore: 🔧 get account

* chore: 🔧 status check

* chore: 🔧 remove log

* chore: 🔧 update apollo client

* refactor: ♻️ server side props

* chore: 🔧 ssr queries

* chore: 🔧 more ssr queries

* chore: 🔧 type check

* chore: 🔧 increase nodeinfo limit

Co-authored-by: apotdevin <apotdevincab@gmail.com>
2020-08-05 08:37:02 +02:00

57 lines
1.3 KiB
TypeScript

import { getNode, getChannel } from 'ln-service';
import { logger } from 'server/helpers/logger';
import { toWithError } from 'server/helpers/async';
import {
LndObject,
GetChannelType,
GetNodeType,
} from 'server/types/ln-service.types';
const errorNode = {
alias: 'Partner node not found',
color: '#000000',
};
export const getNodeFromChannel = async (
id: string,
publicKey: string,
lnd: LndObject | null
) => {
const [channelInfo, channelError] = await toWithError(
getChannel({
lnd,
id,
})
);
if (channelError || !channelInfo) {
logger.verbose(`Error getting channel with id ${id}: %o`, channelError);
return errorNode;
}
const partnerPublicKey =
(channelInfo as GetChannelType).policies[0].public_key !== publicKey
? (channelInfo as GetChannelType).policies[0].public_key
: (channelInfo as GetChannelType).policies[1].public_key;
const [nodeInfo, nodeError] = await toWithError(
getNode({
lnd,
is_omitting_channels: true,
public_key: partnerPublicKey,
})
);
if (nodeError || !nodeInfo) {
logger.verbose(
`Error getting node with public key ${partnerPublicKey}: %o`,
nodeError
);
return errorNode;
}
return {
alias: (nodeInfo as GetNodeType).alias,
color: (nodeInfo as GetNodeType).color,
};
};