From 0788da0e45e313a7a396277f046514e7052dfabe Mon Sep 17 00:00:00 2001 From: k Date: Mon, 24 Apr 2017 13:44:08 -0400 Subject: [PATCH] wip new routes. --- lib/services/address/index.js | 4 ++-- lib/services/db/index.js | 3 +++ lib/services/wallet-api/index.js | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/services/address/index.js b/lib/services/address/index.js index f78f3c16..7a85d366 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -1171,8 +1171,8 @@ AddressService.prototype.getAddressTxidsWithHeights = function(address, options, var opts = options || {}; var txids = {}; - var start = self._encoding.encodeAddressIndexKey(address, opts.start || 0, '00'); - var end = self._encoding.encodeAddressIndexKey(address, opts.end || 0xffffffff); + var start = self._encoding.encodeAddressIndexKey(address, opts.start || 0); //the start and end must be the same length + var end = Buffer.concat([ start.slice(0, -36), new Buffer((opts.end || 0xffffffff), 'hex') ]); var stream = self.store.createKeyStream({ gte: start, diff --git a/lib/services/db/index.js b/lib/services/db/index.js index bdcf3c8c..59eba422 100644 --- a/lib/services/db/index.js +++ b/lib/services/db/index.js @@ -62,6 +62,7 @@ function DB(options) { }; this._sync = new Sync(this.node, this); + this.syncing = true; } util.inherits(DB, Service); @@ -132,6 +133,7 @@ DB.prototype.start = function(callback) { self.store = levelup(self.dataPath, { db: self.levelupStore, keyEncoding: 'binary', valueEncoding: 'binary'}); self._sync.on('error', function(err) { + self.syncing = false; log.error(err); }); @@ -160,6 +162,7 @@ DB.prototype.start = function(callback) { }); self._sync.on('synced', function() { + self.syncing = false; log.info('Initial sync complete'); }); diff --git a/lib/services/wallet-api/index.js b/lib/services/wallet-api/index.js index 8bb237b2..3c632961 100644 --- a/lib/services/wallet-api/index.js +++ b/lib/services/wallet-api/index.js @@ -566,12 +566,10 @@ WalletService.prototype._endpointPostAddresses = function() { if (!addresses || !addresses.length) { return utils.sendError(new Error('addresses are required when creating a wallet.'), res); } - var walletId = req.params.walletId; //also can't be zero + var walletId = req.params.walletId; if (!walletId) { return utils.sendError(new Error('WalletId must be given.'), res); } - // TODO make imdempotent - //this could be a long-running operation, so we'll return a job id if (!self._isJobQueueReady()) { return utils.sendError(new Error('Job queue is currently overloaded, please try again later.'), res); } @@ -1125,6 +1123,16 @@ WalletService.prototype._endpointJobs = function() { }; +WalletService.prototype._endpointIsSynced = function() { + var self = this; + + return function(req, res) { + + res.status(200).jsonp({ result: !self.node.services.db.syncing }); + + }; +}; + WalletService.prototype._endpointJobStatus = function() { var self = this; @@ -1195,6 +1203,9 @@ WalletService.prototype.setupRoutes = function(app) { app.get('/jobs', s._endpointJobs() ); + app.get('/issynced', + s._endpointIsSynced() + ); }; WalletService.prototype.getRoutePrefix = function() {