option to skip double speed confirmations
This commit is contained in:
parent
04f0cf7b08
commit
10c69762bf
|
@ -24,9 +24,9 @@ function spec(b) {
|
|||
// Inputs => add index + coinBase flag
|
||||
var n =0;
|
||||
info.vin.forEach(function(i) {
|
||||
if (i.coinbase) info.isCoinBase = true;
|
||||
i.n = n++;
|
||||
delete i.scriptSig['hex'];
|
||||
if (i.coinbase) info.isCoinBase = true;
|
||||
if (i.scriptSig) delete i.scriptSig['hex'];
|
||||
});
|
||||
|
||||
// Outputs => add total
|
||||
|
|
|
@ -24,6 +24,7 @@ function spec(b) {
|
|||
var CONCURRENCY = 10;
|
||||
|
||||
var MAX_OPEN_FILES = 500;
|
||||
var CONFIRMATION_NR_TO_NOT_CHECK = 10;
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
@ -192,7 +193,7 @@ function spec(b) {
|
|||
var incompleteInputs = 0;
|
||||
|
||||
async.eachLimit(info.vin, CONCURRENCY, function(i, c_in) {
|
||||
self.fromTxIdN(i.txid, i.vout, function(err, ret) {
|
||||
self.fromTxIdN(i.txid, i.vout, info.confirmations, function(err, ret) {
|
||||
//console.log('[TransactionDb.js.154:ret:]',ret); //TODO
|
||||
if (!ret || !ret.addr || !ret.valueSat) {
|
||||
console.log('Could not get TXouts in %s,%d from %s ', i.txid, i.vout, info.txid);
|
||||
|
@ -206,7 +207,16 @@ function spec(b) {
|
|||
i.addr = ret.addr;
|
||||
i.valueSat = ret.valueSat;
|
||||
i.value = ret.valueSat / util.COIN;
|
||||
valueIn += i.valueSat;
|
||||
|
||||
/*
|
||||
* If confirmed by bitcoind, we could not check for double spends
|
||||
* but we prefer to keep the flag of double spend attempt
|
||||
*
|
||||
if (info.confirmations
|
||||
&& info.confirmations >= CONFIRMATION_NR_TO_NOT_CHECK)
|
||||
return c_in();
|
||||
*/
|
||||
// Double spend?
|
||||
if (ret.multipleSpendAttempt || !ret.spendTxId ||
|
||||
(ret.spendTxId && ret.spendTxId !== info.txid)
|
||||
|
@ -227,8 +237,6 @@ function spec(b) {
|
|||
} else {
|
||||
i.doubleSpendTxID = null;
|
||||
}
|
||||
|
||||
valueIn += i.valueSat;
|
||||
return c_in();
|
||||
});
|
||||
},
|
||||
|
@ -271,7 +279,7 @@ function spec(b) {
|
|||
});
|
||||
};
|
||||
|
||||
TransactionDb.prototype.fromTxIdN = function(txid, n, cb) {
|
||||
TransactionDb.prototype.fromTxIdN = function(txid, n, confirmations, cb) {
|
||||
var self = this;
|
||||
var k = OUTS_PREFIX + txid + '-' + n;
|
||||
|
||||
|
@ -288,6 +296,18 @@ function spec(b) {
|
|||
valueSat: parseInt(a[1]),
|
||||
};
|
||||
|
||||
/*
|
||||
* If this TxID comes from an RPC request
|
||||
* the .confirmations value from bitcoind is available
|
||||
* so we could avoid checking if the input were double spended
|
||||
*
|
||||
* This speed up address calculations by ~30%
|
||||
*
|
||||
if (confirmations >= CONFIRMATION_NR_TO_NOT_CHECK) {
|
||||
return cb(null, ret);
|
||||
}
|
||||
*/
|
||||
|
||||
// Spend?
|
||||
var k = SPEND_PREFIX + txid + '-' + n;
|
||||
db.createReadStream({
|
||||
|
|
Loading…
Reference in New Issue