|
@ -3,7 +3,6 @@ |
|
|
var _ = require('lodash'); |
|
|
var _ = require('lodash'); |
|
|
var levelup = require('levelup'); |
|
|
var levelup = require('levelup'); |
|
|
var $ = require('preconditions').singleton(); |
|
|
var $ = require('preconditions').singleton(); |
|
|
var async = require('async'); |
|
|
|
|
|
var log = require('npmlog'); |
|
|
var log = require('npmlog'); |
|
|
log.debug = log.verbose; |
|
|
log.debug = log.verbose; |
|
|
|
|
|
|
|
@ -145,23 +144,29 @@ Storage.prototype.fetchTxs = function(walletId, cb) { |
|
|
// or the whole txp? For now, the entire record makes sense
|
|
|
// or the whole txp? For now, the entire record makes sense
|
|
|
// (faster + easier to access)
|
|
|
// (faster + easier to access)
|
|
|
Storage.prototype.storeTx = function(walletId, txp, cb) { |
|
|
Storage.prototype.storeTx = function(walletId, txp, cb) { |
|
|
var self = this; |
|
|
var ops = [{ |
|
|
|
|
|
type: 'put', |
|
|
async.series([ |
|
|
key: KEY.TXP(walletId, txp.id), |
|
|
|
|
|
value: txp, |
|
|
|
|
|
}, { |
|
|
|
|
|
type: 'put', |
|
|
|
|
|
key: KEY.TXP_BY_TS(walletId, txp.createdOn, txp.id), |
|
|
|
|
|
value: txp, |
|
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
function(next) { |
|
|
if (txp.isPending()) { |
|
|
self.db.put(KEY.TXP(walletId, txp.id), txp, next); |
|
|
ops.push({ |
|
|
}, |
|
|
type: 'put', |
|
|
function(next) { |
|
|
key: KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id), |
|
|
self.db.put(KEY.TXP_BY_TS(walletId, txp.createdOn, txp.id), txp, next); |
|
|
value: txp, |
|
|
}, |
|
|
}); |
|
|
function(next) { |
|
|
} else { |
|
|
if (txp.isPending()) |
|
|
ops.push({ |
|
|
self.db.put(KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id), txp, next); |
|
|
type: 'del', |
|
|
else |
|
|
key: KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id), |
|
|
self.db.del(KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id), next); |
|
|
}); |
|
|
} |
|
|
} |
|
|
], cb); |
|
|
this.db.batch(ops, cb); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Storage.prototype.fetchAddresses = function(walletId, cb) { |
|
|
Storage.prototype.fetchAddresses = function(walletId, cb) { |
|
@ -184,11 +189,11 @@ Storage.prototype.fetchAddresses = function(walletId, cb) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Storage.prototype.storeAddress = function(walletId, address, cb) { |
|
|
Storage.prototype.storeAddress = function(walletId, address, cb) { |
|
|
this.db.put(KEY.ADDRESS(walletId,address.address), address, cb); |
|
|
this.db.put(KEY.ADDRESS(walletId, address.address), address, cb); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Storage.prototype.removeAddress = function(walletId, address, cb) { |
|
|
Storage.prototype.removeAddress = function(walletId, address, cb) { |
|
|
this.db.del(KEY.ADDRESS(walletId,address.address), cb); |
|
|
this.db.del(KEY.ADDRESS(walletId, address.address), cb); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|