add estimatefee endpoint to REST api
This commit is contained in:
parent
d98757125e
commit
df17d26d10
24
app/controllers/utils.js
Normal file
24
app/controllers/utils.js
Normal file
@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Utils = require('../models/Utils'),
|
||||
common = require('./common');
|
||||
|
||||
exports.estimateFee = function(req, res) {
|
||||
|
||||
var nbBlocks = +req.query.nbBlocks || 2;
|
||||
var utilsObject = new Utils();
|
||||
|
||||
var returnJsonp = function(err) {
|
||||
if (err || !utilsObject)
|
||||
return common.handleErrors(err, res);
|
||||
else {
|
||||
res.jsonp(utilsObject);
|
||||
}
|
||||
};
|
||||
|
||||
utilsObject.estimateFee(nbBlocks, returnJsonp);
|
||||
};
|
||||
22
app/models/Utils.js
Normal file
22
app/models/Utils.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
//var imports = require('soop').imports();
|
||||
|
||||
var bitcore = require('bitcore');
|
||||
var RpcClient = bitcore.RpcClient;
|
||||
var config = require('../../config/config');
|
||||
var rpc = new RpcClient(config.bitcoind);
|
||||
|
||||
function Utils() {}
|
||||
|
||||
Utils.prototype.estimateFee = function(n, next) {
|
||||
var that = this;
|
||||
|
||||
rpc.estimateFee(n, function(err, info) {
|
||||
if (err) return next(err);
|
||||
|
||||
that.feePerKB = info.result;
|
||||
return next();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Utils);
|
||||
@ -53,6 +53,10 @@ module.exports = function(app) {
|
||||
app.get(apiPrefix + '/sync', st.sync);
|
||||
app.get(apiPrefix + '/peer', st.peer);
|
||||
|
||||
// Utils route
|
||||
var utils = require('../app/controllers/utils');
|
||||
app.get(apiPrefix + '/utils/estimatefee', utils.estimateFee);
|
||||
|
||||
// Currency
|
||||
var currency = require('../app/controllers/currency');
|
||||
app.get(apiPrefix + '/currency', currency.index);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user