Fixed for getDetailedTransaction.

This commit is contained in:
Chris Kleeschulte 2017-09-27 10:21:31 -04:00
parent 2a1af1e93f
commit 0c75879084
3 changed files with 14 additions and 37 deletions

View File

@ -368,7 +368,8 @@ BlockService.prototype._queueBlock = function(block) {
}
log.info('Block Service: The best block hash is: ' + self._tip.hash +
' at height: ' + self._tip.height + ' Time since last block: ' + utils.convertMillisecondsToHumanReadable(Date.now() - self._timeOfLastBlockReport));
' at height: ' + self._tip.height + ' Time since last block: ' +
utils.convertMillisecondsToHumanReadable(Date.now() - self._timeOfLastBlockReport));
self._timeOfLastBlockReport = Date.now();
log.debug('Block Service: completed processing block: ' + block.rhash() +
@ -638,7 +639,7 @@ BlockService.prototype._processBlock = function(block, callback) {
return callback();
}
log.debug('Block Service: new block: ' + block.rhash());
log.info('Block Service: new block: ' + block.rhash());
// common case
if (!self._detectReorg(block)) {

View File

@ -260,7 +260,7 @@ HeaderService.prototype._queueBlock = function(block) {
return self._handleError(err);
}
log.debug('Header Service: completed processing block: ' + block.rhash() + ' prev hash: ' + bcoin.util.revHex(block.prevBlock));
log.info('Header Service: completed processing block: ' + block.rhash() + ' prev hash: ' + bcoin.util.revHex(block.prevBlock));
});
@ -335,6 +335,7 @@ HeaderService.prototype._syncBlock = function(block, callback) {
var dbOps = self._getDBOpForLastHeader(header);
dbOps = dbOps.concat(self._onHeader(header));
console.log(dbOps);
self._saveHeaders(dbOps, callback);
};
@ -591,6 +592,7 @@ HeaderService.prototype._detectReorg = function(block, callback) {
}
self.getBlockHeader(prevHash, function(err, header) {
if (err) {
return callback(err);
}
@ -599,7 +601,8 @@ HeaderService.prototype._detectReorg = function(block, callback) {
return callback(null, header);
}
log.warn('Block: ' + block.rhash() + ' references: ' + prevHash +
// this should be very rare
log.warn('Header Service: Block: ' + block.rhash() + ' references: ' + prevHash +
' as its previous block, yet we have not stored this block in our data set, thus ignoring this block.');
callback(null, false);

View File

@ -37,37 +37,8 @@ TransactionService.prototype.getAPIMethods = function() {
];
};
TransactionService.prototype.getDetailedTransaction = function(txid, options, callback) {
var self = this;
this.getTransaction(txid, options, function(err, tx) {
if (err) {
return callback(err);
}
if (!tx) {
return callback();
}
self._header.getBlockHeader(tx.__height, function(err, header) {
if (err) {
return callback(err);
}
assert(header, 'Tx must have a header entry in header db for given height.');
tx.__blockhash = header.hash;
callback(null, tx);
});
});
};
TransactionService.prototype.getTransaction = function(txid, options, callback) {
TransactionService.prototype.getDetailedTransaction =
TransactionService.prototype.getTransaction = function(txid, options, callback) {
var self = this;
@ -93,8 +64,7 @@ TransactionService.prototype._getSupplementaryTransactionInfo = function(txid, t
var self = this;
tx.confirmations = self._block.getTip().height - tx.__height + 1;
// TODO maybe we should index the block hash along with the height on tx,
// so that this extra lookup isn't necessary
// TODO maybe we should index the block hash along with the height on tx
self._header.getBlockHeader(tx.__height, function(err, header) {
if (err) {
@ -102,7 +72,9 @@ TransactionService.prototype._getSupplementaryTransactionInfo = function(txid, t
}
if (header) {
// Do we need both of these?
tx.blockHash = header.hash;
tx.__blockHash = header.hash;
}
callback(null, txid, tx, options);
@ -177,6 +149,7 @@ TransactionService.prototype._getMempoolTransaction = function(txid, tx, options
tx.__inputValues = inputValues;
tx.confirmations = 0;
tx.blockHash = null;
tx.__blockHash = null;
callback(null, tx, options);
});