From b0d161993e1a62cacb2ced7f51f46f6d323cbc14 Mon Sep 17 00:00:00 2001 From: AP Date: Sat, 30 Nov 2019 22:24:11 +0100 Subject: [PATCH] chore: add auth to mutations --- .../mutations/channels/closeChannel.ts | 21 +++++++------------ src/schemas/mutations/channels/openChannel.ts | 17 ++++++--------- .../mutations/invoices/createInvoice.ts | 11 +++++----- .../mutations/invoices/parsePayment.ts | 9 ++++---- src/schemas/mutations/invoices/pay.ts | 9 ++++---- src/schemas/query/channels/closedChannels.ts | 11 +++++----- src/schemas/query/invoices/forwards.ts | 7 ++++--- 7 files changed, 35 insertions(+), 50 deletions(-) diff --git a/src/schemas/mutations/channels/closeChannel.ts b/src/schemas/mutations/channels/closeChannel.ts index ead97d0f..fe5bb8ff 100644 --- a/src/schemas/mutations/channels/closeChannel.ts +++ b/src/schemas/mutations/channels/closeChannel.ts @@ -8,7 +8,7 @@ import { GraphQLNonNull, } from 'graphql'; import { CloseChannelType } from '../../../schemaTypes/mutation.ts/channels/closeChannel'; -import { getErrorMsg } from '../../../helpers/helpers'; +import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers'; interface CloseChannelProps { transaction_id: string; @@ -18,22 +18,15 @@ interface CloseChannelProps { export const closeChannel = { type: CloseChannelType, args: { - id: { - type: new GraphQLNonNull(GraphQLString), - }, - forceClose: { - type: GraphQLBoolean, - }, - targetConfirmations: { - type: GraphQLInt, - }, - tokensPerVByte: { - type: GraphQLInt, - }, + id: { type: new GraphQLNonNull(GraphQLString) }, + forceClose: { type: GraphQLBoolean }, + targetConfirmations: { type: GraphQLInt }, + tokensPerVByte: { type: GraphQLInt }, + auth: { type: new GraphQLNonNull(GraphQLString) }, }, resolve: async (root: any, params: any, context: any) => { await requestLimiter(context.ip, params, 'closeChannel', 1, '1s'); - const { lnd } = context; + const lnd = getAuthLnd(params.auth); try { const info: CloseChannelProps = await lnCloseChannel({ diff --git a/src/schemas/mutations/channels/openChannel.ts b/src/schemas/mutations/channels/openChannel.ts index 27ad1573..a8398025 100644 --- a/src/schemas/mutations/channels/openChannel.ts +++ b/src/schemas/mutations/channels/openChannel.ts @@ -8,7 +8,7 @@ import { GraphQLNonNull, } from 'graphql'; import { OpenChannelType } from '../../../schemaTypes/mutation.ts/channels/openChannel'; -import { getErrorMsg } from '../../../helpers/helpers'; +import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers'; interface OpenChannelProps { transaction_id: string; @@ -18,19 +18,14 @@ interface OpenChannelProps { export const openChannel = { type: OpenChannelType, args: { - isPrivate: { - type: GraphQLBoolean, - }, - amount: { - type: new GraphQLNonNull(GraphQLInt), - }, - partnerPublicKey: { - type: new GraphQLNonNull(GraphQLString), - }, + isPrivate: { type: GraphQLBoolean }, + amount: { type: new GraphQLNonNull(GraphQLInt) }, + partnerPublicKey: { type: new GraphQLNonNull(GraphQLString) }, + auth: { type: new GraphQLNonNull(GraphQLString) }, }, resolve: async (root: any, params: any, context: any) => { await requestLimiter(context.ip, params, 'openChannel', 1, '1s'); - const { lnd } = context; + const lnd = getAuthLnd(params.auth); try { const info: OpenChannelProps = await lnOpenChannel({ diff --git a/src/schemas/mutations/invoices/createInvoice.ts b/src/schemas/mutations/invoices/createInvoice.ts index 57843ac8..174ceaf4 100644 --- a/src/schemas/mutations/invoices/createInvoice.ts +++ b/src/schemas/mutations/invoices/createInvoice.ts @@ -1,9 +1,9 @@ import { createInvoice as createInvoiceRequest } from 'ln-service'; import { logger } from '../../../helpers/logger'; import { requestLimiter } from '../../../helpers/rateLimiter'; -import { GraphQLNonNull, GraphQLInt } from 'graphql'; +import { GraphQLNonNull, GraphQLInt, GraphQLString } from 'graphql'; import { InvoiceType } from '../../../schemaTypes/mutation.ts/invoice/createInvoice'; -import { getErrorMsg } from '../../../helpers/helpers'; +import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers'; interface InvoiceProps { chain_address: string; @@ -19,13 +19,12 @@ interface InvoiceProps { export const createInvoice = { type: InvoiceType, args: { - amount: { - type: new GraphQLNonNull(GraphQLInt), - }, + amount: { type: new GraphQLNonNull(GraphQLInt) }, + auth: { type: new GraphQLNonNull(GraphQLString) }, }, resolve: async (root: any, params: any, context: any) => { await requestLimiter(context.ip, params, 'createInvoice', 1, '1s'); - const { lnd } = context; + const lnd = getAuthLnd(params.auth); try { const invoice: InvoiceProps = await createInvoiceRequest({ diff --git a/src/schemas/mutations/invoices/parsePayment.ts b/src/schemas/mutations/invoices/parsePayment.ts index 24093888..df935536 100644 --- a/src/schemas/mutations/invoices/parsePayment.ts +++ b/src/schemas/mutations/invoices/parsePayment.ts @@ -3,7 +3,7 @@ import { logger } from '../../../helpers/logger'; import { requestLimiter } from '../../../helpers/rateLimiter'; import { GraphQLString, GraphQLNonNull } from 'graphql'; import { ParsePaymentType } from '../../../schemaTypes/mutation.ts/invoice/parsePayment'; -import { getErrorMsg } from '../../../helpers/helpers'; +import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers'; interface RouteProps { base_fee_mtokens: string; @@ -32,13 +32,12 @@ interface RequestProps { export const parsePayment = { type: ParsePaymentType, args: { - request: { - type: new GraphQLNonNull(GraphQLString), - }, + request: { type: new GraphQLNonNull(GraphQLString) }, + auth: { type: new GraphQLNonNull(GraphQLString) }, }, resolve: async (root: any, params: any, context: any) => { await requestLimiter(context.ip, params, 'parsePayment', 1, '1s'); - const { lnd } = context; + const lnd = getAuthLnd(params.auth); try { const request: RequestProps = await parsePaymentRequest({ diff --git a/src/schemas/mutations/invoices/pay.ts b/src/schemas/mutations/invoices/pay.ts index 5b57ba05..ed4fb7fa 100644 --- a/src/schemas/mutations/invoices/pay.ts +++ b/src/schemas/mutations/invoices/pay.ts @@ -3,7 +3,7 @@ import { logger } from '../../../helpers/logger'; import { requestLimiter } from '../../../helpers/rateLimiter'; import { GraphQLString, GraphQLNonNull } from 'graphql'; import { PayType } from '../../../schemaTypes/mutation.ts/invoice/pay'; -import { getErrorMsg } from '../../../helpers/helpers'; +import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers'; interface HopProps { channel: string; @@ -29,13 +29,12 @@ interface RequestProps { export const pay = { type: PayType, args: { - request: { - type: new GraphQLNonNull(GraphQLString), - }, + request: { type: new GraphQLNonNull(GraphQLString) }, + auth: { type: new GraphQLNonNull(GraphQLString) }, }, resolve: async (root: any, params: any, context: any) => { await requestLimiter(context.ip, params, 'payRequest', 1, '1s'); - const { lnd } = context; + const lnd = getAuthLnd(params.auth); try { const payment: RequestProps = await payRequest({ diff --git a/src/schemas/query/channels/closedChannels.ts b/src/schemas/query/channels/closedChannels.ts index 6f7c94d6..6c472c9b 100644 --- a/src/schemas/query/channels/closedChannels.ts +++ b/src/schemas/query/channels/closedChannels.ts @@ -1,9 +1,9 @@ -import { GraphQLList, GraphQLString } from 'graphql'; +import { GraphQLList, GraphQLString, GraphQLNonNull } from 'graphql'; import { getClosedChannels as getLnClosedChannels } from 'ln-service'; import { logger } from '../../../helpers/logger'; import { ClosedChannelType } from '../../../schemaTypes/query/info/closedChannels'; import { requestLimiter } from '../../../helpers/rateLimiter'; -import { getErrorMsg } from '../../../helpers/helpers'; +import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers'; const BREACH = 'BREACH'; const COOPERATIVE = 'COOPERATIVE'; @@ -56,13 +56,12 @@ const getCloseReason = ( export const getClosedChannels = { type: new GraphQLList(ClosedChannelType), args: { - type: { - type: GraphQLString, - }, + type: { type: GraphQLString }, + auth: { type: new GraphQLNonNull(GraphQLString) }, }, resolve: async (root: any, params: any, context: any) => { await requestLimiter(context.ip, params, 'closedChannels', 1, '1s'); - const { lnd } = context; + const lnd = getAuthLnd(params.auth); try { const closedChannels: ChannelListProps = await getLnClosedChannels({ diff --git a/src/schemas/query/invoices/forwards.ts b/src/schemas/query/invoices/forwards.ts index f8e30288..616be0d5 100644 --- a/src/schemas/query/invoices/forwards.ts +++ b/src/schemas/query/invoices/forwards.ts @@ -1,9 +1,9 @@ -import { GraphQLList } from 'graphql'; +import { GraphQLList, GraphQLString, GraphQLNonNull } from 'graphql'; import { getForwards as getLnForwards } from 'ln-service'; import { logger } from '../../../helpers/logger'; import { requestLimiter } from '../../../helpers/rateLimiter'; import { GetForwardType } from '../../../schemaTypes/query/info/forwards'; -import { getErrorMsg } from '../../../helpers/helpers'; +import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers'; interface ForwardProps { created_at: string; @@ -22,9 +22,10 @@ interface ForwardsProps { export const getForwards = { type: new GraphQLList(GetForwardType), + args: { auth: { type: new GraphQLNonNull(GraphQLString) } }, resolve: async (root: any, params: any, context: any) => { await requestLimiter(context.ip, params, 'getForwards', 1, '1s'); - const { lnd } = context; + const lnd = getAuthLnd(params.auth); try { const forwardsList: ForwardsProps = await getLnForwards({