mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-22 14:22:33 +01:00
chore: change error handling
This commit is contained in:
parent
81da8f2950
commit
adb2b1d37b
18 changed files with 951 additions and 917 deletions
|
@ -57,3 +57,10 @@ export const getAuthLnd = (auth: string) => {
|
||||||
|
|
||||||
return lnd;
|
return lnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getErrorMsg = (error: any): string => {
|
||||||
|
const code = error[0];
|
||||||
|
const msg = error[1];
|
||||||
|
|
||||||
|
return JSON.stringify({ code, msg });
|
||||||
|
};
|
||||||
|
|
|
@ -1,53 +1,54 @@
|
||||||
import { closeChannel as lnCloseChannel } from "ln-service";
|
import { closeChannel as lnCloseChannel } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import {
|
import {
|
||||||
GraphQLBoolean,
|
GraphQLBoolean,
|
||||||
GraphQLString,
|
GraphQLString,
|
||||||
GraphQLInt,
|
GraphQLInt,
|
||||||
GraphQLNonNull
|
GraphQLNonNull,
|
||||||
} from "graphql";
|
} from 'graphql';
|
||||||
import { CloseChannelType } from "../../../schemaTypes/mutation.ts/channels/closeChannel";
|
import { CloseChannelType } from '../../../schemaTypes/mutation.ts/channels/closeChannel';
|
||||||
|
import { getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface CloseChannelProps {
|
interface CloseChannelProps {
|
||||||
transaction_id: string;
|
transaction_id: string;
|
||||||
transaction_vout: string;
|
transaction_vout: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const closeChannel = {
|
export const closeChannel = {
|
||||||
type: CloseChannelType,
|
type: CloseChannelType,
|
||||||
args: {
|
args: {
|
||||||
id: {
|
id: {
|
||||||
type: new GraphQLNonNull(GraphQLString)
|
type: new GraphQLNonNull(GraphQLString),
|
||||||
|
},
|
||||||
|
forceClose: {
|
||||||
|
type: GraphQLBoolean,
|
||||||
|
},
|
||||||
|
targetConfirmations: {
|
||||||
|
type: GraphQLInt,
|
||||||
|
},
|
||||||
|
tokensPerVByte: {
|
||||||
|
type: GraphQLInt,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
forceClose: {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
type: GraphQLBoolean
|
await requestLimiter(context.ip, params, 'closeChannel', 1, '1s');
|
||||||
},
|
const { lnd } = context;
|
||||||
targetConfirmations: {
|
|
||||||
type: GraphQLInt
|
|
||||||
},
|
|
||||||
tokensPerVByte: {
|
|
||||||
type: GraphQLInt
|
|
||||||
}
|
|
||||||
},
|
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
|
||||||
await requestLimiter(context.ip, params, "closeChannel", 1, "1s");
|
|
||||||
const { lnd } = context;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const info: CloseChannelProps = await lnCloseChannel({
|
const info: CloseChannelProps = await lnCloseChannel({
|
||||||
lnd: lnd,
|
lnd: lnd,
|
||||||
id: params.id,
|
id: params.id,
|
||||||
target_confirmations: params.targetConfirmations,
|
target_confirmations: params.targetConfirmations,
|
||||||
tokens_per_vbyte: params.tokensPerVByte
|
tokens_per_vbyte: params.tokensPerVByte,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
transactionId: info.transaction_id,
|
transactionId: info.transaction_id,
|
||||||
transactionOutputIndex: info.transaction_vout
|
transactionOutputIndex: info.transaction_vout,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error closing channel: %o", error);
|
logger.error('Error closing channel: %o', error);
|
||||||
throw new Error("Failed to close channel.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,48 +1,51 @@
|
||||||
import { openChannel as lnOpenChannel } from "ln-service";
|
import { openChannel as lnOpenChannel } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GraphQLBoolean, GraphQLString, GraphQLInt } from "graphql";
|
import {
|
||||||
import { OpenChannelType } from "../../../schemaTypes/mutation.ts/channels/openChannel";
|
GraphQLBoolean,
|
||||||
|
GraphQLString,
|
||||||
|
GraphQLInt,
|
||||||
|
GraphQLNonNull,
|
||||||
|
} from 'graphql';
|
||||||
|
import { OpenChannelType } from '../../../schemaTypes/mutation.ts/channels/openChannel';
|
||||||
|
import { getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface OpenChannelProps {
|
interface OpenChannelProps {
|
||||||
transaction_id: string;
|
transaction_id: string;
|
||||||
transaction_vout: string;
|
transaction_vout: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const openChannel = {
|
export const openChannel = {
|
||||||
type: OpenChannelType,
|
type: OpenChannelType,
|
||||||
args: {
|
args: {
|
||||||
isPrivate: {
|
isPrivate: {
|
||||||
type: GraphQLBoolean
|
type: GraphQLBoolean,
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
type: new GraphQLNonNull(GraphQLInt),
|
||||||
|
},
|
||||||
|
partnerPublicKey: {
|
||||||
|
type: new GraphQLNonNull(GraphQLString),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
amount: {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
type: GraphQLInt
|
await requestLimiter(context.ip, params, 'openChannel', 1, '1s');
|
||||||
|
const { lnd } = context;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const info: OpenChannelProps = await lnOpenChannel({
|
||||||
|
lnd: lnd,
|
||||||
|
is_private: params.isPrivate,
|
||||||
|
local_tokens: params.amount,
|
||||||
|
partner_public_key: params.partnerPublicKey,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
transactionId: info.transaction_id,
|
||||||
|
transactionOutputIndex: info.transaction_vout,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Error opening channel: %o', error);
|
||||||
|
throw new Error(getErrorMsg(error));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
partnerPublicKey: {
|
|
||||||
type: GraphQLString
|
|
||||||
}
|
|
||||||
},
|
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
|
||||||
await requestLimiter(context.ip, params, "openChannel", 1, "1s");
|
|
||||||
const { lnd } = context;
|
|
||||||
|
|
||||||
if (!params.amount || !params.partnerPublicKey)
|
|
||||||
throw new Error("Amount and partner public key are required");
|
|
||||||
|
|
||||||
try {
|
|
||||||
const info: OpenChannelProps = await lnOpenChannel({
|
|
||||||
lnd: lnd,
|
|
||||||
is_private: params.isPrivate,
|
|
||||||
local_tokens: params.amount,
|
|
||||||
partner_public_key: params.partnerPublicKey
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
transactionId: info.transaction_id,
|
|
||||||
transactionOutputIndex: info.transaction_vout
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
logger.error("Error opening channel: %o", error);
|
|
||||||
throw new Error("Failed to open channel.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,49 +1,50 @@
|
||||||
import { createInvoice as createInvoiceRequest } from "ln-service";
|
import { createInvoice as createInvoiceRequest } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GraphQLNonNull, GraphQLInt } from "graphql";
|
import { GraphQLNonNull, GraphQLInt } from 'graphql';
|
||||||
import { InvoiceType } from "../../../schemaTypes/mutation.ts/invoice/createInvoice";
|
import { InvoiceType } from '../../../schemaTypes/mutation.ts/invoice/createInvoice';
|
||||||
|
import { getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface InvoiceProps {
|
interface InvoiceProps {
|
||||||
chain_address: string;
|
chain_address: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
description: string;
|
description: string;
|
||||||
id: string;
|
id: string;
|
||||||
request: string;
|
request: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
tokens: number;
|
tokens: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Allow more params
|
// TODO: Allow more params
|
||||||
export const createInvoice = {
|
export const createInvoice = {
|
||||||
type: InvoiceType,
|
type: InvoiceType,
|
||||||
args: {
|
args: {
|
||||||
amount: {
|
amount: {
|
||||||
type: new GraphQLNonNull(GraphQLInt)
|
type: new GraphQLNonNull(GraphQLInt),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "createInvoice", 1, "1s");
|
await requestLimiter(context.ip, params, 'createInvoice', 1, '1s');
|
||||||
const { lnd } = context;
|
const { lnd } = context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const invoice: InvoiceProps = await createInvoiceRequest({
|
const invoice: InvoiceProps = await createInvoiceRequest({
|
||||||
lnd: lnd,
|
lnd: lnd,
|
||||||
tokens: params.amount
|
tokens: params.amount,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chainAddress: invoice.chain_address,
|
chainAddress: invoice.chain_address,
|
||||||
createdAt: invoice.created_at,
|
createdAt: invoice.created_at,
|
||||||
description: invoice.description,
|
description: invoice.description,
|
||||||
id: invoice.id,
|
id: invoice.id,
|
||||||
request: invoice.request,
|
request: invoice.request,
|
||||||
secret: invoice.secret,
|
secret: invoice.secret,
|
||||||
tokens: invoice.tokens
|
tokens: invoice.tokens,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error creating invoice: %o", error);
|
logger.error('Error creating invoice: %o', error);
|
||||||
throw new Error("Failed to create invoice.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,78 +1,79 @@
|
||||||
import { parsePaymentRequest } from "ln-service";
|
import { parsePaymentRequest } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GraphQLString, GraphQLNonNull } from "graphql";
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
import { ParsePaymentType } from "../../../schemaTypes/mutation.ts/invoice/parsePayment";
|
import { ParsePaymentType } from '../../../schemaTypes/mutation.ts/invoice/parsePayment';
|
||||||
|
import { getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface RouteProps {
|
interface RouteProps {
|
||||||
base_fee_mtokens: string;
|
base_fee_mtokens: string;
|
||||||
channel: string;
|
channel: string;
|
||||||
cltv_delta: number;
|
cltv_delta: number;
|
||||||
fee_rate: number;
|
fee_rate: number;
|
||||||
public_key: string;
|
public_key: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RequestProps {
|
interface RequestProps {
|
||||||
chain_addresses: string[];
|
chain_addresses: string[];
|
||||||
cltv_delta: number;
|
cltv_delta: number;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
description: string;
|
description: string;
|
||||||
description_hash: string;
|
description_hash: string;
|
||||||
destination: string;
|
destination: string;
|
||||||
expires_at: string;
|
expires_at: string;
|
||||||
id: string;
|
id: string;
|
||||||
is_expired: string;
|
is_expired: string;
|
||||||
mtokens: string;
|
mtokens: string;
|
||||||
network: string;
|
network: string;
|
||||||
routes: RouteProps[];
|
routes: RouteProps[];
|
||||||
tokens: number;
|
tokens: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parsePayment = {
|
export const parsePayment = {
|
||||||
type: ParsePaymentType,
|
type: ParsePaymentType,
|
||||||
args: {
|
args: {
|
||||||
request: {
|
request: {
|
||||||
type: new GraphQLNonNull(GraphQLString)
|
type: new GraphQLNonNull(GraphQLString),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "parsePayment", 1, "1s");
|
await requestLimiter(context.ip, params, 'parsePayment', 1, '1s');
|
||||||
const { lnd } = context;
|
const { lnd } = context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const request: RequestProps = await parsePaymentRequest({
|
const request: RequestProps = await parsePaymentRequest({
|
||||||
lnd: lnd,
|
lnd: lnd,
|
||||||
request: params.request
|
request: params.request,
|
||||||
});
|
});
|
||||||
|
|
||||||
const routes = request.routes.map(route => {
|
const routes = request.routes.map(route => {
|
||||||
return {
|
return {
|
||||||
mTokenFee: route.base_fee_mtokens,
|
mTokenFee: route.base_fee_mtokens,
|
||||||
channel: route.channel,
|
channel: route.channel,
|
||||||
cltvDelta: route.cltv_delta,
|
cltvDelta: route.cltv_delta,
|
||||||
feeRate: route.fee_rate,
|
feeRate: route.fee_rate,
|
||||||
publicKey: route.public_key
|
publicKey: route.public_key,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chainAddresses: request.chain_addresses,
|
chainAddresses: request.chain_addresses,
|
||||||
cltvDelta: request.cltv_delta,
|
cltvDelta: request.cltv_delta,
|
||||||
createdAt: request.created_at,
|
createdAt: request.created_at,
|
||||||
description: request.description,
|
description: request.description,
|
||||||
descriptionHash: request.description_hash,
|
descriptionHash: request.description_hash,
|
||||||
destination: request.destination,
|
destination: request.destination,
|
||||||
expiresAt: request.expires_at,
|
expiresAt: request.expires_at,
|
||||||
id: request.id,
|
id: request.id,
|
||||||
isExpired: request.is_expired,
|
isExpired: request.is_expired,
|
||||||
mTokens: request.mtokens,
|
mTokens: request.mtokens,
|
||||||
network: request.network,
|
network: request.network,
|
||||||
routes: routes,
|
routes: routes,
|
||||||
tokens: request.tokens
|
tokens: request.tokens,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error decoding request: %o", error);
|
logger.error('Error decoding request: %o', error);
|
||||||
throw new Error("Failed to decode request.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,71 +1,72 @@
|
||||||
import { pay as payRequest } from "ln-service";
|
import { pay as payRequest } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GraphQLString, GraphQLNonNull } from "graphql";
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
import { PayType } from "../../../schemaTypes/mutation.ts/invoice/pay";
|
import { PayType } from '../../../schemaTypes/mutation.ts/invoice/pay';
|
||||||
|
import { getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface HopProps {
|
interface HopProps {
|
||||||
channel: string;
|
channel: string;
|
||||||
channel_capacity: number;
|
channel_capacity: number;
|
||||||
fee_mtokens: string;
|
fee_mtokens: string;
|
||||||
forward_mtokens: string;
|
forward_mtokens: string;
|
||||||
timeout: number;
|
timeout: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RequestProps {
|
interface RequestProps {
|
||||||
fee: number;
|
fee: number;
|
||||||
fee_mtokens: string;
|
fee_mtokens: string;
|
||||||
hops: HopProps[];
|
hops: HopProps[];
|
||||||
id: string;
|
id: string;
|
||||||
is_confirmed: boolean;
|
is_confirmed: boolean;
|
||||||
is_outgoing: boolean;
|
is_outgoing: boolean;
|
||||||
mtokens: string;
|
mtokens: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
tokens: number;
|
tokens: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Allow path payments as well
|
// TODO: Allow path payments as well
|
||||||
export const pay = {
|
export const pay = {
|
||||||
type: PayType,
|
type: PayType,
|
||||||
args: {
|
args: {
|
||||||
request: {
|
request: {
|
||||||
type: new GraphQLNonNull(GraphQLString)
|
type: new GraphQLNonNull(GraphQLString),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "payRequest", 1, "1s");
|
await requestLimiter(context.ip, params, 'payRequest', 1, '1s');
|
||||||
const { lnd } = context;
|
const { lnd } = context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const payment: RequestProps = await payRequest({
|
const payment: RequestProps = await payRequest({
|
||||||
lnd: lnd,
|
lnd: lnd,
|
||||||
request: params.request
|
request: params.request,
|
||||||
});
|
});
|
||||||
|
|
||||||
const hops = payment.hops.map(hop => {
|
const hops = payment.hops.map(hop => {
|
||||||
return {
|
return {
|
||||||
channel: hop.channel,
|
channel: hop.channel,
|
||||||
channelCapacity: hop.channel_capacity,
|
channelCapacity: hop.channel_capacity,
|
||||||
mTokenFee: hop.fee_mtokens,
|
mTokenFee: hop.fee_mtokens,
|
||||||
forwardMTokens: hop.forward_mtokens,
|
forwardMTokens: hop.forward_mtokens,
|
||||||
timeout: hop.timeout
|
timeout: hop.timeout,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fee: payment.fee,
|
fee: payment.fee,
|
||||||
feeMTokens: payment.fee_mtokens,
|
feeMTokens: payment.fee_mtokens,
|
||||||
hops: hops,
|
hops: hops,
|
||||||
id: payment.id,
|
id: payment.id,
|
||||||
isConfirmed: payment.is_confirmed,
|
isConfirmed: payment.is_confirmed,
|
||||||
isOutgoing: payment.is_outgoing,
|
isOutgoing: payment.is_outgoing,
|
||||||
mtokens: payment.mtokens,
|
mtokens: payment.mtokens,
|
||||||
secret: payment.secret,
|
secret: payment.secret,
|
||||||
tokens: payment.tokens
|
tokens: payment.tokens,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error paying request: %o", error);
|
logger.error('Error paying request: %o', error);
|
||||||
throw new Error("Failed to pay request.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,34 +1,36 @@
|
||||||
import { getChannelBalance as getLnChannelBalance } from "ln-service";
|
import { getChannelBalance as getLnChannelBalance } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { ChannelBalanceType } from "../../../schemaTypes/query/info/channelBalance";
|
import { ChannelBalanceType } from '../../../schemaTypes/query/info/channelBalance';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GraphQLNonNull, GraphQLString } from "graphql";
|
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface ChannelBalanceProps {
|
interface ChannelBalanceProps {
|
||||||
channel_balance: number;
|
channel_balance: number;
|
||||||
pending_balance: number;
|
pending_balance: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getChannelBalance = {
|
export const getChannelBalance = {
|
||||||
type: ChannelBalanceType,
|
type: ChannelBalanceType,
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "channelBalance", 1, "1s");
|
await requestLimiter(context.ip, params, 'channelBalance', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const channelBalance: ChannelBalanceProps = await getLnChannelBalance({
|
const channelBalance: ChannelBalanceProps = await getLnChannelBalance(
|
||||||
lnd: lnd
|
{
|
||||||
});
|
lnd: lnd,
|
||||||
return {
|
},
|
||||||
confirmedBalance: channelBalance.channel_balance,
|
);
|
||||||
pendingBalance: channelBalance.pending_balance
|
return {
|
||||||
};
|
confirmedBalance: channelBalance.channel_balance,
|
||||||
} catch (error) {
|
pendingBalance: channelBalance.pending_balance,
|
||||||
logger.error("Error getting channel balance: %o", error);
|
};
|
||||||
throw new Error("Failed to get channel balance.");
|
} catch (error) {
|
||||||
}
|
logger.error('Error getting channel balance: %o', error);
|
||||||
}
|
throw new Error(getErrorMsg(error));
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,97 +1,97 @@
|
||||||
import { GraphQLList, GraphQLNonNull, GraphQLString } from "graphql";
|
import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
import { getChannels as getLnChannels, getNode } from "ln-service";
|
import { getChannels as getLnChannels, getNode } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { ChannelType } from "../../../schemaTypes/query/info/channels";
|
import { ChannelType } from '../../../schemaTypes/query/info/channels';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface ChannelListProps {
|
interface ChannelListProps {
|
||||||
channels: ChannelProps[];
|
channels: ChannelProps[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ChannelProps {
|
interface ChannelProps {
|
||||||
capacity: number;
|
capacity: number;
|
||||||
commit_transaction_fee: number;
|
commit_transaction_fee: number;
|
||||||
commit_transaction_weight: number;
|
commit_transaction_weight: number;
|
||||||
id: string;
|
id: string;
|
||||||
is_active: boolean;
|
is_active: boolean;
|
||||||
is_closing: boolean;
|
is_closing: boolean;
|
||||||
is_opening: boolean;
|
is_opening: boolean;
|
||||||
is_partner_initiated: boolean;
|
is_partner_initiated: boolean;
|
||||||
is_private: boolean;
|
is_private: boolean;
|
||||||
is_static_remote_key: boolean;
|
is_static_remote_key: boolean;
|
||||||
local_balance: number;
|
local_balance: number;
|
||||||
local_reserve: number;
|
local_reserve: number;
|
||||||
partner_public_key: string;
|
partner_public_key: string;
|
||||||
pending_payments: [];
|
pending_payments: [];
|
||||||
received: number;
|
received: number;
|
||||||
remote_balance: number;
|
remote_balance: number;
|
||||||
remote_reserve: number;
|
remote_reserve: number;
|
||||||
sent: number;
|
sent: number;
|
||||||
time_offline: number;
|
time_offline: number;
|
||||||
time_online: number;
|
time_online: number;
|
||||||
transaction_id: string;
|
transaction_id: string;
|
||||||
transaction_vout: number;
|
transaction_vout: number;
|
||||||
unsettled_balance: number;
|
unsettled_balance: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getChannels = {
|
export const getChannels = {
|
||||||
type: new GraphQLList(ChannelType),
|
type: new GraphQLList(ChannelType),
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "channels", 1, "1s");
|
await requestLimiter(context.ip, params, 'channels', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const channelList: ChannelListProps = await getLnChannels({
|
const channelList: ChannelListProps = await getLnChannels({
|
||||||
lnd
|
lnd,
|
||||||
});
|
});
|
||||||
|
|
||||||
const channels = channelList.channels.map(async channel => {
|
const channels = channelList.channels.map(async channel => {
|
||||||
const nodeInfo = await getNode({
|
const nodeInfo = await getNode({
|
||||||
lnd,
|
lnd,
|
||||||
is_omitting_channels: true,
|
is_omitting_channels: true,
|
||||||
public_key: channel.partner_public_key
|
public_key: channel.partner_public_key,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
capacity: channel.capacity,
|
capacity: channel.capacity,
|
||||||
commitTransactionFee: channel.commit_transaction_fee,
|
commitTransactionFee: channel.commit_transaction_fee,
|
||||||
commitTransactionWeight: channel.commit_transaction_weight,
|
commitTransactionWeight: channel.commit_transaction_weight,
|
||||||
id: channel.id,
|
id: channel.id,
|
||||||
isActive: channel.is_active,
|
isActive: channel.is_active,
|
||||||
isClosing: channel.is_closing,
|
isClosing: channel.is_closing,
|
||||||
isOpening: channel.is_opening,
|
isOpening: channel.is_opening,
|
||||||
isPartnerInitiated: !channel.is_partner_initiated,
|
isPartnerInitiated: !channel.is_partner_initiated,
|
||||||
isPrivate: channel.is_private,
|
isPrivate: channel.is_private,
|
||||||
isStaticRemoteKey: channel.is_static_remote_key,
|
isStaticRemoteKey: channel.is_static_remote_key,
|
||||||
localBalance: channel.local_balance,
|
localBalance: channel.local_balance,
|
||||||
localReserve: channel.local_reserve,
|
localReserve: channel.local_reserve,
|
||||||
partnerPublicKey: channel.partner_public_key,
|
partnerPublicKey: channel.partner_public_key,
|
||||||
received: channel.received,
|
received: channel.received,
|
||||||
remoteBalance: channel.remote_balance,
|
remoteBalance: channel.remote_balance,
|
||||||
remoteReserve: channel.remote_reserve,
|
remoteReserve: channel.remote_reserve,
|
||||||
sent: channel.sent,
|
sent: channel.sent,
|
||||||
timeOffline: channel.time_offline,
|
timeOffline: channel.time_offline,
|
||||||
timeOnline: channel.time_online,
|
timeOnline: channel.time_online,
|
||||||
transactionId: channel.transaction_id,
|
transactionId: channel.transaction_id,
|
||||||
transactionVout: channel.transaction_vout,
|
transactionVout: channel.transaction_vout,
|
||||||
unsettledBalance: channel.unsettled_balance,
|
unsettledBalance: channel.unsettled_balance,
|
||||||
partnerNodeInfo: {
|
partnerNodeInfo: {
|
||||||
alias: nodeInfo.alias,
|
alias: nodeInfo.alias,
|
||||||
capacity: nodeInfo.capacity,
|
capacity: nodeInfo.capacity,
|
||||||
channelCount: nodeInfo.channel_count,
|
channelCount: nodeInfo.channel_count,
|
||||||
color: nodeInfo.color,
|
color: nodeInfo.color,
|
||||||
lastUpdate: nodeInfo.updated_at
|
lastUpdate: nodeInfo.updated_at,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return channels;
|
return channels;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting channels: %o", error);
|
logger.error('Error getting channels: %o', error);
|
||||||
throw new Error("Failed to get channels.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,99 +1,100 @@
|
||||||
import { GraphQLList, GraphQLString } from "graphql";
|
import { GraphQLList, GraphQLString } from 'graphql';
|
||||||
import { getClosedChannels as getLnClosedChannels } from "ln-service";
|
import { getClosedChannels as getLnClosedChannels } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { ClosedChannelType } from "../../../schemaTypes/query/info/closedChannels";
|
import { ClosedChannelType } from '../../../schemaTypes/query/info/closedChannels';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
|
import { getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
const BREACH = "BREACH";
|
const BREACH = 'BREACH';
|
||||||
const COOPERATIVE = "COOPERATIVE";
|
const COOPERATIVE = 'COOPERATIVE';
|
||||||
const FUNDING = "FUNDING";
|
const FUNDING = 'FUNDING';
|
||||||
const LOCAL = "LOCAL";
|
const LOCAL = 'LOCAL';
|
||||||
const REMOTE = "REMOTE";
|
const REMOTE = 'REMOTE';
|
||||||
const UNKNOWN = "UNKNOWN";
|
const UNKNOWN = 'UNKNOWN';
|
||||||
|
|
||||||
interface ChannelListProps {
|
interface ChannelListProps {
|
||||||
channels: ChannelProps[];
|
channels: ChannelProps[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ChannelProps {
|
interface ChannelProps {
|
||||||
capacity: number;
|
capacity: number;
|
||||||
close_confirm_height: number;
|
close_confirm_height: number;
|
||||||
close_transaction_id: string;
|
close_transaction_id: string;
|
||||||
final_local_balance: number;
|
final_local_balance: number;
|
||||||
final_time_locked_balance: number;
|
final_time_locked_balance: number;
|
||||||
id: string;
|
id: string;
|
||||||
is_breach_close: boolean;
|
is_breach_close: boolean;
|
||||||
is_cooperative_close: boolean;
|
is_cooperative_close: boolean;
|
||||||
is_funding_cancel: boolean;
|
is_funding_cancel: boolean;
|
||||||
is_local_force_close: boolean;
|
is_local_force_close: boolean;
|
||||||
is_remote_force_close: boolean;
|
is_remote_force_close: boolean;
|
||||||
partner_public_key: string;
|
partner_public_key: string;
|
||||||
transaction_id: string;
|
transaction_id: string;
|
||||||
transaction_vout: number;
|
transaction_vout: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getCloseReason = (
|
const getCloseReason = (
|
||||||
breach: boolean,
|
breach: boolean,
|
||||||
cooperative: boolean,
|
cooperative: boolean,
|
||||||
funding: boolean,
|
funding: boolean,
|
||||||
local: boolean,
|
local: boolean,
|
||||||
remote: boolean
|
remote: boolean,
|
||||||
): string => {
|
): string => {
|
||||||
return breach
|
return breach
|
||||||
? BREACH
|
? BREACH
|
||||||
: cooperative
|
: cooperative
|
||||||
? COOPERATIVE
|
? COOPERATIVE
|
||||||
: funding
|
: funding
|
||||||
? FUNDING
|
? FUNDING
|
||||||
: local
|
: local
|
||||||
? LOCAL
|
? LOCAL
|
||||||
: remote
|
: remote
|
||||||
? REMOTE
|
? REMOTE
|
||||||
: UNKNOWN;
|
: UNKNOWN;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getClosedChannels = {
|
export const getClosedChannels = {
|
||||||
type: new GraphQLList(ClosedChannelType),
|
type: new GraphQLList(ClosedChannelType),
|
||||||
args: {
|
args: {
|
||||||
type: {
|
type: {
|
||||||
type: GraphQLString
|
type: GraphQLString,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "closedChannels", 1, "1s");
|
await requestLimiter(context.ip, params, 'closedChannels', 1, '1s');
|
||||||
const { lnd } = context;
|
const { lnd } = context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const closedChannels: ChannelListProps = await getLnClosedChannels({
|
const closedChannels: ChannelListProps = await getLnClosedChannels({
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
});
|
});
|
||||||
|
|
||||||
const channels = closedChannels.channels.map(channel => {
|
const channels = closedChannels.channels.map(channel => {
|
||||||
const closeReason = getCloseReason(
|
const closeReason = getCloseReason(
|
||||||
channel.is_breach_close,
|
channel.is_breach_close,
|
||||||
channel.is_cooperative_close,
|
channel.is_cooperative_close,
|
||||||
channel.is_funding_cancel,
|
channel.is_funding_cancel,
|
||||||
channel.is_local_force_close,
|
channel.is_local_force_close,
|
||||||
channel.is_remote_force_close
|
channel.is_remote_force_close,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
capacity: channel.capacity,
|
capacity: channel.capacity,
|
||||||
closeConfirmHeight: channel.close_confirm_height,
|
closeConfirmHeight: channel.close_confirm_height,
|
||||||
closeTransactionId: channel.close_transaction_id,
|
closeTransactionId: channel.close_transaction_id,
|
||||||
finalLocalBalance: channel.final_local_balance,
|
finalLocalBalance: channel.final_local_balance,
|
||||||
finalTimeLockedBalance: channel.final_time_locked_balance,
|
finalTimeLockedBalance: channel.final_time_locked_balance,
|
||||||
id: channel.id,
|
id: channel.id,
|
||||||
closeReason: closeReason,
|
closeReason: closeReason,
|
||||||
partnerPublicKey: channel.partner_public_key,
|
partnerPublicKey: channel.partner_public_key,
|
||||||
transactionId: channel.transaction_id,
|
transactionId: channel.transaction_id,
|
||||||
transactionVout: channel.transaction_vout
|
transactionVout: channel.transaction_vout,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return channels;
|
return channels;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting closed channels: %o", error);
|
logger.error('Error getting closed channels: %o', error);
|
||||||
throw new Error("Failed to get closed channels.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,77 +1,79 @@
|
||||||
import {
|
import {
|
||||||
getPendingChannels as getLnPendingChannels,
|
getPendingChannels as getLnPendingChannels,
|
||||||
getNode
|
getNode,
|
||||||
} from "ln-service";
|
} from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { PendingChannelType } from "../../../schemaTypes/query/info/pendingChannels";
|
import { PendingChannelType } from '../../../schemaTypes/query/info/pendingChannels';
|
||||||
import { GraphQLList, GraphQLNonNull, GraphQLString } from "graphql";
|
import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface PendingChannelListProps {
|
interface PendingChannelListProps {
|
||||||
pending_channels: PendingChannelProps[];
|
pending_channels: PendingChannelProps[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PendingChannelProps {
|
interface PendingChannelProps {
|
||||||
close_transaction_id: string;
|
close_transaction_id: string;
|
||||||
is_active: boolean;
|
is_active: boolean;
|
||||||
is_closing: boolean;
|
is_closing: boolean;
|
||||||
is_opening: boolean;
|
is_opening: boolean;
|
||||||
local_balance: number;
|
local_balance: number;
|
||||||
local_reserve: number;
|
local_reserve: number;
|
||||||
partner_public_key: string;
|
partner_public_key: string;
|
||||||
received: number;
|
received: number;
|
||||||
remote_balance: number;
|
remote_balance: number;
|
||||||
remote_reserve: number;
|
remote_reserve: number;
|
||||||
sent: number;
|
sent: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getPendingChannels = {
|
export const getPendingChannels = {
|
||||||
type: new GraphQLList(PendingChannelType),
|
type: new GraphQLList(PendingChannelType),
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "pendingChannels", 1, "1s");
|
await requestLimiter(context.ip, params, 'pendingChannels', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pendingChannels: PendingChannelListProps = await getLnPendingChannels(
|
const pendingChannels: PendingChannelListProps = await getLnPendingChannels(
|
||||||
{
|
{
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const channels = pendingChannels.pending_channels.map(
|
||||||
|
async channel => {
|
||||||
|
const nodeInfo = await getNode({
|
||||||
|
lnd,
|
||||||
|
is_omitting_channels: true,
|
||||||
|
public_key: channel.partner_public_key,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
isActive: channel.is_active,
|
||||||
|
isClosing: channel.is_closing,
|
||||||
|
isOpening: channel.is_opening,
|
||||||
|
localBalance: channel.local_balance,
|
||||||
|
localReserve: channel.local_reserve,
|
||||||
|
partnerPublicKey: channel.partner_public_key,
|
||||||
|
received: channel.received,
|
||||||
|
remoteBalance: channel.remote_balance,
|
||||||
|
remoteReserve: channel.remote_reserve,
|
||||||
|
sent: channel.sent,
|
||||||
|
partnerNodeInfo: {
|
||||||
|
alias: nodeInfo.alias,
|
||||||
|
capacity: nodeInfo.capacity,
|
||||||
|
channelCount: nodeInfo.channel_count,
|
||||||
|
color: nodeInfo.color,
|
||||||
|
lastUpdate: nodeInfo.updated_at,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return channels;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Error getting pending channels: %o', error);
|
||||||
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
);
|
},
|
||||||
|
|
||||||
const channels = pendingChannels.pending_channels.map(async channel => {
|
|
||||||
const nodeInfo = await getNode({
|
|
||||||
lnd,
|
|
||||||
is_omitting_channels: true,
|
|
||||||
public_key: channel.partner_public_key
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
isActive: channel.is_active,
|
|
||||||
isClosing: channel.is_closing,
|
|
||||||
isOpening: channel.is_opening,
|
|
||||||
localBalance: channel.local_balance,
|
|
||||||
localReserve: channel.local_reserve,
|
|
||||||
partnerPublicKey: channel.partner_public_key,
|
|
||||||
received: channel.received,
|
|
||||||
remoteBalance: channel.remote_balance,
|
|
||||||
remoteReserve: channel.remote_reserve,
|
|
||||||
sent: channel.sent,
|
|
||||||
partnerNodeInfo: {
|
|
||||||
alias: nodeInfo.alias,
|
|
||||||
capacity: nodeInfo.capacity,
|
|
||||||
channelCount: nodeInfo.channel_count,
|
|
||||||
color: nodeInfo.color,
|
|
||||||
lastUpdate: nodeInfo.updated_at
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
return channels;
|
|
||||||
} catch (error) {
|
|
||||||
logger.error("Error getting pending channels: %o", error);
|
|
||||||
throw new Error("Failed to get pending channels.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,56 +1,62 @@
|
||||||
import {
|
import {
|
||||||
getChainBalance as getBalance,
|
getChainBalance as getBalance,
|
||||||
getPendingChainBalance as getPending
|
getPendingChainBalance as getPending,
|
||||||
} from "ln-service";
|
} from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GraphQLInt, GraphQLNonNull, GraphQLString } from "graphql";
|
import { GraphQLInt, GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface ChainBalanceProps {
|
interface ChainBalanceProps {
|
||||||
chain_balance: number;
|
chain_balance: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PendingChainBalanceProps {
|
interface PendingChainBalanceProps {
|
||||||
pending_chain_balance: number;
|
pending_chain_balance: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getChainBalance = {
|
export const getChainBalance = {
|
||||||
type: GraphQLInt,
|
type: GraphQLInt,
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "chainBalance", 1, "1s");
|
await requestLimiter(context.ip, params, 'chainBalance', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const value: ChainBalanceProps = await getBalance({
|
const value: ChainBalanceProps = await getBalance({
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
});
|
});
|
||||||
return value.chain_balance;
|
return value.chain_balance;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting chain balance: %o", error);
|
logger.error('Error getting chain balance: %o', error);
|
||||||
throw new Error("Failed to get chain balance.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPendingChainBalance = {
|
export const getPendingChainBalance = {
|
||||||
type: GraphQLInt,
|
type: GraphQLInt,
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "pendingChainBalance", 1, "1s");
|
await requestLimiter(
|
||||||
|
context.ip,
|
||||||
|
params,
|
||||||
|
'pendingChainBalance',
|
||||||
|
1,
|
||||||
|
'1s',
|
||||||
|
);
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pendingValue: PendingChainBalanceProps = await getPending({
|
const pendingValue: PendingChainBalanceProps = await getPending({
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
});
|
});
|
||||||
return pendingValue.pending_chain_balance;
|
return pendingValue.pending_chain_balance;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting pending chain balance: %o", error);
|
logger.error('Error getting pending chain balance: %o', error);
|
||||||
throw new Error("Failed to get pending chain balance.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,47 +1,48 @@
|
||||||
import { getNetworkInfo as getLnNetworkInfo } from "ln-service";
|
import { getNetworkInfo as getLnNetworkInfo } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { NetworkInfoType } from "../../../schemaTypes/query/info/networkInfo";
|
import { NetworkInfoType } from '../../../schemaTypes/query/info/networkInfo';
|
||||||
import { GraphQLNonNull, GraphQLString } from "graphql";
|
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface NetworkInfoProps {
|
interface NetworkInfoProps {
|
||||||
average_channel_size: number;
|
average_channel_size: number;
|
||||||
channel_count: number;
|
channel_count: number;
|
||||||
max_channel_size: number;
|
max_channel_size: number;
|
||||||
median_channel_size: number;
|
median_channel_size: number;
|
||||||
min_channel_size: number;
|
min_channel_size: number;
|
||||||
node_count: number;
|
node_count: number;
|
||||||
not_recently_updated_policy_count: number;
|
not_recently_updated_policy_count: number;
|
||||||
total_capacity: number;
|
total_capacity: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getNetworkInfo = {
|
export const getNetworkInfo = {
|
||||||
type: NetworkInfoType,
|
type: NetworkInfoType,
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "networkInfo", 1, "1s");
|
await requestLimiter(context.ip, params, 'networkInfo', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const info: NetworkInfoProps = await getLnNetworkInfo({
|
const info: NetworkInfoProps = await getLnNetworkInfo({
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
averageChannelSize: info.average_channel_size,
|
averageChannelSize: info.average_channel_size,
|
||||||
channelCount: info.channel_count,
|
channelCount: info.channel_count,
|
||||||
maxChannelSize: info.max_channel_size,
|
maxChannelSize: info.max_channel_size,
|
||||||
medianChannelSize: info.median_channel_size,
|
medianChannelSize: info.median_channel_size,
|
||||||
minChannelSize: info.min_channel_size,
|
minChannelSize: info.min_channel_size,
|
||||||
nodeCount: info.node_count,
|
nodeCount: info.node_count,
|
||||||
notRecentlyUpdatedPolicyCount: info.not_recently_updated_policy_count,
|
notRecentlyUpdatedPolicyCount:
|
||||||
totalCapacity: info.total_capacity
|
info.not_recently_updated_policy_count,
|
||||||
};
|
totalCapacity: info.total_capacity,
|
||||||
} catch (error) {
|
};
|
||||||
logger.error("Error getting network info: %o", error);
|
} catch (error) {
|
||||||
throw new Error("Failed to get network info.");
|
logger.error('Error getting network info: %o', error);
|
||||||
}
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,58 +1,58 @@
|
||||||
import { getWalletInfo } from "ln-service";
|
import { getWalletInfo } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { NodeInfoType } from "../../../schemaTypes/query/info/nodeInfo";
|
import { NodeInfoType } from '../../../schemaTypes/query/info/nodeInfo';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
import { GraphQLNonNull, GraphQLString } from "graphql";
|
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
|
|
||||||
interface NodeInfoProps {
|
interface NodeInfoProps {
|
||||||
chains: string[];
|
chains: string[];
|
||||||
color: string;
|
color: string;
|
||||||
active_channels_count: number;
|
active_channels_count: number;
|
||||||
alias: string;
|
alias: string;
|
||||||
current_block_hash: string;
|
current_block_hash: string;
|
||||||
current_block_height: number;
|
current_block_height: number;
|
||||||
is_synced_to_chain: boolean;
|
is_synced_to_chain: boolean;
|
||||||
is_synced_to_graph: boolean;
|
is_synced_to_graph: boolean;
|
||||||
latest_block_at: string;
|
latest_block_at: string;
|
||||||
peers_count: number;
|
peers_count: number;
|
||||||
pending_channels_count: number;
|
pending_channels_count: number;
|
||||||
public_key: string;
|
public_key: string;
|
||||||
uris: string[];
|
uris: string[];
|
||||||
version: string;
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getNodeInfo = {
|
export const getNodeInfo = {
|
||||||
type: NodeInfoType,
|
type: NodeInfoType,
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "nodeInfo", 1, "1s");
|
await requestLimiter(context.ip, params, 'nodeInfo', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const info: NodeInfoProps = await getWalletInfo({
|
const info: NodeInfoProps = await getWalletInfo({
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
chains: info.chains,
|
chains: info.chains,
|
||||||
color: info.color,
|
color: info.color,
|
||||||
activeChannelsCount: info.active_channels_count,
|
activeChannelsCount: info.active_channels_count,
|
||||||
alias: info.alias,
|
alias: info.alias,
|
||||||
currentBlockHash: info.current_block_hash,
|
currentBlockHash: info.current_block_hash,
|
||||||
currentBlockHeight: info.current_block_height,
|
currentBlockHeight: info.current_block_height,
|
||||||
isSyncedToChain: info.is_synced_to_chain,
|
isSyncedToChain: info.is_synced_to_chain,
|
||||||
isSyncedToGraph: info.is_synced_to_graph,
|
isSyncedToGraph: info.is_synced_to_graph,
|
||||||
latestBlockAt: info.latest_block_at,
|
latestBlockAt: info.latest_block_at,
|
||||||
peersCount: info.peers_count,
|
peersCount: info.peers_count,
|
||||||
pendingChannelsCount: info.pending_channels_count,
|
pendingChannelsCount: info.pending_channels_count,
|
||||||
publicKey: info.public_key,
|
publicKey: info.public_key,
|
||||||
uris: info.uris,
|
uris: info.uris,
|
||||||
version: info.version
|
version: info.version,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting node info: %o", error);
|
logger.error('Error getting node info: %o', error);
|
||||||
throw new Error("Failed to get node info.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,49 +1,50 @@
|
||||||
import { GraphQLList } from "graphql";
|
import { GraphQLList } from 'graphql';
|
||||||
import { getForwards as getLnForwards } from "ln-service";
|
import { getForwards as getLnForwards } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GetForwardType } from "../../../schemaTypes/query/info/forwards";
|
import { GetForwardType } from '../../../schemaTypes/query/info/forwards';
|
||||||
|
import { getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface ForwardProps {
|
interface ForwardProps {
|
||||||
created_at: string;
|
created_at: string;
|
||||||
fee: number;
|
fee: number;
|
||||||
fee_mtokens: string;
|
fee_mtokens: string;
|
||||||
incoming_channel: string;
|
incoming_channel: string;
|
||||||
mtokens: string;
|
mtokens: string;
|
||||||
outgoing_channel: string;
|
outgoing_channel: string;
|
||||||
tokens: number;
|
tokens: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ForwardsProps {
|
interface ForwardsProps {
|
||||||
forwards: ForwardProps[];
|
forwards: ForwardProps[];
|
||||||
next: string;
|
next: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getForwards = {
|
export const getForwards = {
|
||||||
type: new GraphQLList(GetForwardType),
|
type: new GraphQLList(GetForwardType),
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "getForwards", 1, "1s");
|
await requestLimiter(context.ip, params, 'getForwards', 1, '1s');
|
||||||
const { lnd } = context;
|
const { lnd } = context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const forwardsList: ForwardsProps = await getLnForwards({
|
const forwardsList: ForwardsProps = await getLnForwards({
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
});
|
});
|
||||||
|
|
||||||
const forwards = forwardsList.forwards.map(forward => ({
|
const forwards = forwardsList.forwards.map(forward => ({
|
||||||
createdAt: forward.created_at,
|
createdAt: forward.created_at,
|
||||||
fee: forward.fee,
|
fee: forward.fee,
|
||||||
feeMtokens: forward.fee_mtokens,
|
feeMtokens: forward.fee_mtokens,
|
||||||
incomingChannel: forward.incoming_channel,
|
incomingChannel: forward.incoming_channel,
|
||||||
mtokens: forward.mtokens,
|
mtokens: forward.mtokens,
|
||||||
outgoingChannel: forward.outgoing_channel,
|
outgoingChannel: forward.outgoing_channel,
|
||||||
tokens: forward.tokens
|
tokens: forward.tokens,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return forwards;
|
return forwards;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting forwards: %o", error);
|
logger.error('Error getting forwards: %o', error);
|
||||||
throw new Error("Failed to get forwards.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,102 +1,102 @@
|
||||||
import { GraphQLList, GraphQLNonNull, GraphQLString } from "graphql";
|
import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
import { getInvoices as getLnInvoices } from "ln-service";
|
import { getInvoices as getLnInvoices } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GetInvoiceType } from "../../../schemaTypes/query/info/invoices";
|
import { GetInvoiceType } from '../../../schemaTypes/query/info/invoices';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface PaymentProps {
|
interface PaymentProps {
|
||||||
confirmed_at: string;
|
confirmed_at: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
created_height: number;
|
created_height: number;
|
||||||
in_channel: string;
|
in_channel: string;
|
||||||
is_canceled: boolean;
|
is_canceled: boolean;
|
||||||
is_confirmed: boolean;
|
is_confirmed: boolean;
|
||||||
is_held: boolean;
|
is_held: boolean;
|
||||||
mtokens: string;
|
mtokens: string;
|
||||||
pending_index: number;
|
pending_index: number;
|
||||||
tokens: number;
|
tokens: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InvoiceProps {
|
interface InvoiceProps {
|
||||||
chain_address: string;
|
chain_address: string;
|
||||||
confirmed_at: string;
|
confirmed_at: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
description: string;
|
description: string;
|
||||||
description_hash: string;
|
description_hash: string;
|
||||||
expires_at: string;
|
expires_at: string;
|
||||||
id: string;
|
id: string;
|
||||||
is_canceled: boolean;
|
is_canceled: boolean;
|
||||||
is_confirmed: boolean;
|
is_confirmed: boolean;
|
||||||
is_held: boolean;
|
is_held: boolean;
|
||||||
is_outgoing: boolean;
|
is_outgoing: boolean;
|
||||||
is_private: boolean;
|
is_private: boolean;
|
||||||
payments: PaymentProps[];
|
payments: PaymentProps[];
|
||||||
received: number;
|
received: number;
|
||||||
received_mtokens: string;
|
received_mtokens: string;
|
||||||
request: string;
|
request: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
tokens: number;
|
tokens: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InvoicesProps {
|
interface InvoicesProps {
|
||||||
invoices: InvoiceProps[];
|
invoices: InvoiceProps[];
|
||||||
next: string;
|
next: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getInvoices = {
|
export const getInvoices = {
|
||||||
type: new GraphQLList(GetInvoiceType),
|
type: new GraphQLList(GetInvoiceType),
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "getInvoices", 1, "1s");
|
await requestLimiter(context.ip, params, 'getInvoices', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const invoiceList: InvoicesProps = await getLnInvoices({
|
const invoiceList: InvoicesProps = await getLnInvoices({
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
});
|
});
|
||||||
|
|
||||||
const invoices = invoiceList.invoices.map(invoice => {
|
const invoices = invoiceList.invoices.map(invoice => {
|
||||||
const payments = invoice.payments.map(payment => ({
|
const payments = invoice.payments.map(payment => ({
|
||||||
confirmedAt: payment.confirmed_at,
|
confirmedAt: payment.confirmed_at,
|
||||||
createdAt: payment.created_at,
|
createdAt: payment.created_at,
|
||||||
createdHeight: payment.created_height,
|
createdHeight: payment.created_height,
|
||||||
inChannel: payment.in_channel,
|
inChannel: payment.in_channel,
|
||||||
isCanceled: payment.is_canceled,
|
isCanceled: payment.is_canceled,
|
||||||
isConfirmed: payment.is_confirmed,
|
isConfirmed: payment.is_confirmed,
|
||||||
isHeld: payment.is_held,
|
isHeld: payment.is_held,
|
||||||
mtokens: payment.mtokens,
|
mtokens: payment.mtokens,
|
||||||
pendingIndex: payment.pending_index,
|
pendingIndex: payment.pending_index,
|
||||||
tokens: payment.tokens
|
tokens: payment.tokens,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chainAddress: invoice.chain_address,
|
chainAddress: invoice.chain_address,
|
||||||
confirmedAt: invoice.confirmed_at,
|
confirmedAt: invoice.confirmed_at,
|
||||||
createdAt: invoice.created_at,
|
createdAt: invoice.created_at,
|
||||||
description: invoice.description,
|
description: invoice.description,
|
||||||
descriptionHash: invoice.description_hash,
|
descriptionHash: invoice.description_hash,
|
||||||
expiresAt: invoice.expires_at,
|
expiresAt: invoice.expires_at,
|
||||||
id: invoice.id,
|
id: invoice.id,
|
||||||
isCanceled: invoice.is_canceled,
|
isCanceled: invoice.is_canceled,
|
||||||
isConfirmed: invoice.is_confirmed,
|
isConfirmed: invoice.is_confirmed,
|
||||||
isHeld: invoice.is_held,
|
isHeld: invoice.is_held,
|
||||||
isOutgoing: invoice.is_outgoing,
|
isOutgoing: invoice.is_outgoing,
|
||||||
isPrivate: invoice.is_private,
|
isPrivate: invoice.is_private,
|
||||||
payments: payments,
|
payments: payments,
|
||||||
received: invoice.received,
|
received: invoice.received,
|
||||||
receivedMtokens: invoice.received_mtokens,
|
receivedMtokens: invoice.received_mtokens,
|
||||||
request: invoice.request,
|
request: invoice.request,
|
||||||
secret: invoice.secret,
|
secret: invoice.secret,
|
||||||
tokens: invoice.tokens
|
tokens: invoice.tokens,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return invoices;
|
return invoices;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting invoices: %o", error);
|
logger.error('Error getting invoices: %o', error);
|
||||||
throw new Error("Failed to get invoices.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,61 +1,61 @@
|
||||||
import { GraphQLList, GraphQLNonNull, GraphQLString } from "graphql";
|
import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
import { getPayments as getLnPayments } from "ln-service";
|
import { getPayments as getLnPayments } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { GetPaymentType } from "../../../schemaTypes/query/info/payments";
|
import { GetPaymentType } from '../../../schemaTypes/query/info/payments';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
interface PaymentProps {
|
interface PaymentProps {
|
||||||
created_at: string;
|
created_at: string;
|
||||||
destination: string;
|
destination: string;
|
||||||
fee: number;
|
fee: number;
|
||||||
fee_mtokens: string;
|
fee_mtokens: string;
|
||||||
hops: string[];
|
hops: string[];
|
||||||
id: string;
|
id: string;
|
||||||
is_confirmed: boolean;
|
is_confirmed: boolean;
|
||||||
is_outgoing: boolean;
|
is_outgoing: boolean;
|
||||||
mtokens: string;
|
mtokens: string;
|
||||||
request: string;
|
request: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
tokens: number;
|
tokens: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PaymentsProps {
|
interface PaymentsProps {
|
||||||
payments: PaymentProps[];
|
payments: PaymentProps[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getPayments = {
|
export const getPayments = {
|
||||||
type: new GraphQLList(GetPaymentType),
|
type: new GraphQLList(GetPaymentType),
|
||||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "getPayments", 1, "1s");
|
await requestLimiter(context.ip, params, 'getPayments', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const paymentList: PaymentsProps = await getLnPayments({
|
const paymentList: PaymentsProps = await getLnPayments({
|
||||||
lnd: lnd
|
lnd: lnd,
|
||||||
});
|
});
|
||||||
|
|
||||||
const payments = paymentList.payments.map(payment => ({
|
const payments = paymentList.payments.map(payment => ({
|
||||||
createdAt: payment.created_at,
|
createdAt: payment.created_at,
|
||||||
destination: payment.destination,
|
destination: payment.destination,
|
||||||
fee: payment.fee,
|
fee: payment.fee,
|
||||||
feeMtokens: payment.fee_mtokens,
|
feeMtokens: payment.fee_mtokens,
|
||||||
hops: payment.hops,
|
hops: payment.hops,
|
||||||
id: payment.id,
|
id: payment.id,
|
||||||
isConfirmed: payment.is_confirmed,
|
isConfirmed: payment.is_confirmed,
|
||||||
isOutgoing: payment.is_outgoing,
|
isOutgoing: payment.is_outgoing,
|
||||||
mtokens: payment.mtokens,
|
mtokens: payment.mtokens,
|
||||||
request: payment.request,
|
request: payment.request,
|
||||||
secret: payment.secret,
|
secret: payment.secret,
|
||||||
tokens: payment.tokens
|
tokens: payment.tokens,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return payments;
|
return payments;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting payments: %o", error);
|
logger.error('Error getting payments: %o', error);
|
||||||
throw new Error("Failed to get payments.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,68 +1,68 @@
|
||||||
import { GraphQLString, GraphQLNonNull } from "graphql";
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
import { getForwards as getLnForwards } from "ln-service";
|
import { getForwards as getLnForwards } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { subHours, subDays } from "date-fns";
|
import { subHours, subDays } from 'date-fns';
|
||||||
import { countArray } from "./Helpers";
|
import { countArray } from './Helpers';
|
||||||
import { ForwardCompleteProps } from "./ForwardReport.interface";
|
import { ForwardCompleteProps } from './ForwardReport.interface';
|
||||||
import { ForwardChannelsType } from "../../../schemaTypes/query/report/ForwardChannels";
|
import { ForwardChannelsType } from '../../../schemaTypes/query/report/ForwardChannels';
|
||||||
import { sortBy } from "underscore";
|
import { sortBy } from 'underscore';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
export const getForwardChannelsReport = {
|
export const getForwardChannelsReport = {
|
||||||
type: ForwardChannelsType,
|
type: ForwardChannelsType,
|
||||||
args: {
|
args: {
|
||||||
auth: { type: new GraphQLNonNull(GraphQLString) },
|
auth: { type: new GraphQLNonNull(GraphQLString) },
|
||||||
time: { type: GraphQLString },
|
time: { type: GraphQLString },
|
||||||
order: { type: GraphQLString }
|
order: { type: GraphQLString },
|
||||||
},
|
},
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(
|
await requestLimiter(
|
||||||
context.ip,
|
context.ip,
|
||||||
params,
|
params,
|
||||||
"getForwardChannelsReport",
|
'getForwardChannelsReport',
|
||||||
1,
|
1,
|
||||||
"1s"
|
'1s',
|
||||||
);
|
);
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
let startDate = new Date();
|
let startDate = new Date();
|
||||||
const endDate = new Date();
|
const endDate = new Date();
|
||||||
|
|
||||||
if (params.time === "month") {
|
if (params.time === 'month') {
|
||||||
startDate = subDays(endDate, 30);
|
startDate = subDays(endDate, 30);
|
||||||
} else if (params.time === "week") {
|
} else if (params.time === 'week') {
|
||||||
startDate = subDays(endDate, 7);
|
startDate = subDays(endDate, 7);
|
||||||
} else {
|
} else {
|
||||||
startDate = subHours(endDate, 24);
|
startDate = subHours(endDate, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const forwardsList: ForwardCompleteProps = await getLnForwards({
|
const forwardsList: ForwardCompleteProps = await getLnForwards({
|
||||||
lnd: lnd,
|
lnd: lnd,
|
||||||
after: startDate,
|
after: startDate,
|
||||||
before: endDate,
|
before: endDate,
|
||||||
limit: 10000
|
limit: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
const incomingCount = countArray(forwardsList.forwards, true);
|
const incomingCount = countArray(forwardsList.forwards, true);
|
||||||
const outgoingCount = countArray(forwardsList.forwards, false);
|
const outgoingCount = countArray(forwardsList.forwards, false);
|
||||||
|
|
||||||
const sortedInCount = sortBy(incomingCount, params.order)
|
const sortedInCount = sortBy(incomingCount, params.order)
|
||||||
.reverse()
|
.reverse()
|
||||||
.slice(0, 5);
|
.slice(0, 5);
|
||||||
const sortedOutCount = sortBy(outgoingCount, params.order)
|
const sortedOutCount = sortBy(outgoingCount, params.order)
|
||||||
.reverse()
|
.reverse()
|
||||||
.slice(0, 5);
|
.slice(0, 5);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
incoming: JSON.stringify(sortedInCount),
|
incoming: JSON.stringify(sortedInCount),
|
||||||
outgoing: JSON.stringify(sortedOutCount)
|
outgoing: JSON.stringify(sortedOutCount),
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting forward channel report: %o", error);
|
logger.error('Error getting forward channel report: %o', error);
|
||||||
throw new Error("Failed to get forward channel report.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,72 +1,79 @@
|
||||||
import { GraphQLString, GraphQLNonNull } from "graphql";
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
import { getForwards as getLnForwards } from "ln-service";
|
import { getForwards as getLnForwards } from 'ln-service';
|
||||||
import { logger } from "../../../helpers/logger";
|
import { logger } from '../../../helpers/logger';
|
||||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||||
import { groupBy } from "underscore";
|
import { groupBy } from 'underscore';
|
||||||
import {
|
import {
|
||||||
subHours,
|
subHours,
|
||||||
subDays,
|
subDays,
|
||||||
differenceInHours,
|
differenceInHours,
|
||||||
differenceInCalendarDays
|
differenceInCalendarDays,
|
||||||
} from "date-fns";
|
} from 'date-fns';
|
||||||
import { reduceForwardArray } from "./Helpers";
|
import { reduceForwardArray } from './Helpers';
|
||||||
import { ForwardCompleteProps } from "./ForwardReport.interface";
|
import { ForwardCompleteProps } from './ForwardReport.interface';
|
||||||
import { getAuthLnd } from "../../../helpers/helpers";
|
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||||
|
|
||||||
export const getForwardReport = {
|
export const getForwardReport = {
|
||||||
type: GraphQLString,
|
type: GraphQLString,
|
||||||
args: {
|
args: {
|
||||||
auth: { type: new GraphQLNonNull(GraphQLString) },
|
auth: { type: new GraphQLNonNull(GraphQLString) },
|
||||||
time: { type: GraphQLString }
|
time: { type: GraphQLString },
|
||||||
},
|
},
|
||||||
resolve: async (root: any, params: any, context: any) => {
|
resolve: async (root: any, params: any, context: any) => {
|
||||||
await requestLimiter(context.ip, params, "getForwardReport", 1, "1s");
|
await requestLimiter(context.ip, params, 'getForwardReport', 1, '1s');
|
||||||
|
|
||||||
const lnd = getAuthLnd(params.auth);
|
const lnd = getAuthLnd(params.auth);
|
||||||
|
|
||||||
let startDate = new Date();
|
let startDate = new Date();
|
||||||
const endDate = new Date();
|
const endDate = new Date();
|
||||||
let days = 7;
|
let days = 7;
|
||||||
|
|
||||||
if (params.time === "month") {
|
if (params.time === 'month') {
|
||||||
startDate = subDays(endDate, 30);
|
startDate = subDays(endDate, 30);
|
||||||
days = 30;
|
days = 30;
|
||||||
} else if (params.time === "week") {
|
} else if (params.time === 'week') {
|
||||||
startDate = subDays(endDate, 7);
|
startDate = subDays(endDate, 7);
|
||||||
} else {
|
} else {
|
||||||
startDate = subHours(endDate, 24);
|
startDate = subHours(endDate, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const forwardsList: ForwardCompleteProps = await getLnForwards({
|
const forwardsList: ForwardCompleteProps = await getLnForwards({
|
||||||
lnd: lnd,
|
lnd: lnd,
|
||||||
after: startDate,
|
after: startDate,
|
||||||
before: endDate,
|
before: endDate,
|
||||||
limit: 10000
|
limit: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (params.time === "month" || params.time === "week") {
|
if (params.time === 'month' || params.time === 'week') {
|
||||||
const orderedDay = groupBy(forwardsList.forwards, item => {
|
const orderedDay = groupBy(forwardsList.forwards, item => {
|
||||||
return (
|
return (
|
||||||
days - differenceInCalendarDays(endDate, new Date(item.created_at))
|
days -
|
||||||
);
|
differenceInCalendarDays(
|
||||||
});
|
endDate,
|
||||||
|
new Date(item.created_at),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const reducedOrderedDay = reduceForwardArray(orderedDay);
|
const reducedOrderedDay = reduceForwardArray(orderedDay);
|
||||||
|
|
||||||
return JSON.stringify(reducedOrderedDay);
|
return JSON.stringify(reducedOrderedDay);
|
||||||
} else {
|
} else {
|
||||||
const orderedHour = groupBy(forwardsList.forwards, item => {
|
const orderedHour = groupBy(forwardsList.forwards, item => {
|
||||||
return 24 - differenceInHours(endDate, new Date(item.created_at));
|
return (
|
||||||
});
|
24 -
|
||||||
|
differenceInHours(endDate, new Date(item.created_at))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const reducedOrderedHour = reduceForwardArray(orderedHour);
|
const reducedOrderedHour = reduceForwardArray(orderedHour);
|
||||||
|
|
||||||
return JSON.stringify(reducedOrderedHour);
|
return JSON.stringify(reducedOrderedHour);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error getting forward report: %o", error);
|
logger.error('Error getting forward report: %o', error);
|
||||||
throw new Error("Failed to get forward report.");
|
throw new Error(getErrorMsg(error));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue