From df17d26d10a6c9bee62f41b71615f76d3c628458 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 15 Jul 2015 16:20:27 -0300 Subject: [PATCH 1/4] add estimatefee endpoint to REST api --- app/controllers/utils.js | 24 ++++++++++++++++++++++++ app/models/Utils.js | 22 ++++++++++++++++++++++ config/routes.js | 4 ++++ 3 files changed, 50 insertions(+) create mode 100644 app/controllers/utils.js create mode 100644 app/models/Utils.js diff --git a/app/controllers/utils.js b/app/controllers/utils.js new file mode 100644 index 0000000..b7f0ce7 --- /dev/null +++ b/app/controllers/utils.js @@ -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); +}; diff --git a/app/models/Utils.js b/app/models/Utils.js new file mode 100644 index 0000000..ab51dee --- /dev/null +++ b/app/models/Utils.js @@ -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); diff --git a/config/routes.js b/config/routes.js index d4ba952..fbb896c 100644 --- a/config/routes.js +++ b/config/routes.js @@ -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); From 6886441b0b10afa37dabac16868236f39345cf63 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 15 Jul 2015 16:23:28 -0300 Subject: [PATCH 2/4] update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index ea04cac..046f553 100644 --- a/README.md +++ b/README.md @@ -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). From 360f743f8fad19126e5e819fa57a966619a6c384 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 15 Jul 2015 16:41:24 -0300 Subject: [PATCH 3/4] bump bitcore ^0.1.41 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c5e35cd..3f01722 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "base58-native": "0.1.2", "bignum": "*", "morgan": "*", - "bitcore": "git://github.com/bitpay/bitcore.git#aa41c70cff2583d810664c073a324376c39c8b36", + "bitcore": "^0.1.41", "bufferput": "git://github.com/bitpay/node-bufferput.git", "buffertools": "*", "commander": "^2.3.0", From 876b2e31de0529b97c7d3d70b538cd347f304dde Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 16 Jul 2015 17:18:31 -0300 Subject: [PATCH 4/4] update bitcore dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f01722..8676082 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "base58-native": "0.1.2", "bignum": "*", "morgan": "*", - "bitcore": "^0.1.41", + "bitcore": "git://github.com/bitpay/bitcore.git#51c53b16ced6bcaf4b78329955d6814579fe4ee9", "bufferput": "git://github.com/bitpay/node-bufferput.git", "buffertools": "*", "commander": "^2.3.0",