bindings: fixes confirmation issue with orphaned block transactions

This commit is contained in:
Braydon Fuller 2016-03-04 13:47:22 -05:00
parent 462e4e3cdd
commit 8c10221480
2 changed files with 67 additions and 1 deletions

View File

@ -796,4 +796,66 @@ describe('Node Functionality', function() {
}); });
}); });
describe('Orphaned Transactions', function() {
var orphanedTransaction;
before(function(done) {
var count;
var invalidatedBlockHash;
async.series([
function(next) {
client.getBlockCount(function(err, response) {
if (err) {
return next(err);
}
count = response.result;
next();
});
},
function(next) {
client.getBlockHash(count, function(err, response) {
if (err) {
return next(err);
}
invalidatedBlockHash = response.result;
next();
});
},
function(next) {
client.getBlock(invalidatedBlockHash, function(err, response) {
if (err) {
return next(err);
}
orphanedTransaction = response.result.tx[1];
next();
});
},
function(next) {
client.invalidateBlock(invalidatedBlockHash, next);
}
], function(err) {
if (err) {
throw err;
}
done();
});
});
it('will not show confirmation count for orphaned transaction', function(done) {
// This test verifies that in the situation that the transaction is not in the mempool and
// is included in an orphaned block transaction index that the confirmation count will be unconfirmed.
node.services.bitcoind.getTransactionWithBlockInfo(orphanedTransaction, false, function(err, data) {
if (err) {
return done(err);
}
should.exist(data.height);
data.height.should.equal(-1);
done();
});
});
});
}); });

View File

@ -1230,7 +1230,11 @@ async_get_tx_and_info(uv_work_t *req) {
data->height = -1; data->height = -1;
} else { } else {
blockIndex = mapBlockIndex[blockHash]; blockIndex = mapBlockIndex[blockHash];
data->height = blockIndex->nHeight; if (!chainActive.Contains(blockIndex)) {
data->height = -1;
} else {
data->height = blockIndex->nHeight;
}
} }
} }