mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-21 22:11:37 +01:00
chore: add auth to mutations
This commit is contained in:
parent
adb2b1d37b
commit
b0d161993e
7 changed files with 35 additions and 50 deletions
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Add table
Reference in a new issue