mirror of
https://github.com/apotdevin/thunderhub.git
synced 2024-11-19 09:50:03 +01:00
feat: add adminCheck query
This commit is contained in:
parent
358944a79b
commit
098f541a33
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "thunderhub",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -39,10 +39,7 @@ export const getAuthLnd = (auth: {
|
||||
return lnd;
|
||||
};
|
||||
|
||||
export const getErrorMsg = (error: any[]): string => {
|
||||
const code = error[0];
|
||||
const msg = error[1];
|
||||
|
||||
export const getErrorDetails = (error: any[]): string => {
|
||||
let details = '';
|
||||
if (error.length > 2) {
|
||||
if (error[2].err) {
|
||||
@ -52,5 +49,14 @@ export const getErrorMsg = (error: any[]): string => {
|
||||
}
|
||||
}
|
||||
|
||||
return details;
|
||||
};
|
||||
|
||||
export const getErrorMsg = (error: any[]): string => {
|
||||
const code = error[0];
|
||||
const msg = error[1];
|
||||
|
||||
let details = getErrorDetails(error);
|
||||
|
||||
return JSON.stringify({ code, msg, details });
|
||||
};
|
||||
|
29
src/schemas/query/general/adminCheck.ts
Normal file
29
src/schemas/query/general/adminCheck.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { pay as payRequest } from 'ln-service';
|
||||
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||
import { GraphQLBoolean } from 'graphql';
|
||||
import { getAuthLnd, getErrorDetails } from '../../../helpers/helpers';
|
||||
import { defaultParams } from '../../../helpers/defaultProps';
|
||||
|
||||
export const adminCheck = {
|
||||
type: GraphQLBoolean,
|
||||
args: {
|
||||
...defaultParams,
|
||||
},
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
await requestLimiter(context.ip, 'adminCheck');
|
||||
|
||||
const lnd = getAuthLnd(params.auth);
|
||||
|
||||
try {
|
||||
await payRequest({
|
||||
lnd,
|
||||
request: 'admin check',
|
||||
});
|
||||
} catch (error) {
|
||||
const details = getErrorDetails(error);
|
||||
if (details.includes('invalid character in string')) return true;
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
},
|
||||
};
|
@ -1,10 +1,12 @@
|
||||
import { getChainBalance, getPendingChainBalance } from "./chainBalance";
|
||||
import { getNetworkInfo } from "./networkInfo";
|
||||
import { getNodeInfo } from "./nodeInfo";
|
||||
import { getChainBalance, getPendingChainBalance } from './chainBalance';
|
||||
import { getNetworkInfo } from './networkInfo';
|
||||
import { getNodeInfo } from './nodeInfo';
|
||||
import { adminCheck } from './adminCheck';
|
||||
|
||||
export const generalQueries = {
|
||||
getChainBalance,
|
||||
getPendingChainBalance,
|
||||
getNetworkInfo,
|
||||
getNodeInfo
|
||||
getChainBalance,
|
||||
getPendingChainBalance,
|
||||
getNetworkInfo,
|
||||
getNodeInfo,
|
||||
adminCheck,
|
||||
};
|
||||
|
@ -40,4 +40,5 @@ export const RateConfig: RateConfigProps = {
|
||||
chainTransactions: { max: 3, window: '1s' },
|
||||
getRoutes: { max: 3, window: '1s' },
|
||||
payViaRoute: { max: 3, window: '1s' },
|
||||
adminCheck: { max: 3, window: '1s' },
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user