Merge pull request #341 from isocolsky/feat/estimatefee
Feat/estimatefee
This commit is contained in:
commit
74c27b284f
@ -371,6 +371,13 @@ Where "xxx" can be:
|
|||||||
* getBestBlockHash
|
* getBestBlockHash
|
||||||
* getLastBlockHash
|
* getLastBlockHash
|
||||||
|
|
||||||
|
|
||||||
|
### Utility methods
|
||||||
|
```
|
||||||
|
/api/utils/estimatefee[?nbBlocks=2]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Web Socket API
|
## Web Socket API
|
||||||
The web socket API is served using [socket.io](http://socket.io).
|
The web socket API is served using [socket.io](http://socket.io).
|
||||||
|
|
||||||
|
|||||||
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 + '/sync', st.sync);
|
||||||
app.get(apiPrefix + '/peer', st.peer);
|
app.get(apiPrefix + '/peer', st.peer);
|
||||||
|
|
||||||
|
// Utils route
|
||||||
|
var utils = require('../app/controllers/utils');
|
||||||
|
app.get(apiPrefix + '/utils/estimatefee', utils.estimateFee);
|
||||||
|
|
||||||
// Currency
|
// Currency
|
||||||
var currency = require('../app/controllers/currency');
|
var currency = require('../app/controllers/currency');
|
||||||
app.get(apiPrefix + '/currency', currency.index);
|
app.get(apiPrefix + '/currency', currency.index);
|
||||||
|
|||||||
@ -48,7 +48,7 @@
|
|||||||
"base58-native": "0.1.2",
|
"base58-native": "0.1.2",
|
||||||
"bignum": "*",
|
"bignum": "*",
|
||||||
"morgan": "*",
|
"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",
|
"bufferput": "git://github.com/bitpay/node-bufferput.git",
|
||||||
"buffertools": "*",
|
"buffertools": "*",
|
||||||
"commander": "^2.3.0",
|
"commander": "^2.3.0",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user