feat: bitcoin fee query

This commit is contained in:
AP 2019-12-10 06:12:03 +01:00
parent 5de9502f58
commit ae923e9fcc
6 changed files with 74 additions and 8 deletions

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

View File

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

View File

@ -0,0 +1,7 @@
import { createAddress } from './getAddress';
import { sendToAddress } from './sendToAddress';
export const onChain = {
createAddress,
sendToAddress,
};

View File

@ -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

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

View File

@ -1,5 +1,7 @@
import { getBitcoinPrice } from "./bitcoinPrice";
import { getBitcoinPrice } from './bitcoinPrice';
import { getBitcoinFees } from './bitcoinFee';
export const dataQueries = {
getBitcoinPrice
getBitcoinPrice,
getBitcoinFees,
};