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) {
self.node.services.transaction.getTransaction(input.prevTxId, {}, function(err, tx) {
self.node.services.transaction.getTransaction(input.prevTxId.toString('hex'), {}, function(err, tx) {
if(err) {
return next(err);
@ -647,6 +647,8 @@ WalletService.prototype._endpointGetTransactions = function() {
var self = this;
return function(req, res) {
console.log('endpoint get transactions');
var walletId = req.params.walletId;
self.db.pauseSync(function() {
@ -666,7 +668,7 @@ WalletService.prototype._endpointGetTransactions = function() {
//txids are sent in and the actual tx's are found here
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) {
transform.push(utils.toJSONL(self._formatTransaction(tx)));
@ -679,7 +681,7 @@ WalletService.prototype._endpointGetTransactions = function() {
transform._flush = function (callback) {
self.db.resumeSync();
callback();
}
};
var encodingFn = self._encoding.encodeWalletTransactionKey.bind(self._encoding);
//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;
self.node.services.transaction.getTransaction(txid, options, function(err, tx) {
self.node.services.transaction.getTransaction(txid.toString('hex'), options, function(err, tx) {
if(err) {
return callback(err);
@ -818,9 +820,9 @@ WalletService.prototype._getTransactionFromDb = function(options, txid, callback
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) {
return next(err);
@ -1233,6 +1235,7 @@ WalletService.prototype._endpointJobStatus = function() {
WalletService.prototype._endpointGetInfo = function() {
var self = this;
return function(req, res) {
console.log('info called');
res.jsonp({
result: 'ok',
dbheight: self.node.services.db.tip.__height,

View File

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

View File

@ -129,7 +129,7 @@ describe('Wallet Operations', function() {
it('should register wallet', function(done) {
utils.registerWallet.call(utils, self.opts, function(err, res) {
utils.registerWallet(self.opts, function(err, res) {
if (err) {
return done(err);
@ -144,24 +144,23 @@ describe('Wallet Operations', function() {
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) {
//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) {
return done(err);
}
utils.waitForBitcoreNode.call(utils, self.opts, function(err) {
utils.waitForBitcoreNode(self.opts, function(err) {
if(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) {
async.series([
utils.startBitcoind.bind(utils, self.opts),
utils.waitForBitcoinReady.bind(utils, self.opts),
utils.unlockWallet.bind(utils, self.opts),
utils.setupInitialTxs.bind(utils, self.opts),
utils.sendTxs.bind(utils, self.opts),
utils.startBitcoreNode.bind(utils, self.opts),
utils.waitForBitcoreNode.bind(utils, self.opts),
utils.registerWallet.bind(utils, self.opts),
utils.uploadWallet.bind(utils, self.opts)
], done);
});
// before(function(done) {
// async.series([
// utils.startBitcoind.bind(utils, self.opts),
// utils.waitForBitcoinReady.bind(utils, self.opts),
// utils.unlockWallet.bind(utils, self.opts),
// utils.setupInitialTxs.bind(utils, self.opts),
// utils.sendTxs.bind(utils, self.opts),
// utils.startBitcoreNode.bind(utils, self.opts),
// utils.waitForBitcoreNode.bind(utils, self.opts),
// utils.registerWallet.bind(utils, self.opts),
// utils.uploadWallet.bind(utils, self.opts)
// ], 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,
self.opts,
{ path: '/wallet-api/wallets/' + self.opts.walletId + '/balance' });
// utils.queryBitcoreNode(httpOpts, function(err, res) {
// if(err) {
// return done(err);
// }
// 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,
self.opts,
{ path: '/wallet-api/wallets/' + opts.walletId + '/utxos' });
// utils.queryBitcoreNode(httpOpts, function(err, res) {
utils.queryBitcoreNode.call(utils, httpOpts, function(err, res) {
// if(err) {
// return done(err);
// }
if(err) {
return done(err);
}
// var results = JSON.parse(res);
// var balance = 0;
var results = JSON.parse(res);
var balance = 0;
// results.utxos.forEach(function(utxo) {
// balance += utxo.satoshis;
// });
results.utxos.forEach(function(utxo) {
balance += utxo.satoshis;
});
// results.height.should.equal(self.opts.blockHeight);
// balance.should.equal(self.opts.satoshisReceived);
// done();
// });
// });
results.height.should.equal(self.opts.blockHeight);
balance.should.equal(self.opts.satoshisReceived);
done();
});
});
// it('should get the list of jobs', function(done) {
// var httpOpts = utils.getHttpOpts(self.opts, { path: '/wallet-api/jobs' });
// 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) {
var httpOpts = utils.getHttpOpts.call(utils, self.opts, { path: '/wallet-api/jobs' });
utils.queryBitcoreNode.call(utils, httpOpts, function(err, res) {
if(err) {
return done(err);
}
var results = JSON.parse(res);
results.jobCount.should.equal(1);
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();
});
});
});
// it('should remove all wallets', function(done) {
// var httpOpts = utils.getHttpOpts(self.opts, { path: '/wallet-api/wallets', method: 'DELETE' });
// utils.queryBitcoreNode(httpOpts, function(err, res) {
// if(err) {
// return done(err);
// }
// var results = JSON.parse(res);
// results.numberRemoved.should.equal(152);
// done();
// });
// });
//});
});