mirror of
https://github.com/apotdevin/thunderhub.git
synced 2024-11-19 18:00:05 +01:00
feat: pending chain balance query
This commit is contained in:
parent
256d04a8e9
commit
ecad5380f2
@ -1,12 +1,19 @@
|
||||
import { getChainBalance as getLnChainBalance } from "ln-service";
|
||||
import {
|
||||
getChainBalance as getBalance,
|
||||
getPendingChainBalance as getPending
|
||||
} from "ln-service";
|
||||
import { logger } from "../../../helpers/logger";
|
||||
import { GraphQLInt } from "graphql";
|
||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
||||
import { GraphQLInt } from "graphql";
|
||||
|
||||
interface ChainBalanceProps {
|
||||
chain_balance: number;
|
||||
}
|
||||
|
||||
interface PendingChainBalanceProps {
|
||||
pending_chain_balance: number;
|
||||
}
|
||||
|
||||
export const getChainBalance = {
|
||||
type: GraphQLInt,
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
@ -14,13 +21,31 @@ export const getChainBalance = {
|
||||
const { lnd } = context;
|
||||
|
||||
try {
|
||||
const chainBalance: ChainBalanceProps = await getLnChainBalance({
|
||||
const value: ChainBalanceProps = await getBalance({
|
||||
lnd: lnd
|
||||
});
|
||||
return chainBalance.chain_balance;
|
||||
return value.chain_balance;
|
||||
} catch (error) {
|
||||
logger.error("Error getting chain balance: %o", error);
|
||||
throw new Error("Failed to get chain balance.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getPendingChainBalance = {
|
||||
type: GraphQLInt,
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
await requestLimiter(context.ip, params, "pendingChainBalance", 1, "1s");
|
||||
const { lnd } = context;
|
||||
|
||||
try {
|
||||
const pendingValue: PendingChainBalanceProps = await getPending({
|
||||
lnd: lnd
|
||||
});
|
||||
return pendingValue.pending_chain_balance;
|
||||
} catch (error) {
|
||||
logger.error("Error getting pending chain balance: %o", error);
|
||||
throw new Error("Failed to get pending chain balance.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { getChainBalance } from "./chainBalance";
|
||||
import { getChainBalance, getPendingChainBalance } from "./chainBalance";
|
||||
import { getNetworkInfo } from "./networkInfo";
|
||||
import { getNodeInfo } from "./nodeInfo";
|
||||
|
||||
export const generalQueries = {
|
||||
getChainBalance,
|
||||
getPendingChainBalance,
|
||||
getNetworkInfo,
|
||||
getNodeInfo
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user