You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
/*!
|
|
* accounts/get-fees-rest-api.js
|
|
* Copyright © 2019 – Katana Cryptographic Ltd. All Rights Reserved.
|
|
*/
|
|
'use strict'
|
|
|
|
const Logger = require('../lib/logger')
|
|
const rpcFees = require('../lib/bitcoind-rpc/fees')
|
|
const authMgr = require('../lib/auth/authorizations-manager')
|
|
const HttpServer = require('../lib/http-server/http-server')
|
|
|
|
const debugApi = !!(process.argv.indexOf('api-debug') > -1)
|
|
|
|
|
|
/**
|
|
* A singleton providing util methods used by the API
|
|
*/
|
|
class FeesRestApi {
|
|
|
|
/**
|
|
* Constructor
|
|
* @param {pushtx.HttpServer} httpServer - HTTP server
|
|
*/
|
|
constructor(httpServer) {
|
|
this.httpServer = httpServer
|
|
// Establish routes
|
|
this.httpServer.app.get(
|
|
'/fees',
|
|
authMgr.checkAuthentication.bind(authMgr),
|
|
this.getFees.bind(this),
|
|
HttpServer.sendAuthError
|
|
)
|
|
// Refresh the network fees
|
|
rpcFees.refresh()
|
|
}
|
|
|
|
/**
|
|
* Refresh and return the current fees
|
|
* @param {object} req - http request object
|
|
* @param {object} res - http response object
|
|
*/
|
|
async getFees(req, res) {
|
|
try {
|
|
const fees = await rpcFees.getFees()
|
|
HttpServer.sendOkDataOnly(res, fees)
|
|
} catch (e) {
|
|
HttpServer.sendError(res, e)
|
|
} finally {
|
|
debugApi && Logger.info(`API : Completed GET /fees`)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = FeesRestApi
|
|
|