File tree Expand file tree Collapse file tree 5 files changed +58
-1
lines changed Expand file tree Collapse file tree 5 files changed +58
-1
lines changed Original file line number Diff line number Diff 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
375382The web socket API is served using [ socket.io] ( http://socket.io ) .
376383
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments