Skip to main content
Glama
fee.js1.55 kB
'use strict'; var axios = require('axios') var db = require('./db') var networks = [ 'bitcoin', 'bitcoincash', 'litecoin', 'smileycoin', 'testnet' ]; function save(network, data) { if (network !== 'bitcoin') throw new Error(network + ' currency fee is not supported'); var collection = db().collection('fee'); return collection.updateOne({_id: network}, {$set: { hour: data.hour, fastest: data.fastest, minimum: data.minimum }}, {upsert: true}); } function getFromAPI(network) { if (network !== 'bitcoin') throw new Error(network + ' currency fee is not supported'); return axios.get('https://bitcoinfees.earn.com/api/v1/fees/recommended').then(function(response) { var data = response.data; if (!data.fastestFee || !data.hourFee) throw new Error('Bad fee response'); response.data.minimum = Math.max(Math.ceil(response.data.hourFee / 2), 10) return response.data; }) } function getFromCache(network) { if (networks.indexOf(network) === -1) { return Promise.reject({error: 'Currency fee is not supported'}); } var collection = db().collection('fee'); return collection .find({_id: network}) .limit(1) .next(); } function getFromCache(network) { if (networks.indexOf(network) === -1) { return Promise.reject({error: 'Currency fee is not supported'}); } var collection = db().collection('fee'); return collection .find({_id: network}) .limit(1) .next(); } module.exports = { save: save, getFromAPI: getFromAPI, getFromCache: getFromCache }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fefergrgrgrg/cloudflare-api-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server