|
|
@ -156,20 +156,19 @@ function spec() { |
|
|
|
|
|
|
|
var filter = reindex ? {} : { processed: false } ; |
|
|
|
|
|
|
|
Transaction.find(filter, |
|
|
|
function(err, txs) { |
|
|
|
if (err) return cb(err); |
|
|
|
Transaction.find(filter, function(err, txs) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var read = 0, |
|
|
|
pull = 0, |
|
|
|
write = 0, |
|
|
|
total = txs.length; |
|
|
|
var read = 0, |
|
|
|
pull = 0, |
|
|
|
proc = 0, |
|
|
|
total = txs.length; |
|
|
|
|
|
|
|
console.log('\tneed to pull %d txs', total); |
|
|
|
console.log('\tneed to pull %d txs', total); |
|
|
|
|
|
|
|
if (!total) return cb(); |
|
|
|
if (!total) return cb(); |
|
|
|
|
|
|
|
async.each(txs, function(tx, next) { |
|
|
|
async.each(txs, function(tx, next) { |
|
|
|
if (read++ % 1000 === 0) progress_bar('read', read, total); |
|
|
|
|
|
|
|
if (!tx.txid) { |
|
|
@ -177,73 +176,14 @@ function spec() { |
|
|
|
return next(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// This will trigger an RPC call
|
|
|
|
Transaction.fromIdWithInfo( tx.txid, function(err,t) { |
|
|
|
if (pull++ % 1000 === 0) progress_bar('\tpull', pull, total); |
|
|
|
|
|
|
|
if (!err && t) { |
|
|
|
var index = 0; |
|
|
|
|
|
|
|
async.each(t.info.vin, function(i, next_in) { |
|
|
|
|
|
|
|
/* |
|
|
|
* TODO Support multisigs??? |
|
|
|
* how?? |
|
|
|
*/ |
|
|
|
|
|
|
|
if (i.addr && i.value) { |
|
|
|
TransactionItem.create({ |
|
|
|
txid : t.txid, |
|
|
|
value : -1 * i.value, |
|
|
|
addr : i.addr, |
|
|
|
index : i.n, |
|
|
|
}, next_in); |
|
|
|
} |
|
|
|
else { |
|
|
|
if ( !i.coinbase ) |
|
|
|
console.log ("TX: %s seems to be multisig IN. Skipping... ", t.txid); |
|
|
|
return next_in(); |
|
|
|
} |
|
|
|
}, |
|
|
|
function (err) { |
|
|
|
if (err) console.log (err); |
|
|
|
index = 0; |
|
|
|
async.each(t.info.vout, function(o, next_out) { |
|
|
|
|
|
|
|
/* |
|
|
|
* TODO Support multisigs |
|
|
|
*/ |
|
|
|
if (o.value && o.scriptPubKey |
|
|
|
&& o.scriptPubKey.addresses |
|
|
|
&& o.scriptPubKey.addresses[0] |
|
|
|
) { |
|
|
|
TransactionItem.create({ |
|
|
|
txid : t.txid, |
|
|
|
value : o.value, |
|
|
|
addr : o.scriptPubKey.addresses[0], |
|
|
|
index : o.n, |
|
|
|
}, next_out); |
|
|
|
} |
|
|
|
else { |
|
|
|
console.log ("TX: %s,%d seems to be multisig OUT. Skipping... ", t.txid, o.n); |
|
|
|
return next_out(); |
|
|
|
} |
|
|
|
}, |
|
|
|
function (err) { |
|
|
|
if (err) console.log (err); |
|
|
|
if (write++ % 1000 === 0) progress_bar('\t\twrite', write, total); |
|
|
|
return next(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
else return next(); |
|
|
|
Transaction.explodeTransactionItems( tx.txid, function(err) { |
|
|
|
if (proc++ % 1000 === 0) progress_bar('\tproc', pull, total); |
|
|
|
next(err); |
|
|
|
}); |
|
|
|
}, |
|
|
|
function(err) { |
|
|
|
return cb(err); |
|
|
|
}); |
|
|
|
}); |
|
|
|
cb); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Sync.prototype.init = function(opts) { |
|
|
|