Skip to content

Commit

Permalink
Merge pull request #106 from matiu/bug/fix-double-spent
Browse files Browse the repository at this point in the history
fix double spent reports
  • Loading branch information
cmgustavo committed May 30, 2014
2 parents 1b29ca5 + 69f7ee6 commit 4dabb9f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 37 deletions.
5 changes: 0 additions & 5 deletions app/controllers/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ exports.list = function(req, res) {
var dateStr;
var todayStr = formatTimestamp(new Date());

console.log('[blocks.js.102]'); //TODO
if (req.query.blockDate) {
// TODO: Validate format yyyy-mm-dd
dateStr = req.query.blockDate;
Expand All @@ -110,18 +109,14 @@ console.log('[blocks.js.102]'); //TODO
isToday = true;
}
var gte = Math.round((new Date(dateStr)).getTime() / 1000);
console.log('[blocks.js.112:gte:]',gte); //TODO

//pagination
var lte = parseInt(req.query.startTimestamp) || gte + 86400;
console.log('[blocks.js.115:lte:]',lte); //TODO
var prev = formatTimestamp(new Date((gte - 86400) * 1000));
var next = lte ? formatTimestamp(new Date(lte * 1000)) :null;
console.log('[blocks.js.116:next:]',next, lte); //TODO
var limit = parseInt(req.query.limit || DFLT_LIMIT) + 1;
var more;

console.log('[blocks.js.119]'); //TODO
bdb.getBlocksByDate(gte, lte, limit, function(err, blockList) {

if (err) {
Expand Down
21 changes: 21 additions & 0 deletions dev-util/getTx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
'use strict';

var util = require('util'),
config = require('../config/config');

process.env.NODE_ENV = process.env.NODE_ENV || 'development';

var TransactionDb = require('../lib/TransactionDb.js').default();
var hash = process.argv[2] || '4286d6fc82a314348af4e9d3ce649f78ce4569937e9ad6613563755f0d14e3d1';

var t= TransactionDb.fromIdWithInfo(hash,function(err,tx) {
console.log('Err:');
console.log(err);

console.log('Ret:');
console.log(util.inspect(tx,{depth:null}));
});



27 changes: 0 additions & 27 deletions dev-util/get_tx.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/BlockDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ BlockDb.prototype.getBlocksByDate = function(start_ts, end_ts, limit, cb) {
limit: limit,
reverse: 1,
};
console.log('[BlockDb.js.298:opts:]',opts); //TODO

db.createReadStream(opts)
.on('data', function (data) {
Expand Down
13 changes: 9 additions & 4 deletions lib/TransactionDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var bitcore = require('bitcore'),
buffertools = require('buffertools');

var logger = require('./logger').logger;
var info = logger.info;
var inf = logger.inf;

var db = imports.db || levelup(config.leveldb + '/txs',{maxOpenFiles: MAX_OPEN_FILES} );
var PoolMatch = imports.poolMatch || require('soop').load('./PoolMatch',config);
Expand Down Expand Up @@ -188,7 +188,7 @@ TransactionDb.prototype._fillOutpoints = function(txInfo, cb) {
async.eachLimit(txInfo.vin, CONCURRENCY, function(i, c_in) {
self.fromTxIdN(i.txid, i.vout, function(err, ret) {
if (!ret || !ret.addr || !ret.valueSat) {
info('Could not get TXouts in %s,%d from %s ', i.txid, i.vout, txInfo.txid);
inf('Could not get TXouts in %s,%d from %s ', i.txid, i.vout, txInfo.txid);
if (ret) i.unconfirmedInput = ret.unconfirmedInput;
incompleteInputs = 1;
return c_in(); // error not scalated
Expand All @@ -201,19 +201,24 @@ TransactionDb.prototype._fillOutpoints = function(txInfo, cb) {
i.value = ret.valueSat / util.COIN;
valueIn += i.valueSat;

console.log('[TransactionDb.js.204:ret:]',ret); //TODO
if (ret.multipleSpentAttempt || !ret.spentTxId ||
(ret.spentTxId && ret.spentTxId !== info.txid)
(ret.spentTxId && ret.spentTxId !== txInfo.txid)
) {
if (ret.multipleSpentAttempts) {
ret.multipleSpentAttempts.forEach(function(mul) {
if (mul.spentTxId !== info.txid) {
if (mul.spentTxId !== txInfo.txid) {

console.log('[TransactionDb.js.210]'); //TODO
i.doubleSpentTxID = ret.spentTxId;
i.doubleSpentIndex = ret.spentIndex;
}
});
} else if (!ret.spentTxId) {
i.dbError = 'Input spent not registered';
} else {

console.log('[TransactionDb.js.219]'); //TODO
i.doubleSpentTxID = ret.spentTxId;
i.doubleSpentIndex = ret.spentIndex;
}
Expand Down

0 comments on commit 4dabb9f

Please sign in to comment.