Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
24 changes: 24 additions & 0 deletions app/controllers/utils.js
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions app/models/Utils.js
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 4 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down