|
|
@ -39,11 +39,8 @@ var KEY = { |
|
|
|
TXP: function(walletId, txProposalId) { |
|
|
|
return 'txp!' + walletId + opKey(txProposalId); |
|
|
|
}, |
|
|
|
TXP_BY_TS: function(walletId, ts, txProposalId) { |
|
|
|
return 'txp-ts!' + walletId + opKeyTs(ts) + opKey(txProposalId); |
|
|
|
}, |
|
|
|
PENDING_TXP_BY_TS: function(walletId, ts, txProposalId) { |
|
|
|
return 'pending-txp-ts!' + walletId + opKey(ts) + opKey(txProposalId); |
|
|
|
PENDING_TXP: function(walletId, txProposalId) { |
|
|
|
return 'pending-txp-ts!' + walletId + opKey(txProposalId); |
|
|
|
}, |
|
|
|
ADDRESS: function(walletId, address) { |
|
|
|
return 'address!' + walletId + opKey(address); |
|
|
@ -107,7 +104,7 @@ Storage.prototype.fetchTx = function(walletId, txProposalId, cb) { |
|
|
|
|
|
|
|
Storage.prototype.fetchPendingTxs = function(walletId, cb) { |
|
|
|
var txs = []; |
|
|
|
var key = KEY.PENDING_TXP_BY_TS(walletId); |
|
|
|
var key = KEY.PENDING_TXP(walletId); |
|
|
|
this.db.createReadStream({ |
|
|
|
gte: key, |
|
|
|
lt: key + '~' |
|
|
@ -135,12 +132,12 @@ Storage.prototype.fetchPendingTxs = function(walletId, cb) { |
|
|
|
Storage.prototype.fetchTxs = function(walletId, opts, cb) { |
|
|
|
var txs = []; |
|
|
|
opts = opts || {}; |
|
|
|
opts.limit = opts.limit || -1; |
|
|
|
opts.minTs = opts.minTs || 0; |
|
|
|
opts.maxTs = opts.maxTs || MAX_TS; |
|
|
|
opts.limit = _.isNumber(opts.limit) ? parseInt(opts.limit) : -1; |
|
|
|
opts.minTs = _.isNumber(opts.minTs) ? ('000000000000' + parseInt(opts.minTs)).slice(-12) : 0; |
|
|
|
opts.maxTs = _.isNumber(opts.maxTs) ? ('000000000000' + parseInt(opts.maxTs)).slice(-12) : MAX_TS; |
|
|
|
|
|
|
|
var key = KEY.TXP_BY_TS(walletId, opts.minTs); |
|
|
|
var endkey = KEY.TXP_BY_TS(walletId, opts.maxTs); |
|
|
|
var key = KEY.TXP(walletId, opts.minTs); |
|
|
|
var endkey = KEY.TXP(walletId, opts.maxTs); |
|
|
|
|
|
|
|
this.db.createReadStream({ |
|
|
|
gt: key, |
|
|
@ -168,22 +165,18 @@ Storage.prototype.storeTx = function(walletId, txp, cb) { |
|
|
|
type: 'put', |
|
|
|
key: KEY.TXP(walletId, txp.id), |
|
|
|
value: txp, |
|
|
|
}, { |
|
|
|
type: 'put', |
|
|
|
key: KEY.TXP_BY_TS(walletId, txp.createdOn, txp.id), |
|
|
|
value: txp, |
|
|
|
}]; |
|
|
|
|
|
|
|
if (txp.isPending()) { |
|
|
|
ops.push({ |
|
|
|
type: 'put', |
|
|
|
key: KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id), |
|
|
|
key: KEY.PENDING_TXP(walletId, txp.id), |
|
|
|
value: txp, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
ops.push({ |
|
|
|
type: 'del', |
|
|
|
key: KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id), |
|
|
|
key: KEY.PENDING_TXP(walletId, txp.id), |
|
|
|
}); |
|
|
|
} |
|
|
|
this.db.batch(ops, cb); |
|
|
|