sample server
This commit is contained in:
parent
7a8a7ea997
commit
1bbdd4c14c
17
lib/lock.js
17
lib/lock.js
|
@ -1,10 +1,25 @@
|
|||
var $ = require('preconditions').singleton();
|
||||
var _ = require('lodash');
|
||||
var log = require('npmlog');
|
||||
log.debug = log.verbose;
|
||||
|
||||
var LocalLock = require('./locallock');
|
||||
var RemoteLock = require('locker');
|
||||
|
||||
function Lock(opts) {
|
||||
this.lock = new LocalLock();
|
||||
opts = opts || {};
|
||||
if (opts.lockerServer) {
|
||||
this.lock = new RemoteLock(opts.lockerServer.port, opts.lockerServer.host);
|
||||
|
||||
this.lock.on('reset', function() {
|
||||
log.debug('Locker server reset');
|
||||
});
|
||||
this.lock.on('error', function(error) {
|
||||
log.error('Locker server threw error', error);
|
||||
});
|
||||
} else {
|
||||
this.lock = new LocalLock();
|
||||
}
|
||||
};
|
||||
|
||||
Lock.prototype.runLocked = function(token, cb, task) {
|
||||
|
|
|
@ -147,9 +147,9 @@ Storage.prototype.fetchPendingTxs = function(walletId, cb) {
|
|||
var txs = [];
|
||||
var key = KEY.PENDING_TXP(walletId);
|
||||
this.db.createReadStream({
|
||||
gte: key,
|
||||
lt: key + '~'
|
||||
})
|
||||
gte: key,
|
||||
lt: key + '~'
|
||||
})
|
||||
.on('data', function(data) {
|
||||
txs.push(TxProposal.fromObj(data.value));
|
||||
})
|
||||
|
@ -183,11 +183,11 @@ Storage.prototype.fetchTxs = function(walletId, opts, cb) {
|
|||
var endkey = KEY.TXP(walletId, opts.maxTs);
|
||||
|
||||
this.db.createReadStream({
|
||||
gt: key,
|
||||
lt: endkey + '~',
|
||||
reverse: true,
|
||||
limit: opts.limit,
|
||||
})
|
||||
gt: key,
|
||||
lt: endkey + '~',
|
||||
reverse: true,
|
||||
limit: opts.limit,
|
||||
})
|
||||
.on('data', function(data) {
|
||||
txs.push(TxProposal.fromObj(data.value));
|
||||
})
|
||||
|
@ -220,11 +220,11 @@ Storage.prototype.fetchNotifications = function(walletId, opts, cb) {
|
|||
var endkey = KEY.NOTIFICATION(walletId, opts.maxTs);
|
||||
|
||||
this.db.createReadStream({
|
||||
gt: key,
|
||||
lt: endkey + '~',
|
||||
reverse: opts.reverse,
|
||||
limit: opts.limit,
|
||||
})
|
||||
gt: key,
|
||||
lt: endkey + '~',
|
||||
reverse: opts.reverse,
|
||||
limit: opts.limit,
|
||||
})
|
||||
.on('data', function(data) {
|
||||
txs.push(Notification.fromObj(data.value));
|
||||
})
|
||||
|
@ -284,9 +284,9 @@ Storage.prototype._delByKey = function(key, cb) {
|
|||
var self = this;
|
||||
var keys = [];
|
||||
this.db.createKeyStream({
|
||||
gte: key,
|
||||
lt: key + '~',
|
||||
})
|
||||
gte: key,
|
||||
lt: key + '~',
|
||||
})
|
||||
.on('data', function(key) {
|
||||
keys.push(key);
|
||||
})
|
||||
|
@ -341,9 +341,9 @@ Storage.prototype.fetchAddresses = function(walletId, cb) {
|
|||
var addresses = [];
|
||||
var key = KEY.ADDRESS(walletId);
|
||||
this.db.createReadStream({
|
||||
gte: key,
|
||||
lt: key + '~'
|
||||
})
|
||||
gte: key,
|
||||
lt: key + '~'
|
||||
})
|
||||
.on('data', function(data) {
|
||||
addresses.push(Address.fromObj(data.value));
|
||||
})
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
(function() {
|
||||
var Locker = require('locker-server'),
|
||||
locker = new Locker();
|
||||
|
||||
locker.listen(3003);
|
||||
})();
|
|
@ -29,6 +29,7 @@
|
|||
"leveldown": "^0.10.0",
|
||||
"levelup": "^0.19.0",
|
||||
"locker": "^0.1.0",
|
||||
"locker-server": "^0.1.3",
|
||||
"lodash": "^3.3.1",
|
||||
"mocha-lcov-reporter": "0.0.1",
|
||||
"morgan": "*",
|
||||
|
|
Loading…
Reference in New Issue