Skip to content

Commit 74c27b2

Browse files
committed
Merge pull request #341 from isocolsky/feat/estimatefee
Feat/estimatefee
2 parents 74a96e9 + 876b2e3 commit 74c27b2

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ Where "xxx" can be:
371371
* getBestBlockHash
372372
* getLastBlockHash
373373

374+
375+
### Utility methods
376+
```
377+
/api/utils/estimatefee[?nbBlocks=2]
378+
```
379+
380+
374381
## Web Socket API
375382
The web socket API is served using [socket.io](http://socket.io).
376383

app/controllers/utils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var Utils = require('../models/Utils'),
8+
common = require('./common');
9+
10+
exports.estimateFee = function(req, res) {
11+
12+
var nbBlocks = +req.query.nbBlocks || 2;
13+
var utilsObject = new Utils();
14+
15+
var returnJsonp = function(err) {
16+
if (err || !utilsObject)
17+
return common.handleErrors(err, res);
18+
else {
19+
res.jsonp(utilsObject);
20+
}
21+
};
22+
23+
utilsObject.estimateFee(nbBlocks, returnJsonp);
24+
};

app/models/Utils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
//var imports = require('soop').imports();
3+
4+
var bitcore = require('bitcore');
5+
var RpcClient = bitcore.RpcClient;
6+
var config = require('../../config/config');
7+
var rpc = new RpcClient(config.bitcoind);
8+
9+
function Utils() {}
10+
11+
Utils.prototype.estimateFee = function(n, next) {
12+
var that = this;
13+
14+
rpc.estimateFee(n, function(err, info) {
15+
if (err) return next(err);
16+
17+
that.feePerKB = info.result;
18+
return next();
19+
});
20+
};
21+
22+
module.exports = require('soop')(Utils);

config/routes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ module.exports = function(app) {
5353
app.get(apiPrefix + '/sync', st.sync);
5454
app.get(apiPrefix + '/peer', st.peer);
5555

56+
// Utils route
57+
var utils = require('../app/controllers/utils');
58+
app.get(apiPrefix + '/utils/estimatefee', utils.estimateFee);
59+
5660
// Currency
5761
var currency = require('../app/controllers/currency');
5862
app.get(apiPrefix + '/currency', currency.index);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"base58-native": "0.1.2",
4949
"bignum": "*",
5050
"morgan": "*",
51-
"bitcore": "git://github.com/bitpay/bitcore.git#aa41c70cff2583d810664c073a324376c39c8b36",
51+
"bitcore": "git://github.com/bitpay/bitcore.git#51c53b16ced6bcaf4b78329955d6814579fe4ee9",
5252
"bufferput": "git://github.com/bitpay/node-bufferput.git",
5353
"buffertools": "*",
5454
"commander": "^2.3.0",

0 commit comments

Comments
 (0)