File tree Expand file tree Collapse file tree 2 files changed +20
-19
lines changed Expand file tree Collapse file tree 2 files changed +20
-19
lines changed Original file line number Diff line number Diff line change 44 * Module dependencies.
55 */
66
7- var Utils = require ( '../models/Utils' ) ,
8- common = require ( './common' ) ;
7+ var _ = require ( 'lodash' ) ;
8+
9+ var Utils = require ( '../models/Utils' ) ;
10+ var common = require ( './common' ) ;
911
1012exports . estimateFee = function ( req , res ) {
13+ var args = req . query . nbBlocks || '2' ;
14+ var nbBlocks = args . split ( ',' ) ;
1115
12- var nbBlocks = + req . query . nbBlocks || 2 ;
1316 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 ) ;
17+ utilsObject . estimateFee ( nbBlocks , function ( err , fees ) {
18+ if ( err ) return common . handleErrors ( err , res ) ;
19+ res . jsonp ( fees ) ;
20+ } ) ;
2421} ;
Original file line number Diff line number Diff line change 11'use strict' ;
22//var imports = require('soop').imports();
3+ var _ = require ( 'lodash' ) ;
4+ var async = require ( 'async' ) ;
35
46var bitcore = require ( 'bitcore' ) ;
57var RpcClient = bitcore . RpcClient ;
@@ -8,14 +10,16 @@ var rpc = new RpcClient(config.bitcoind);
810
911function Utils ( ) { }
1012
11- Utils . prototype . estimateFee = function ( n , next ) {
13+ Utils . prototype . estimateFee = function ( nbBlocks , cb ) {
1214 var that = this ;
1315
14- rpc . estimateFee ( n , function ( err , info ) {
15- if ( err ) return next ( err ) ;
16-
17- that . feePerKB = info . result ;
18- return next ( ) ;
16+ async . map ( [ ] . concat ( nbBlocks ) , function ( n , next ) {
17+ rpc . estimateFee ( + n , function ( err , info ) {
18+ return next ( err , [ n , info . result ] ) ;
19+ } ) ;
20+ } , function ( err , result ) {
21+ if ( err ) return cb ( err ) ;
22+ return cb ( null , _ . zipObject ( result ) ) ;
1923 } ) ;
2024} ;
2125
You can’t perform that action at this time.
0 commit comments