This commit is contained in:
Chris Kleeschulte 2017-05-11 10:00:01 -04:00
parent 67517be6d4
commit 94445c2073
3 changed files with 100 additions and 102 deletions

View File

@ -291,7 +291,7 @@ WalletService.prototype._processSerialInput = function(opts, tx, input, callback
async.mapSeries(walletIds, function(walletId, next) { async.mapSeries(walletIds, function(walletId, next) {
self.node.services.transaction.getTransaction(input.prevTxId, {}, function(err, tx) { self.node.services.transaction.getTransaction(input.prevTxId.toString('hex'), {}, function(err, tx) {
if(err) { if(err) {
return next(err); return next(err);
@ -647,6 +647,8 @@ WalletService.prototype._endpointGetTransactions = function() {
var self = this; var self = this;
return function(req, res) { return function(req, res) {
console.log('endpoint get transactions');
var walletId = req.params.walletId; var walletId = req.params.walletId;
self.db.pauseSync(function() { self.db.pauseSync(function() {
@ -666,7 +668,7 @@ WalletService.prototype._endpointGetTransactions = function() {
//txids are sent in and the actual tx's are found here //txids are sent in and the actual tx's are found here
transform._transform = function(chunk, enc, callback) { transform._transform = function(chunk, enc, callback) {
var txid = self._encoding.decodeWalletTransactionKey(chunk).txid; var txid = self._encoding.decodeWalletTransactionKey(chunk).txid.toString('hex');
self._getTransactionFromDb(options, txid, function(err, tx) { self._getTransactionFromDb(options, txid, function(err, tx) {
transform.push(utils.toJSONL(self._formatTransaction(tx))); transform.push(utils.toJSONL(self._formatTransaction(tx)));
@ -679,7 +681,7 @@ WalletService.prototype._endpointGetTransactions = function() {
transform._flush = function (callback) { transform._flush = function (callback) {
self.db.resumeSync(); self.db.resumeSync();
callback(); callback();
} };
var encodingFn = self._encoding.encodeWalletTransactionKey.bind(self._encoding); var encodingFn = self._encoding.encodeWalletTransactionKey.bind(self._encoding);
//creates a stream of txids that match the wallet's set of addresses //creates a stream of txids that match the wallet's set of addresses
@ -808,7 +810,7 @@ WalletService.prototype._getTransactionFromDb = function(options, txid, callback
var self = options.self; var self = options.self;
self.node.services.transaction.getTransaction(txid, options, function(err, tx) { self.node.services.transaction.getTransaction(txid.toString('hex'), options, function(err, tx) {
if(err) { if(err) {
return callback(err); return callback(err);
@ -818,9 +820,9 @@ WalletService.prototype._getTransactionFromDb = function(options, txid, callback
return callback(null, tx); return callback(null, tx);
} }
async.map(tx.inputs, function(input, next) { async.mapLimit(tx.inputs, 8, function(input, next) {
self.node.services.transaction.getTransaction(input.prevTxId, options, function(err, tx) { self.node.services.transaction.getTransaction(input.prevTxId.toString('hex'), options, function(err, tx) {
if(err) { if(err) {
return next(err); return next(err);
@ -1233,6 +1235,7 @@ WalletService.prototype._endpointJobStatus = function() {
WalletService.prototype._endpointGetInfo = function() { WalletService.prototype._endpointGetInfo = function() {
var self = this; var self = this;
return function(req, res) { return function(req, res) {
console.log('info called');
res.jsonp({ res.jsonp({
result: 'ok', result: 'ok',
dbheight: self.node.services.db.tip.__height, dbheight: self.node.services.db.tip.__height,

View File

@ -25,7 +25,7 @@ utils.toArgs = function(opts) {
}; };
utils.waitForService = function(task, callback) { utils.waitForService = function(task, callback) {
var retryOpts = { times: 20, interval: 1000 }; var retryOpts = { times: 20, interval: 10000 };
async.retry(retryOpts, task, callback); async.retry(retryOpts, task, callback);
}; };
@ -35,9 +35,8 @@ utils.queryBitcoreNode = function(httpOpts, callback) {
if (res.statusCode !== 200 && res.statusCode !== 201) { if (res.statusCode !== 200 && res.statusCode !== 201) {
if (error) { if (error) {
return; return callback();
} }
return callback(res.statusCode);
} }
var resError; var resError;
@ -53,7 +52,7 @@ utils.queryBitcoreNode = function(httpOpts, callback) {
res.on('end', function() { res.on('end', function() {
if (error) { if (error) {
return; return callback(error);
} }
if (httpOpts.errorFilter) { if (httpOpts.errorFilter) {
return callback(httpOpts.errorFilter(resError, resData)); return callback(httpOpts.errorFilter(resError, resData));
@ -65,7 +64,7 @@ utils.queryBitcoreNode = function(httpOpts, callback) {
request.on('error', function(e) { request.on('error', function(e) {
error = e; error = e;
callback(error); callback();
}); });
request.write(httpOpts.body || ''); request.write(httpOpts.body || '');
@ -100,8 +99,14 @@ utils.waitForBitcoreNode = function(opts, callback) {
}; };
var httpOpts = self.getHttpOpts(opts, { path: '/wallet-api/info', errorFilter: errorFilter }); var httpOpts = self.getHttpOpts(opts, { path: '/wallet-api/info', errorFilter: errorFilter });
var rounds = 10;
self.waitForService(self.queryBitcoreNode.bind(self, httpOpts), callback); async.whilst(
function() {
console.log('called rounds', rounds);
return rounds--;
},
self.queryBitcoreNode.bind(self, httpOpts), callback);
//self.waitForService(self.queryBitcoreNode.bind(self, httpOpts), callback);
}; };
utils.waitForBitcoinReady = function(opts, callback) { utils.waitForBitcoinReady = function(opts, callback) {
@ -334,7 +339,6 @@ utils.uploadWallet = function(opts, callback) {
}; };
utils.getListOfTxs = function(opts, callback) { utils.getListOfTxs = function(opts, callback) {
var self = this; var self = this;
var end = Date.now() + 86400000; var end = Date.now() + 86400000;
var httpOpts = self.getHttpOpts(opts, { var httpOpts = self.getHttpOpts(opts, {

View File

@ -129,7 +129,7 @@ describe('Wallet Operations', function() {
it('should register wallet', function(done) { it('should register wallet', function(done) {
utils.registerWallet.call(utils, self.opts, function(err, res) { utils.registerWallet(self.opts, function(err, res) {
if (err) { if (err) {
return done(err); return done(err);
@ -144,24 +144,23 @@ describe('Wallet Operations', function() {
it('should upload a wallet', function(done) { it('should upload a wallet', function(done) {
utils.uploadWallet.call(utils, self.opts, done); utils.uploadWallet(self.opts, done);
}); });
it('should get a list of transactions', function(done) { it('should get a list of transactions', function(done) {
//the wallet should be fully uploaded and indexed by the time this happens //the wallet should be fully uploaded and indexed by the time this happens
utils.sendTxs.call(utils, self.opts, function(err) { utils.sendTxs(self.opts, function(err) {
if(err) { if(err) {
return done(err); return done(err);
} }
utils.waitForBitcoreNode.call(utils, self.opts, function(err) { utils.waitForBitcoreNode(self.opts, function(err) {
if(err) { if(err) {
return done(err); return done(err);
} }
utils.getListOfTxs.call(utils, self.opts, done); utils.getListOfTxs(self.opts, done);
}); });
}); });
@ -169,106 +168,98 @@ describe('Wallet Operations', function() {
}); });
describe('Load addresses after syncing the blockchain', function() { //describe('Load addresses after syncing the blockchain', function() {
var self = this; // var self = this;
self.opts = Object.assign({}, opts); // self.opts = Object.assign({}, opts);
after(utils.cleanup.bind(utils, self.opts)); // after(utils.cleanup.bind(utils, self.opts));
before(function(done) { // before(function(done) {
async.series([ // async.series([
utils.startBitcoind.bind(utils, self.opts), // utils.startBitcoind.bind(utils, self.opts),
utils.waitForBitcoinReady.bind(utils, self.opts), // utils.waitForBitcoinReady.bind(utils, self.opts),
utils.unlockWallet.bind(utils, self.opts), // utils.unlockWallet.bind(utils, self.opts),
utils.setupInitialTxs.bind(utils, self.opts), // utils.setupInitialTxs.bind(utils, self.opts),
utils.sendTxs.bind(utils, self.opts), // utils.sendTxs.bind(utils, self.opts),
utils.startBitcoreNode.bind(utils, self.opts), // utils.startBitcoreNode.bind(utils, self.opts),
utils.waitForBitcoreNode.bind(utils, self.opts), // utils.waitForBitcoreNode.bind(utils, self.opts),
utils.registerWallet.bind(utils, self.opts), // utils.registerWallet.bind(utils, self.opts),
utils.uploadWallet.bind(utils, self.opts) // utils.uploadWallet.bind(utils, self.opts)
], done); // ], done);
}); // });
it('should get list of transactions', function(done) { // it('should get list of transactions', function(done) {
utils.waitForBitcoreNode(self.opts, function(err) { // utils.getListOfTxs(self.opts, done);
if(err) { // });
return done(err);
}
utils.getListOfTxs.call(utils, self.opts, done);
});
}); // it('should get the balance of a wallet', function(done) {
it('should get the balance of a wallet', function(done) { // var httpOpts = utils.getHttpOpts(
// self.opts,
// { path: '/wallet-api/wallets/' + self.opts.walletId + '/balance' });
var httpOpts = utils.getHttpOpts.call( // utils.queryBitcoreNode(httpOpts, function(err, res) {
utils, // if(err) {
self.opts, // return done(err);
{ path: '/wallet-api/wallets/' + self.opts.walletId + '/balance' }); // }
// var results = JSON.parse(res);
// results.satoshis.should.equal(self.opts.satoshisReceived);
// done();
// });
utils.queryBitcoreNode.call(utils, httpOpts, function(err, res) { // });
if(err) {
return done(err);
}
var results = JSON.parse(res);
results.satoshis.should.equal(self.opts.satoshisReceived);
done();
});
}); // it('should get the set of utxos for the wallet', function(done) {
it('should get the set of utxos for the wallet', function(done) { // var httpOpts = utils.getHttpOpts(
// self.opts,
// { path: '/wallet-api/wallets/' + opts.walletId + '/utxos' });
var httpOpts = utils.getHttpOpts.call( // utils.queryBitcoreNode(httpOpts, function(err, res) {
utils,
self.opts,
{ path: '/wallet-api/wallets/' + opts.walletId + '/utxos' });
utils.queryBitcoreNode.call(utils, httpOpts, function(err, res) { // if(err) {
// return done(err);
// }
if(err) { // var results = JSON.parse(res);
return done(err); // var balance = 0;
}
var results = JSON.parse(res); // results.utxos.forEach(function(utxo) {
var balance = 0; // balance += utxo.satoshis;
// });
results.utxos.forEach(function(utxo) { // results.height.should.equal(self.opts.blockHeight);
balance += utxo.satoshis; // balance.should.equal(self.opts.satoshisReceived);
}); // done();
// });
// });
results.height.should.equal(self.opts.blockHeight); // it('should get the list of jobs', function(done) {
balance.should.equal(self.opts.satoshisReceived); // var httpOpts = utils.getHttpOpts(self.opts, { path: '/wallet-api/jobs' });
done(); // utils.queryBitcoreNode(httpOpts, function(err, res) {
}); // if(err) {
}); // return done(err);
// }
// var results = JSON.parse(res);
// results.jobCount.should.equal(1);
// done();
// });
// });
it('should get the list of jobs', function(done) { // it('should remove all wallets', function(done) {
var httpOpts = utils.getHttpOpts.call(utils, self.opts, { path: '/wallet-api/jobs' }); // var httpOpts = utils.getHttpOpts(self.opts, { path: '/wallet-api/wallets', method: 'DELETE' });
utils.queryBitcoreNode.call(utils, httpOpts, function(err, res) { // utils.queryBitcoreNode(httpOpts, function(err, res) {
if(err) { // if(err) {
return done(err); // return done(err);
} // }
var results = JSON.parse(res); // var results = JSON.parse(res);
results.jobCount.should.equal(1); // results.numberRemoved.should.equal(152);
done(); // done();
}); // });
}); // });
//});
it('should remove all wallets', function(done) {
var httpOpts = utils.getHttpOpts.call(utils, self.opts, { path: '/wallet-api/wallets', method: 'DELETE' });
utils.queryBitcoreNode.call(utils, httpOpts, function(err, res) {
if(err) {
return done(err);
}
var results = JSON.parse(res);
results.numberRemoved.should.equal(152);
done();
});
});
});
}); });