Compare commits

..

No commits in common. "46134e1a6302c497ddf6c1789ab811a663af34bd" and "fe6896ba98d25638a4464fe3ac12333d5cfcba3e" have entirely different histories.

2 changed files with 26 additions and 38 deletions

View File

@ -644,13 +644,13 @@ WalletService.prototype._endpointResyncAddresses = function() {
if(!oldAddresses) {
return res.status(404).send('Not found');
}
self._removeWallet(walletId, function(err) {
if(err) {
return utils.sendError(err, res);
}
self._createWallet(walletId, function() {
var jobId = utils.generateJobId();
@ -713,16 +713,16 @@ WalletService.prototype._endpointGetTransactions = function() {
walletId: walletId
};
var missingTxidCount = 0;
var txStream = new Transform({ objectMode: true, highWaterMark: 100 });
var missingTxidCount = 0;
var transform = new Transform({ objectMode: true, highWaterMark: 1000000 });
//txids are sent in and the actual tx's are found here
txStream._transform = function(chunk, enc, callback) {
transform._transform = function(chunk, enc, callback) {
var txid = self._encoding.decodeWalletTransactionKey(chunk).txid.toString('hex');
if (txid.length !== 64 || txid === '0000000000000000000000000000000000000000000000000000000000000000') {
missingTxidCount++;
txStream.emit('error', new Error('Chunk: ' + chunk.toString('hex') + ' did not contain a txid.'));
log.error('missingTxidCount: ', missingTxidCount);
return callback();
}
@ -730,38 +730,31 @@ WalletService.prototype._endpointGetTransactions = function() {
if(err) {
log.error(err);
txStream.emit('error', err);
transform.unpipe();
return callback();
}
var formattedTx = utils.toJSONL(self._formatTransaction(tx));
txStream.push(formattedTx);
transform.push(formattedTx);
callback();
});
};
txStream.on('error', function(err) {
log.error(err);
utils.sendError(err, res);
txStream.unpipe();
});
txStream._flush = function(callback) {
transform._flush = function(callback) {
self.db.resumeSync();
callback();
};
var encodingFn = self._encoding.encodeWalletTransactionKey.bind(self._encoding);
var dbStream = self.db.createKeyStream(self._getSearchParams(encodingFn, options));
var stream = self.db.createKeyStream(self._getSearchParams(encodingFn, options));
dbStream.on('close', function() {
dbStream.unpipe();
stream.on('close', function() {
stream.unpipe();
});
dbStream.pipe(txStream).pipe(res);
stream.pipe(transform).pipe(res);
});
});
};
@ -1380,7 +1373,7 @@ WalletService.prototype._setupWriteRoutes = function(app) {
v.checkAddresses,
s._endpointPostAddresses()
);
app.put('/wallets/:walletId/addresses/resync',
app.put('/wallets/:walletId/addresses/resync',
s._endpointResyncAddresses()
);
};
@ -1399,3 +1392,4 @@ WalletService.prototype.getRoutePrefix = function() {
};
module.exports = WalletService;

View File

@ -76,6 +76,16 @@ utils.waitForBitcoreNode = function(opts, callback) {
var self = this;
opts.bitcore.process.stdout.on('data', function(data) {
if (opts.debug) {
console.log(data.toString());
}
});
opts.bitcore.process.stderr.on('data', function(data) {
console.log(data.toString());
});
var errorFilter = function(err, res) {
try {
var info = JSON.parse(res);
@ -143,22 +153,7 @@ utils.initializeAndStartService = function(opts, callback) {
};
utils.startBitcoreNode = function(opts, callback) {
this.initializeAndStartService(opts.bitcore, function(err) {
if (err) {
return callback(err);
}
opts.bitcore.process.stdout.on('data', function(data) {
if (opts.debug) {
process.stdout.write(data.toString());
}
});
opts.bitcore.process.stderr.on('data', function(data) {
process.stderr.write(data.toString());
});
callback();
});
this.initializeAndStartService(opts.bitcore, callback);
};
utils.startBitcoind = function(opts, callback) {
@ -346,7 +341,6 @@ utils.getListOfTxs = function(opts, callback) {
path: '/wallet-api/wallets/' + opts.walletId + '/transactions?start=0&end=' + end });
self.queryBitcoreNode(httpOpts, function(err, res) {
if(err) {
return callback(err);
}