diff --git a/src/lib/clightning/clightningService.ts b/src/lib/clightning/clightningService.ts index e909f14..8d898c8 100644 --- a/src/lib/clightning/clightningService.ts +++ b/src/lib/clightning/clightningService.ts @@ -1,5 +1,6 @@ import { CLightningNode, LightningNode } from 'shared/types'; import { + LightningNodeAddress, LightningNodeBalances, LightningNodeInfo, LightningService, @@ -32,6 +33,11 @@ class CLightningService implements LightningService { }; } + async getNewAddress(node: LightningNode): Promise { + const address = await this.request(node, 'getNewAddress'); + return { address }; + } + /** * Helper function to continually query the node until a successful * response is received or it times out diff --git a/src/lib/lightning/notImplementedService.ts b/src/lib/lightning/notImplementedService.ts index 4eb0a3b..b1cf2dc 100644 --- a/src/lib/lightning/notImplementedService.ts +++ b/src/lib/lightning/notImplementedService.ts @@ -1,5 +1,10 @@ import { LightningNode } from 'shared/types'; -import { LightningNodeBalances, LightningNodeInfo, LightningService } from './types'; +import { + LightningNodeAddress, + LightningNodeBalances, + LightningNodeInfo, + LightningService, +} from './types'; class NotImplementedService implements LightningService { getInfo(node: LightningNode): Promise { @@ -13,6 +18,9 @@ class NotImplementedService implements LightningService { `waitUntilOnline is not implemented for ${node.implementation} nodes`, ); } + getNewAddress(node: LightningNode): Promise { + throw new Error(`getNewAddress is not implemented for ${node.implementation} nodes`); + } } export default new NotImplementedService(); diff --git a/src/lib/lightning/types.ts b/src/lib/lightning/types.ts index b6df37b..b67bf88 100644 --- a/src/lib/lightning/types.ts +++ b/src/lib/lightning/types.ts @@ -16,11 +16,26 @@ export interface LightningNodeBalances { unconfirmed: string; } +export interface LightningNodeAddress { + address: string; +} + +export interface LightningNodeChannel { + pending: boolean; + uniqueId: string; + channelPoint: string; + pubkey: string; + capacity: string; + localBalance: string; + remoteBalance: string; + status: string; +} + export interface LightningService { waitUntilOnline: (node: LightningNode) => Promise; getInfo: (node: LightningNode) => Promise; getBalances: (node: LightningNode) => Promise; - // getNewAddress: (node: LightningNode) => Promise; + getNewAddress: (node: LightningNode) => Promise; // openChannel: (from: LightningNode, to: LightningNode, amount: string) => Promise; // closeChannel: (node: LightningNode, channelPoint: string) => Promise; // listChannels: (node: LightningNode) => Promise; diff --git a/src/lib/lnd/lndService.ts b/src/lib/lnd/lndService.ts index 608a736..5048fa6 100644 --- a/src/lib/lnd/lndService.ts +++ b/src/lib/lnd/lndService.ts @@ -1,6 +1,10 @@ import * as LND from '@radar/lnrpc'; import { LndNode } from 'shared/types'; -import { LightningNodeBalances, LightningNodeInfo } from 'lib/lightning/types'; +import { + LightningNodeAddress, + LightningNodeBalances, + LightningNodeInfo, +} from 'lib/lightning/types'; import { LndLibrary } from 'types'; import { waitFor } from 'utils/async'; import { getContainerName } from 'utils/network'; @@ -29,7 +33,7 @@ class LndService implements LndLibrary { }; } - async getNewAddress(node: LndNode): Promise { + async getNewAddress(node: LndNode): Promise { return await proxy.getNewAddress(node); } diff --git a/src/types/index.ts b/src/types/index.ts index 0c4965b..b15c339 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -4,6 +4,7 @@ import { ChainInfo, WalletInfo } from 'bitcoin-core'; import { BitcoinNode, CommonNode, LightningNode, LndNode, Status } from 'shared/types'; import { IpcSender } from 'lib/ipc/ipcService'; import { + LightningNodeAddress, LightningNodeBalances, LightningNodeInfo, LightningService, @@ -55,7 +56,7 @@ export interface LndLibrary { waitUntilOnline: (node: LndNode) => Promise; getInfo: (node: LndNode) => Promise; getBalances: (node: LndNode) => Promise; - getNewAddress: (node: LndNode) => Promise; + getNewAddress: (node: LndNode) => Promise; openChannel: (from: LndNode, to: LndNode, amount: string) => Promise; closeChannel: (node: LndNode, channelPoint: string) => Promise; listChannels: (node: LndNode) => Promise; diff --git a/src/utils/chart.spec.ts b/src/utils/chart.spec.ts index 6dbda9c..0fc9668 100644 --- a/src/utils/chart.spec.ts +++ b/src/utils/chart.spec.ts @@ -2,9 +2,8 @@ import { IChart, IConfig } from '@mrblenny/react-flow-chart'; import { defaultChannel, defaultPendingChannel, defaultPendingOpenChannel } from 'shared'; import { LndNodeMapping } from 'store/models/lnd'; import { Network } from 'types'; -import { defaultStateInfo } from 'utils/tests'; +import { defaultStateInfo, getNetwork } from 'utils/tests'; import { initChartFromNetwork, snap, updateChartFromLnd } from './chart'; -import { getNetwork } from './tests'; describe('Chart Util', () => { let network: Network; diff --git a/src/utils/chart.ts b/src/utils/chart.ts index 21c391f..98ded1f 100644 --- a/src/utils/chart.ts +++ b/src/utils/chart.ts @@ -1,6 +1,7 @@ import { IChart, IConfig, ILink, INode, IPosition } from '@mrblenny/react-flow-chart'; import { Channel, PendingChannel } from '@radar/lnrpc'; import { BitcoinNode, LightningNode } from 'shared/types'; +import { LightningNodeChannel } from 'lib/lightning/types'; import { LndNodeMapping } from 'store/models/lnd'; import { Network } from 'types'; import btclogo from 'resources/bitcoin.svg'; @@ -115,18 +116,7 @@ const updateNodeSize = (node: INode) => { }; }; -interface ChannelInfo { - pending: boolean; - uniqueId: string; - channelPoint: string; - pubkey: string; - capacity: string; - localBalance: string; - remoteBalance: string; - status: string; -} - -const mapOpenChannel = (chan: Channel): ChannelInfo => ({ +const mapOpenChannel = (chan: Channel): LightningNodeChannel => ({ pending: false, uniqueId: chan.channelPoint.slice(-12), channelPoint: chan.channelPoint, @@ -137,7 +127,9 @@ const mapOpenChannel = (chan: Channel): ChannelInfo => ({ status: 'Open', }); -const mapPendingChannel = (status: string) => (chan: PendingChannel): ChannelInfo => ({ +const mapPendingChannel = (status: string) => ( + chan: PendingChannel, +): LightningNodeChannel => ({ pending: true, uniqueId: chan.channelPoint.slice(-12), channelPoint: chan.channelPoint, @@ -149,15 +141,15 @@ const mapPendingChannel = (status: string) => (chan: PendingChannel): ChannelInf }); const updateLinksAndPorts = ( - info: ChannelInfo, + chan: LightningNodeChannel, pubkeys: Record, nodes: { [x: string]: INode }, fromNode: INode, links: { [x: string]: ILink }, ) => { // use the channel point as a unique id since pending channels do not have a channel id yet - const chanId = info.uniqueId; - const toName = pubkeys[info.pubkey]; + const chanId = chan.uniqueId; + const toName = pubkeys[chan.pubkey]; const toNode = nodes[toName]; const fromOnLeftSide = fromNode.position.x < toNode.position.x; @@ -184,13 +176,13 @@ const updateLinksAndPorts = ( from: { nodeId: fromNode.id, portId: chanId }, to: { nodeId: toName, portId: chanId }, properties: { - type: info.pending ? 'pending-channel' : 'open-channel', - channelPoint: info.channelPoint, - capacity: info.capacity, - fromBalance: info.localBalance, - toBalance: info.remoteBalance, + type: chan.pending ? 'pending-channel' : 'open-channel', + channelPoint: chan.channelPoint, + capacity: chan.capacity, + fromBalance: chan.localBalance, + toBalance: chan.remoteBalance, direction: fromOnLeftSide ? 'ltr' : 'rtl', - status: info.status, + status: chan.status, }, }; };