mirror of
https://github.com/apotdevin/thunderhub.git
synced 2024-11-19 18:00:05 +01:00
feat: bitcoin fee query
This commit is contained in:
parent
5de9502f58
commit
ae923e9fcc
18
src/schemaTypes/query/data/bitcoinFee.ts
Normal file
18
src/schemaTypes/query/data/bitcoinFee.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { GraphQLObjectType, GraphQLInt } from 'graphql';
|
||||
|
||||
export const BitcoinFeeType = new GraphQLObjectType({
|
||||
name: 'bitcoinFeeType',
|
||||
fields: () => {
|
||||
return {
|
||||
fast: {
|
||||
type: GraphQLInt,
|
||||
},
|
||||
halfHour: {
|
||||
type: GraphQLInt,
|
||||
},
|
||||
hour: {
|
||||
type: GraphQLInt,
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
@ -1,4 +1,5 @@
|
||||
import { channels } from "./channels";
|
||||
import { invoices } from "./invoices";
|
||||
import { channels } from './channels';
|
||||
import { invoices } from './invoices';
|
||||
import { onChain } from './onchain';
|
||||
|
||||
export const mutation = { ...channels, ...invoices };
|
||||
export const mutation = { ...channels, ...invoices, ...onChain };
|
||||
|
7
src/schemas/mutations/onchain/index.ts
Normal file
7
src/schemas/mutations/onchain/index.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { createAddress } from './getAddress';
|
||||
import { sendToAddress } from './sendToAddress';
|
||||
|
||||
export const onChain = {
|
||||
createAddress,
|
||||
sendToAddress,
|
||||
};
|
@ -18,18 +18,18 @@ interface SendProps {
|
||||
tokens: number;
|
||||
}
|
||||
|
||||
export const sentToAddress = {
|
||||
export const sendToAddress = {
|
||||
type: SendToType,
|
||||
args: {
|
||||
auth: { type: new GraphQLNonNull(GraphQLString) },
|
||||
address: { type: new GraphQLNonNull(GraphQLString) },
|
||||
tokens: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
tokens: { type: GraphQLInt },
|
||||
fee: { type: GraphQLInt },
|
||||
target: { type: GraphQLInt },
|
||||
sendAll: { type: GraphQLBoolean },
|
||||
},
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
await requestLimiter(context.ip, params, 'createAddress', 1, '1s');
|
||||
await requestLimiter(context.ip, params, 'sendToAddress', 1, '1s');
|
||||
const lnd = getAuthLnd(params.auth);
|
||||
|
||||
const props = params.fee
|
||||
|
38
src/schemas/query/data/bitcoinFee.ts
Normal file
38
src/schemas/query/data/bitcoinFee.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { logger } from '../../../helpers/logger';
|
||||
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||
import { GraphQLString } from 'graphql';
|
||||
import fetch from 'node-fetch';
|
||||
import { BitcoinFeeType } from '../../../schemaTypes/query/data/bitcoinFee';
|
||||
|
||||
const url = 'https://bitcoinfees.earn.com/api/v1/fees/recommended';
|
||||
|
||||
export const getBitcoinFees = {
|
||||
type: BitcoinFeeType,
|
||||
args: {
|
||||
currency: {
|
||||
type: GraphQLString,
|
||||
},
|
||||
},
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
await requestLimiter(context.ip, params, 'bitcoinFee', 1, '1s');
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const json = await response.json();
|
||||
|
||||
if (json) {
|
||||
const { fastestFee, halfHourFee, hourFee } = json;
|
||||
return {
|
||||
fast: fastestFee,
|
||||
halfHour: halfHourFee,
|
||||
hour: hourFee,
|
||||
};
|
||||
} else {
|
||||
throw new Error('Problem getting Bitcoin fees.');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Error getting bitcoin fees: %o', error);
|
||||
throw new Error('Problem getting Bitcoin fees.');
|
||||
}
|
||||
},
|
||||
};
|
@ -1,5 +1,7 @@
|
||||
import { getBitcoinPrice } from "./bitcoinPrice";
|
||||
import { getBitcoinPrice } from './bitcoinPrice';
|
||||
import { getBitcoinFees } from './bitcoinFee';
|
||||
|
||||
export const dataQueries = {
|
||||
getBitcoinPrice
|
||||
getBitcoinPrice,
|
||||
getBitcoinFees,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user