Browse Source

refactor(lnd): update LndService.closeChannel to be generic

master
jamaljsr 5 years ago
parent
commit
cba287c000
  1. 5
      src/lib/clightning/clightningService.ts
  2. 6
      src/lib/lightning/notImplementedService.ts
  3. 2
      src/lib/lightning/types.ts
  4. 6
      src/lib/lnd/lndService.ts
  5. 16
      src/types/index.ts
  6. 1
      src/utils/tests/renderWithProviders.tsx

5
src/lib/clightning/clightningService.ts

@ -55,6 +55,11 @@ class CLightningService implements LightningService {
throw new Error(`openChannel is not implemented for ${from.implementation} nodes`);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async closeChannel(node: LightningNode, channelPoint: string): Promise<any> {
throw new Error(`closeChannel is not implemented for ${node.implementation} nodes`);
}
/**
* Helper function to continually query the node until a successful
* response is received or it times out

6
src/lib/lightning/notImplementedService.ts

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { LightningNode } from 'shared/types';
import {
LightningNodeAddress,
@ -31,13 +32,14 @@ class NotImplementedService implements LightningService {
}
openChannel(
from: LightningNode,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
to: LightningNode,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
amount: string,
): Promise<LightningNodeChannelPoint> {
throw new Error(`getChannels is not implemented for ${from.implementation} nodes`);
}
closeChannel(node: LightningNode, channelPoint: string): Promise<any> {
throw new Error(`closeChannel is not implemented for ${node.implementation} nodes`);
}
}
export default new NotImplementedService();

2
src/lib/lightning/types.ts

@ -47,7 +47,7 @@ export interface LightningService {
to: LightningNode,
amount: string,
) => Promise<LightningNodeChannelPoint>;
// closeChannel: (node: LightningNode, channelPoint: string) => Promise<any>;
closeChannel: (node: LightningNode, channelPoint: string) => Promise<any>;
// listChannels: (node: LightningNode) => Promise<LND.ListChannelsResponse>;
// pendingChannels: (node: LightningNode) => Promise<LND.PendingChannelsResponse>;
// onNodesDeleted: (nodes: LightningNode[]) => Promise<void>;

6
src/lib/lnd/lndService.ts

@ -95,7 +95,7 @@ class LndService implements LndLibrary {
};
}
async closeChannel(node: LndNode, channelPoint: string): Promise<any> {
async closeChannel(node: LightningNode, channelPoint: string): Promise<any> {
const [txid, txindex] = channelPoint.split(':');
const req: LND.CloseChannelRequest = {
channelPoint: {
@ -104,7 +104,7 @@ class LndService implements LndLibrary {
outputIndex: parseInt(txindex),
},
};
return await proxy.closeChannel(node, req);
return await proxy.closeChannel(this.cast(node), req);
}
async listChannels(node: LndNode): Promise<LND.ListChannelsResponse> {
@ -124,7 +124,7 @@ class LndService implements LndLibrary {
* response is received or it times out
*/
async waitUntilOnline(
node: LndNode,
node: LightningNode,
interval = 3 * 1000, // check every 3 seconds
timeout = 30 * 1000, // timeout after 30 seconds
): Promise<void> {

16
src/types/index.ts

@ -55,17 +55,17 @@ export interface BitcoindLibrary {
}
export interface LndLibrary {
waitUntilOnline: (node: LndNode) => Promise<void>;
getInfo: (node: LndNode) => Promise<LightningNodeInfo>;
getBalances: (node: LndNode) => Promise<LightningNodeBalances>;
getNewAddress: (node: LndNode) => Promise<LightningNodeAddress>;
getChannels: (node: LndNode) => Promise<LightningNodeChannel[]>;
waitUntilOnline: (node: LightningNode) => Promise<void>;
getInfo: (node: LightningNode) => Promise<LightningNodeInfo>;
getBalances: (node: LightningNode) => Promise<LightningNodeBalances>;
getNewAddress: (node: LightningNode) => Promise<LightningNodeAddress>;
getChannels: (node: LightningNode) => Promise<LightningNodeChannel[]>;
openChannel: (
from: LndNode,
to: LndNode,
from: LightningNode,
to: LightningNode,
amount: string,
) => Promise<LightningNodeChannelPoint>;
closeChannel: (node: LndNode, channelPoint: string) => Promise<any>;
closeChannel: (node: LightningNode, channelPoint: string) => Promise<any>;
listChannels: (node: LndNode) => Promise<LND.ListChannelsResponse>;
pendingChannels: (node: LndNode) => Promise<LND.PendingChannelsResponse>;
onNodesDeleted: (nodes: LndNode[]) => Promise<void>;

1
src/utils/tests/renderWithProviders.tsx

@ -14,6 +14,7 @@ export const lightningServiceMock: jest.Mocked<LightningService> = {
getNewAddress: jest.fn(),
getChannels: jest.fn(),
openChannel: jest.fn(),
closeChannel: jest.fn(),
waitUntilOnline: jest.fn(),
};
// injections allow you to mock the dependencies of redux store actions

Loading…
Cancel
Save