Fixed streaming issue and slowness when using new PublicKey.
This commit is contained in:
parent
26704e52f7
commit
492895538a
@ -394,12 +394,12 @@ Bitcoin.prototype.getTransaction = function(txid, callback) {
|
||||
var self = this;
|
||||
self._tryAllClients(function(client, done) {
|
||||
//this won't work without a bitcoin node that has a tx index
|
||||
log.error('Txid: ' + txid + ' not found in index! Calling getRawTransaction to retrieve.');
|
||||
self.client.getRawTransaction(txid.toString('hex'), 0, function(err, response) {
|
||||
if (err) {
|
||||
return done(self._wrapRPCError(err));
|
||||
}
|
||||
var tx = new Transaction(response.result);
|
||||
done(null, tx);
|
||||
done(null, response.result);
|
||||
});
|
||||
}, callback);
|
||||
};
|
||||
|
||||
@ -72,19 +72,21 @@ util.inherits(DB, Service);
|
||||
DB.dependencies = ['bitcoind'];
|
||||
|
||||
DB.prototype.pauseSync = function(callback) {
|
||||
this._lockTimes.push(process.hrtime());
|
||||
if (this._sync.syncing) {
|
||||
this._sync.once('synced', function() {
|
||||
this._sync.paused = true;
|
||||
var self = this;
|
||||
self._lockTimes.push(process.hrtime());
|
||||
if (self._sync.syncing) {
|
||||
self._sync.once('synced', function() {
|
||||
self._sync.paused = true;
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
this._sync.paused = true;
|
||||
self._sync.paused = true;
|
||||
setImmediate(callback);
|
||||
}
|
||||
};
|
||||
|
||||
DB.prototype.resumeSync = function() {
|
||||
log.debug('Attempting to resume sync');
|
||||
var time = this._lockTimes.shift();
|
||||
if (this._lockTimes.length === 0) {
|
||||
if (time) {
|
||||
|
||||
@ -76,6 +76,7 @@ Sync.prototype.sync = function() {
|
||||
var self = this;
|
||||
|
||||
if(this.syncing || this.paused) {
|
||||
log.debug('Sync lock held, not able to sync at the moment');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -190,6 +190,9 @@ TransactionService.prototype.getTransaction = function(txid, options, callback)
|
||||
self._getMissingInputValues(tx, next);
|
||||
});
|
||||
}, function(tx, next) {
|
||||
if (tx) {
|
||||
return next(null, tx);
|
||||
}
|
||||
self.node.services.bitcoind.getTransaction(txid, next);
|
||||
}], callback);
|
||||
};
|
||||
|
||||
@ -17,7 +17,7 @@ var LRU = require('lru-cache');
|
||||
var Encoding = require('./encoding');
|
||||
var Input = require('bitcore-lib').Transaction.Input;
|
||||
var Transform = require('stream').Transform;
|
||||
var transform = new Transform({ objectMode: true });
|
||||
var transform = new Transform({ objectMode: true, highWaterMark: 1000000 });
|
||||
|
||||
var WalletService = function(options) {
|
||||
BaseService.call(this, options);
|
||||
@ -668,12 +668,13 @@ WalletService.prototype._endpointGetTransactions = function() {
|
||||
transform._transform = function(chunk, enc, callback) {
|
||||
|
||||
var txid = self._encoding.decodeWalletTransactionKey(chunk).txid.toString('hex');
|
||||
|
||||
self._getTransactionFromDb(options, txid, function(err, tx) {
|
||||
|
||||
if(err) {
|
||||
log.error(err);
|
||||
transform.push(null);
|
||||
return;
|
||||
transform.unpipe();
|
||||
return callback();
|
||||
}
|
||||
|
||||
var formattedTx = utils.toJSONL(self._formatTransaction(tx));
|
||||
@ -685,13 +686,12 @@ WalletService.prototype._endpointGetTransactions = function() {
|
||||
};
|
||||
|
||||
transform._flush = function(callback) {
|
||||
stream.unpipe(transform);
|
||||
self.db.resumeSync();
|
||||
transform.push(null);
|
||||
callback();
|
||||
};
|
||||
|
||||
var encodingFn = self._encoding.encodeWalletTransactionKey.bind(self._encoding);
|
||||
//creates a stream of txids that match the wallet's set of addresses
|
||||
var stream = self.store.createKeyStream(self._getSearchParams(encodingFn, options));
|
||||
|
||||
stream.pipe(transform).pipe(res);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user