Merge pull request #341 from isocolsky/feat/estimatefee

Feat/estimatefee
This commit is contained in:
Gustavo Maximiliano Cortez 2015-07-22 15:22:36 -03:00
commit 74c27b284f
5 changed files with 58 additions and 1 deletions

View File

@ -371,6 +371,13 @@ Where "xxx" can be:
* getBestBlockHash
* getLastBlockHash
### Utility methods
```
/api/utils/estimatefee[?nbBlocks=2]
```
## Web Socket API
The web socket API is served using [socket.io](http://socket.io).

24
app/controllers/utils.js Normal file
View 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
View 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);

View File

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

View File

@ -48,7 +48,7 @@
"base58-native": "0.1.2",
"bignum": "*",
"morgan": "*",
"bitcore": "git://github.com/bitpay/bitcore.git#aa41c70cff2583d810664c073a324376c39c8b36",
"bitcore": "git://github.com/bitpay/bitcore.git#51c53b16ced6bcaf4b78329955d6814579fe4ee9",
"bufferput": "git://github.com/bitpay/node-bufferput.git",
"buffertools": "*",
"commander": "^2.3.0",