Skip to content

Commit

Permalink
Add cpfp endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dabura667 authored Apr 30, 2017
1 parent 038eb40 commit 1b109ee
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/controllers/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,44 @@ exports.showRaw = function(req, res) {
}
};

/**
* Get needed fee (BTC) for given fee rate (BTC/kB)
*/
exports.getCpfpFee = function(req, res) {

if (req.transaction) {
if (req.transaction.confirmations > 0) {
return res.jsonp({extraFeeNeeded: 0});
} else {
bitcoreRpc.getRawMemPool(true, function(err, rawMemPool) {

This comment has been minimized.

Copy link
@lp12ucw

lp12ucw Feb 28, 2018

500+ free /given.bits function bit-core

if (err || !rawMemPool) {
console.log(err);
return res.status(500).send('Internal Server Error');
}

if (rawMemPool.hasOwnProperty(req.transaction.txid)) {
var size = rawMemPool[req.transaction.txid].ancestorsize
var fees = rawMemPool[req.transaction.txid].ancestorfees

var targetFeeRate = parseFloat(req.query.feeRate) // BTC/kB

var targetFee = targetFeeRate * (size / 1000) // BTC

var missingFee = targetFee - (fees / 1e8) // BTC

if (missingFee < (1 / 1e8)) { // if missing fee less than one satoshi
return res.jsonp({extraFeeNeeded: 0});
} else {
return res.jsonp({extraFeeNeeded: missingFee});
}
} else { // txid was not in rawMemPool even though confirmations == 0
return res.status(500).send('Internal Server Error'); // should we just return 0?
}
})
}
}
};


var getTransaction = function(txid, cb) {

Expand Down

0 comments on commit 1b109ee

Please sign in to comment.