mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-21 22:11:37 +01:00
fix: pending channels and balance
This commit is contained in:
parent
f1eb1e78d9
commit
f980e3c256
6 changed files with 55 additions and 29 deletions
|
@ -18,7 +18,7 @@ Object {
|
|||
exports[`Chain Resolvers getPendingChainBalance 1`] = `
|
||||
Object {
|
||||
"data": Object {
|
||||
"getPendingChainBalance": "1000000",
|
||||
"getPendingChainBalance": "1003000",
|
||||
},
|
||||
"errors": undefined,
|
||||
"extensions": undefined,
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
getUtxos,
|
||||
sendToChainAddress,
|
||||
createChainAddress,
|
||||
getPendingChannels,
|
||||
} from 'ln-service';
|
||||
import { ContextType } from 'server/types/apiTypes';
|
||||
import { logger } from 'server/helpers/logger';
|
||||
|
@ -18,6 +19,7 @@ import {
|
|||
GetChainTransactionsType,
|
||||
GetUtxosType,
|
||||
SendToChainAddressType,
|
||||
GetPendingChannelsType,
|
||||
} from 'server/types/ln-service.types';
|
||||
|
||||
interface ChainBalanceProps {
|
||||
|
@ -60,8 +62,19 @@ export const chainResolvers = {
|
|||
lnd,
|
||||
})
|
||||
);
|
||||
return pendingValue.pending_chain_balance || 0;
|
||||
|
||||
const { pending_channels } = await to<GetPendingChannelsType>(
|
||||
getPendingChannels({ lnd })
|
||||
);
|
||||
|
||||
const closing =
|
||||
pending_channels
|
||||
.filter(p => p.is_closing)
|
||||
.reduce((p, c) => p + c.local_balance, 0) || 0;
|
||||
|
||||
return pendingValue.pending_chain_balance + closing || 0;
|
||||
},
|
||||
|
||||
getChainTransactions: async (
|
||||
_: undefined,
|
||||
__: undefined,
|
||||
|
|
|
@ -2,27 +2,7 @@ import { getPendingChannels as getLnPendingChannels } from 'ln-service';
|
|||
import { ContextType } from 'server/types/apiTypes';
|
||||
import { to } from 'server/helpers/async';
|
||||
import { requestLimiter } from 'server/helpers/rateLimiter';
|
||||
|
||||
interface PendingChannelListProps {
|
||||
pending_channels: PendingChannelProps[];
|
||||
}
|
||||
|
||||
interface PendingChannelProps {
|
||||
close_transaction_id: string;
|
||||
is_active: boolean;
|
||||
is_closing: boolean;
|
||||
is_opening: boolean;
|
||||
local_balance: number;
|
||||
local_reserve: number;
|
||||
partner_public_key: string;
|
||||
received: number;
|
||||
remote_balance: number;
|
||||
remote_reserve: number;
|
||||
sent: number;
|
||||
transaction_fee: number;
|
||||
transaction_id: string;
|
||||
transaction_vout: number;
|
||||
}
|
||||
import { GetPendingChannelsType } from 'server/types/ln-service.types';
|
||||
|
||||
export const getPendingChannels = async (
|
||||
_: undefined,
|
||||
|
@ -33,7 +13,7 @@ export const getPendingChannels = async (
|
|||
|
||||
const { lnd } = context;
|
||||
|
||||
const { pending_channels }: PendingChannelListProps = await to(
|
||||
const { pending_channels } = await to<GetPendingChannelsType>(
|
||||
getLnPendingChannels({ lnd })
|
||||
);
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { getNode, getWalletInfo, getClosedChannels } from 'ln-service';
|
||||
import {
|
||||
getNode,
|
||||
getWalletInfo,
|
||||
getClosedChannels,
|
||||
getPendingChannels,
|
||||
} from 'ln-service';
|
||||
import { to, toWithError } from 'server/helpers/async';
|
||||
import { requestLimiter } from 'server/helpers/rateLimiter';
|
||||
import {
|
||||
|
@ -6,6 +11,7 @@ import {
|
|||
LndObject,
|
||||
GetWalletInfoType,
|
||||
GetNodeType,
|
||||
GetPendingChannelsType,
|
||||
} from 'server/types/ln-service.types';
|
||||
import { ContextType } from '../../types/apiTypes';
|
||||
import { logger } from '../../helpers/logger';
|
||||
|
@ -45,12 +51,20 @@ export const nodeResolvers = {
|
|||
})
|
||||
);
|
||||
|
||||
const { pending_channels } = await to<GetPendingChannelsType>(
|
||||
getPendingChannels({ lnd })
|
||||
);
|
||||
|
||||
const pending_channels_count = pending_channels.length;
|
||||
|
||||
return {
|
||||
...info,
|
||||
pending_channels_count,
|
||||
closed_channels_count: closedChannels?.channels?.length || 0,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
Node: {
|
||||
node: async (parent: NodeParent) => {
|
||||
const { lnd, withChannels, publicKey } = parent;
|
||||
|
|
|
@ -151,3 +151,22 @@ export type SendToChainAddressType = {
|
|||
is_outgoing: boolean;
|
||||
tokens: number | null;
|
||||
};
|
||||
|
||||
export type PendingChannelType = {
|
||||
close_transaction_id: string;
|
||||
is_active: boolean;
|
||||
is_closing: boolean;
|
||||
is_opening: boolean;
|
||||
local_balance: number;
|
||||
local_reserve: number;
|
||||
partner_public_key: string;
|
||||
received: number;
|
||||
remote_balance: number;
|
||||
remote_reserve: number;
|
||||
sent: number;
|
||||
transaction_fee: number;
|
||||
transaction_id: string;
|
||||
transaction_vout: number;
|
||||
};
|
||||
|
||||
export type GetPendingChannelsType = { pending_channels: PendingChannelType[] };
|
||||
|
|
|
@ -98,7 +98,7 @@ Object {
|
|||
"color": "color",
|
||||
"is_synced_to_chain": true,
|
||||
"peers_count": 1,
|
||||
"pending_channels_count": 2,
|
||||
"pending_channels_count": 3,
|
||||
"version": "version",
|
||||
},
|
||||
},
|
||||
|
@ -160,7 +160,7 @@ Object {
|
|||
"getNodeInfo": Object {
|
||||
"active_channels_count": 1,
|
||||
"closed_channels_count": 3,
|
||||
"pending_channels_count": 2,
|
||||
"pending_channels_count": 3,
|
||||
},
|
||||
},
|
||||
"errors": undefined,
|
||||
|
@ -768,11 +768,11 @@ Object {
|
|||
"color": "color",
|
||||
"is_synced_to_chain": true,
|
||||
"peers_count": 1,
|
||||
"pending_channels_count": 2,
|
||||
"pending_channels_count": 3,
|
||||
"public_key": "key",
|
||||
"version": "version",
|
||||
},
|
||||
"getPendingChainBalance": "1000000",
|
||||
"getPendingChainBalance": "1003000",
|
||||
},
|
||||
"errors": undefined,
|
||||
"extensions": undefined,
|
||||
|
|
Loading…
Add table
Reference in a new issue