|
@ -20,6 +20,12 @@ var Storage = function(opts) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// WARN: Ts is supposed to have fixed with. Y33 problem :)
|
|
|
|
|
|
|
|
|
|
|
|
var opKey = function(key) { |
|
|
|
|
|
return key ? '!' + key : ''; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
var KEY = { |
|
|
var KEY = { |
|
|
WALLET: function(id) { |
|
|
WALLET: function(id) { |
|
|
return 'wallet::' + id; |
|
|
return 'wallet::' + id; |
|
@ -27,17 +33,17 @@ var KEY = { |
|
|
COPAYER: function(id) { |
|
|
COPAYER: function(id) { |
|
|
return 'copayer::' + id; |
|
|
return 'copayer::' + id; |
|
|
}, |
|
|
}, |
|
|
TXP_BY_ID: function(walletId, txProposalId) { |
|
|
TXP: function(walletId, txProposalId) { |
|
|
return 'txp::' + walletId + '::' + txProposalId; |
|
|
return 'txp!' + walletId + opKey(txProposalId); |
|
|
}, |
|
|
}, |
|
|
TXP_BY_TS: function(walletId, ts) { |
|
|
TXP_BY_TS: function(walletId, ts, txProposalId) { |
|
|
return 'txp-ts::' + walletId + '::' + ts.toFixed(12); |
|
|
return 'txp-ts!' + walletId + opKey(ts) + opKey(txProposalId); |
|
|
}, |
|
|
}, |
|
|
PENDING_TXP_BY_TS: function(walletId, ts) { |
|
|
PENDING_TXP_BY_TS: function(walletId, ts, txProposalId) { |
|
|
return 'pending-txp-ts::' + walletId + '::' + ts.toFixed(12); |
|
|
return 'pending-txp-ts!' + walletId + opKey(ts) + opKey(txProposalId); |
|
|
}, |
|
|
}, |
|
|
ADDRESS: function(walletId, address) { |
|
|
ADDRESS: function(walletId, address) { |
|
|
return 'address::' + walletId + '::' + address; |
|
|
return 'address!' + walletId + opKey(address); |
|
|
}, |
|
|
}, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -87,7 +93,7 @@ Storage.prototype.fetchCopayerLookup = function(copayerId, cb) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Storage.prototype.fetchTx = function(walletId, txProposalId, cb) { |
|
|
Storage.prototype.fetchTx = function(walletId, txProposalId, cb) { |
|
|
this.db.get(KEY.TXP_BY_ID(walletId, txProposalId), function(err, data) { |
|
|
this.db.get(KEY.TXP(walletId, txProposalId), function(err, data) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
if (err.notFound) return cb(); |
|
|
if (err.notFound) return cb(); |
|
|
return cb(err); |
|
|
return cb(err); |
|
@ -99,7 +105,7 @@ Storage.prototype.fetchTx = function(walletId, txProposalId, cb) { |
|
|
|
|
|
|
|
|
Storage.prototype.fetchPendingTxs = function(walletId, cb) { |
|
|
Storage.prototype.fetchPendingTxs = function(walletId, cb) { |
|
|
var txs = []; |
|
|
var txs = []; |
|
|
var key = KEY.PENDING_TXP_BY_TS(walletId,''); |
|
|
var key = KEY.PENDING_TXP_BY_TS(walletId); |
|
|
this.db.createReadStream({ |
|
|
this.db.createReadStream({ |
|
|
gte: key, |
|
|
gte: key, |
|
|
lt: key + '~' |
|
|
lt: key + '~' |
|
@ -118,7 +124,7 @@ Storage.prototype.fetchPendingTxs = function(walletId, cb) { |
|
|
|
|
|
|
|
|
Storage.prototype.fetchTxs = function(walletId, cb) { |
|
|
Storage.prototype.fetchTxs = function(walletId, cb) { |
|
|
var txs = []; |
|
|
var txs = []; |
|
|
var key = KEY.TXP_BY_ID(walletId,''); |
|
|
var key = KEY.TXP(walletId); |
|
|
this.db.createReadStream({ |
|
|
this.db.createReadStream({ |
|
|
gte: key, |
|
|
gte: key, |
|
|
lt: key + '~' |
|
|
lt: key + '~' |
|
@ -144,23 +150,23 @@ Storage.prototype.storeTx = function(walletId, txp, cb) { |
|
|
async.series([ |
|
|
async.series([ |
|
|
|
|
|
|
|
|
function(next) { |
|
|
function(next) { |
|
|
self.db.put(KEY.TXP_BY_ID(walletId, txp.id), txp, next); |
|
|
self.db.put(KEY.TXP(walletId, txp.id), txp, next); |
|
|
}, |
|
|
}, |
|
|
function(next) { |
|
|
function(next) { |
|
|
self.db.put(KEY.TXP_BY_TS(walletId, txp.createdOn), txp, next); |
|
|
self.db.put(KEY.TXP_BY_TS(walletId, txp.createdOn, txp.id), txp, next); |
|
|
}, |
|
|
}, |
|
|
function(next) { |
|
|
function(next) { |
|
|
if (txp.isPending()) |
|
|
if (txp.isPending()) |
|
|
self.db.put(KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn), txp, next); |
|
|
self.db.put(KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id), txp, next); |
|
|
else |
|
|
else |
|
|
self.db.del(KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn), next); |
|
|
self.db.del(KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id), next); |
|
|
} |
|
|
} |
|
|
], cb); |
|
|
], cb); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Storage.prototype.fetchAddresses = function(walletId, cb) { |
|
|
Storage.prototype.fetchAddresses = function(walletId, cb) { |
|
|
var addresses = []; |
|
|
var addresses = []; |
|
|
var key = KEY.ADDRESS(walletId,''); |
|
|
var key = KEY.ADDRESS(walletId); |
|
|
this.db.createReadStream({ |
|
|
this.db.createReadStream({ |
|
|
gte: key, |
|
|
gte: key, |
|
|
lt: key + '~' |
|
|
lt: key + '~' |
|
|