feat: refactor close channel mutation

This commit is contained in:
AP 2019-11-22 05:44:16 +01:00
parent 5c56dd51c7
commit 69f277f044

View file

@ -1,7 +1,12 @@
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 { GraphQLBoolean, GraphQLString } from "graphql"; import {
GraphQLBoolean,
GraphQLString,
GraphQLInt,
GraphQLNonNull
} from "graphql";
import { CloseChannelType } from "../../../schemaTypes/mutation.ts/channels/closeChannel"; import { CloseChannelType } from "../../../schemaTypes/mutation.ts/channels/closeChannel";
interface CloseChannelProps { interface CloseChannelProps {
@ -12,34 +17,29 @@ interface CloseChannelProps {
export const closeChannel = { export const closeChannel = {
type: CloseChannelType, type: CloseChannelType,
args: { args: {
id: {
type: new GraphQLNonNull(GraphQLString)
},
forceClose: { forceClose: {
type: GraphQLBoolean type: GraphQLBoolean
}, },
id: { targetConfirmations: {
type: GraphQLString type: GraphQLInt
}, },
transactionId: { tokensPerVByte: {
type: GraphQLString type: GraphQLInt
},
transactionOutput: {
type: GraphQLString
} }
}, },
resolve: async (root: any, params: any, context: any) => { resolve: async (root: any, params: any, context: any) => {
await requestLimiter(context.ip, params, "closeChannel", 1, "1s"); await requestLimiter(context.ip, params, "closeChannel", 1, "1s");
const { lnd } = context; const { lnd } = context;
if (!params.id && !params.transactionId && !params.transactionOutput)
throw new Error(
"Id, transaction id or transaction output index are required"
);
try { try {
const info: CloseChannelProps = await lnCloseChannel({ const info: CloseChannelProps = await lnCloseChannel({
lnd: lnd, lnd: lnd,
id: params.id, id: params.id,
is_force_close: params.forceClose, target_confirmations: params.targetConfirmations,
transaction_id: params.transactionId tokens_per_vbyte: params.tokensPerVByte
}); });
return { return {
transactionId: info.transaction_id, transactionId: info.transaction_id,