feat: add adminCheck query

This commit is contained in:
AP 2020-02-22 15:33:06 +01:00
parent 358944a79b
commit 098f541a33
5 changed files with 50 additions and 12 deletions

View File

@ -1,6 +1,6 @@
{
"name": "thunderhub",
"version": "0.1.1",
"version": "0.1.2",
"description": "",
"main": "index.js",
"scripts": {

View File

@ -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 });
};

View 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();
}
},
};

View File

@ -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,
};

View File

@ -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' },
};