thunderhub/server/helpers/getNodeFromChannel.ts
Anthony Potdevin bc4415cde7
chore: 🔧 enable strict tsconfig (#96)
* chore: 🔧 strict enable wip

* Improve typings, add type dependencies (#97)

We improve the TypeScript situation by enabling `noImplicitAny`. This
leads to a bunch of errors, as expected. We fix some of these by
installing the correct types, and some are fixed manually by an educated
guess. There are still a lot left, and these seem to be a big mix of
lacking types for the `ln-service` dependency and potential bugs.

* Strict null (#100)

* chore: 🔧 enable strict-null

* chore: 🔧 more checks

* chore: 🔧 some fixes

* chore: 🔧 more types

* chore: 🔧 more types

* chore: 🔧 more types

* chore: 🔧 more types

* chore: 🔧 more types

* chore: 🔧 more types

* chore: 🔧 more types

* chore: 🔧 enable strict

* fix: 🐛 input

* fix: 🐛 forward report

* fix: 🐛 chat sending

* fix: 🐛 chat bubble input

Co-authored-by: Torkel Rogstad <torkel@rogstad.io>
2020-08-05 08:35:26 +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
) => {
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,
};
};