File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,44 @@ exports.showRaw = function(req, res) {
9292 }
9393} ;
9494
95+ /**
96+ * Get needed fee (BTC) for given fee rate (BTC/kB)
97+ */
98+ exports . getCpfpFee = function ( req , res ) {
99+
100+ if ( req . transaction ) {
101+ if ( req . transaction . confirmations > 0 ) {
102+ return res . jsonp ( { extraFeeNeeded : 0 } ) ;
103+ } else {
104+ bitcoreRpc . getRawMemPool ( true , function ( err , rawMemPool ) {
105+ if ( err || ! rawMemPool ) {
106+ console . log ( err ) ;
107+ return res . status ( 500 ) . send ( 'Internal Server Error' ) ;
108+ }
109+
110+ if ( rawMemPool . hasOwnProperty ( req . transaction . txid ) ) {
111+ var size = rawMemPool [ req . transaction . txid ] . ancestorsize
112+ var fees = rawMemPool [ req . transaction . txid ] . ancestorfees
113+
114+ var targetFeeRate = parseFloat ( req . query . feeRate ) // BTC/kB
115+
116+ var targetFee = targetFeeRate * ( size / 1000 ) // BTC
117+
118+ var missingFee = targetFee - ( fees / 1e8 ) // BTC
119+
120+ if ( missingFee < ( 1 / 1e8 ) ) { // if missing fee less than one satoshi
121+ return res . jsonp ( { extraFeeNeeded : 0 } ) ;
122+ } else {
123+ return res . jsonp ( { extraFeeNeeded : missingFee } ) ;
124+ }
125+ } else { // txid was not in rawMemPool even though confirmations == 0
126+ return res . status ( 500 ) . send ( 'Internal Server Error' ) ; // should we just return 0?
127+ }
128+ } )
129+ }
130+ }
131+ } ;
132+
95133
96134var getTransaction = function ( txid , cb ) {
97135
You can’t perform that action at this time.
0 commit comments