chore: add auth to mutations

This commit is contained in:
AP 2019-11-30 22:24:11 +01:00
parent adb2b1d37b
commit b0d161993e
7 changed files with 35 additions and 50 deletions

View file

@ -8,7 +8,7 @@ import {
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'; import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers';
interface CloseChannelProps { interface CloseChannelProps {
transaction_id: string; transaction_id: string;
@ -18,22 +18,15 @@ interface CloseChannelProps {
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 },
forceClose: { tokensPerVByte: { type: GraphQLInt },
type: GraphQLBoolean, auth: { type: new GraphQLNonNull(GraphQLString) },
},
targetConfirmations: {
type: GraphQLInt,
},
tokensPerVByte: {
type: GraphQLInt,
},
}, },
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 = getAuthLnd(params.auth);
try { try {
const info: CloseChannelProps = await lnCloseChannel({ const info: CloseChannelProps = await lnCloseChannel({

View file

@ -8,7 +8,7 @@ import {
GraphQLNonNull, GraphQLNonNull,
} from 'graphql'; } from 'graphql';
import { OpenChannelType } from '../../../schemaTypes/mutation.ts/channels/openChannel'; import { OpenChannelType } from '../../../schemaTypes/mutation.ts/channels/openChannel';
import { getErrorMsg } from '../../../helpers/helpers'; import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers';
interface OpenChannelProps { interface OpenChannelProps {
transaction_id: string; transaction_id: string;
@ -18,19 +18,14 @@ interface OpenChannelProps {
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: { auth: { type: new GraphQLNonNull(GraphQLString) },
type: new GraphQLNonNull(GraphQLInt),
},
partnerPublicKey: {
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, 'openChannel', 1, '1s'); await requestLimiter(context.ip, params, 'openChannel', 1, '1s');
const { lnd } = context; const lnd = getAuthLnd(params.auth);
try { try {
const info: OpenChannelProps = await lnOpenChannel({ const info: OpenChannelProps = await lnOpenChannel({

View file

@ -1,9 +1,9 @@
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, GraphQLString } from 'graphql';
import { InvoiceType } from '../../../schemaTypes/mutation.ts/invoice/createInvoice'; import { InvoiceType } from '../../../schemaTypes/mutation.ts/invoice/createInvoice';
import { getErrorMsg } from '../../../helpers/helpers'; import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers';
interface InvoiceProps { interface InvoiceProps {
chain_address: string; chain_address: string;
@ -19,13 +19,12 @@ interface InvoiceProps {
export const createInvoice = { export const createInvoice = {
type: InvoiceType, type: InvoiceType,
args: { args: {
amount: { amount: { type: new GraphQLNonNull(GraphQLInt) },
type: new GraphQLNonNull(GraphQLInt), 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, 'createInvoice', 1, '1s'); await requestLimiter(context.ip, params, 'createInvoice', 1, '1s');
const { lnd } = context; const lnd = getAuthLnd(params.auth);
try { try {
const invoice: InvoiceProps = await createInvoiceRequest({ const invoice: InvoiceProps = await createInvoiceRequest({

View file

@ -3,7 +3,7 @@ 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'; import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers';
interface RouteProps { interface RouteProps {
base_fee_mtokens: string; base_fee_mtokens: string;
@ -32,13 +32,12 @@ interface RequestProps {
export const parsePayment = { export const parsePayment = {
type: ParsePaymentType, type: ParsePaymentType,
args: { args: {
request: { request: { type: new GraphQLNonNull(GraphQLString) },
type: new GraphQLNonNull(GraphQLString), 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, 'parsePayment', 1, '1s'); await requestLimiter(context.ip, params, 'parsePayment', 1, '1s');
const { lnd } = context; const lnd = getAuthLnd(params.auth);
try { try {
const request: RequestProps = await parsePaymentRequest({ const request: RequestProps = await parsePaymentRequest({

View file

@ -3,7 +3,7 @@ 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'; import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers';
interface HopProps { interface HopProps {
channel: string; channel: string;
@ -29,13 +29,12 @@ interface RequestProps {
export const pay = { export const pay = {
type: PayType, type: PayType,
args: { args: {
request: { request: { type: new GraphQLNonNull(GraphQLString) },
type: new GraphQLNonNull(GraphQLString), 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, 'payRequest', 1, '1s'); await requestLimiter(context.ip, params, 'payRequest', 1, '1s');
const { lnd } = context; const lnd = getAuthLnd(params.auth);
try { try {
const payment: RequestProps = await payRequest({ const payment: RequestProps = await payRequest({

View file

@ -1,9 +1,9 @@
import { GraphQLList, GraphQLString } from 'graphql'; import { GraphQLList, GraphQLString, GraphQLNonNull } 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'; import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers';
const BREACH = 'BREACH'; const BREACH = 'BREACH';
const COOPERATIVE = 'COOPERATIVE'; const COOPERATIVE = 'COOPERATIVE';
@ -56,13 +56,12 @@ const getCloseReason = (
export const getClosedChannels = { export const getClosedChannels = {
type: new GraphQLList(ClosedChannelType), type: new GraphQLList(ClosedChannelType),
args: { args: {
type: { type: { type: GraphQLString },
type: GraphQLString, 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, 'closedChannels', 1, '1s'); await requestLimiter(context.ip, params, 'closedChannels', 1, '1s');
const { lnd } = context; const lnd = getAuthLnd(params.auth);
try { try {
const closedChannels: ChannelListProps = await getLnClosedChannels({ const closedChannels: ChannelListProps = await getLnClosedChannels({

View file

@ -1,9 +1,9 @@
import { GraphQLList } from 'graphql'; import { GraphQLList, 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 { GetForwardType } from '../../../schemaTypes/query/info/forwards'; import { GetForwardType } from '../../../schemaTypes/query/info/forwards';
import { getErrorMsg } from '../../../helpers/helpers'; import { getErrorMsg, getAuthLnd } from '../../../helpers/helpers';
interface ForwardProps { interface ForwardProps {
created_at: string; created_at: string;
@ -22,9 +22,10 @@ interface ForwardsProps {
export const getForwards = { export const getForwards = {
type: new GraphQLList(GetForwardType), type: new GraphQLList(GetForwardType),
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, 'getForwards', 1, '1s'); await requestLimiter(context.ip, params, 'getForwards', 1, '1s');
const { lnd } = context; const lnd = getAuthLnd(params.auth);
try { try {
const forwardsList: ForwardsProps = await getLnForwards({ const forwardsList: ForwardsProps = await getLnForwards({