|
|
@ -105,30 +105,45 @@ Storage.prototype.fetchCopayerLookup = function(copayerId, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype.fetchTx = function(walletId, txProposalId, cb) { |
|
|
|
this.db.get(KEY.TXP(walletId, txProposalId), function(err, data) { |
|
|
|
Storage.prototype.fetchNotification = function(walletId, notificationId, cb) { |
|
|
|
this.db.get(KEY.NOTIFICATION(walletId, notificationId), function(err, data) { |
|
|
|
if (err) { |
|
|
|
if (err.notFound) return cb(); |
|
|
|
return cb(err); |
|
|
|
} |
|
|
|
return cb(null, TxProposal.fromObj(data)); |
|
|
|
return cb(null, Notification.fromObj(data)); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype._completeTxData = function(walletId, txs, cb) { |
|
|
|
var txList = [].concat(txs); |
|
|
|
this.fetchWallet(walletId, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
_.each(txList, function(tx) { |
|
|
|
tx.creatorName = wallet.getCopayer(tx.creatorId).name; |
|
|
|
_.each(_.values(tx.actions), function(action) { |
|
|
|
action.copayerName = wallet.getCopayer(action.copayerId).name; |
|
|
|
}); |
|
|
|
}); |
|
|
|
return cb(null, txs); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype.fetchNotification = function(walletId, notificationId, cb) { |
|
|
|
this.db.get(KEY.NOTIFICATION(walletId, notificationId), function(err, data) { |
|
|
|
Storage.prototype.fetchTx = function(walletId, txProposalId, cb) { |
|
|
|
var self = this; |
|
|
|
this.db.get(KEY.TXP(walletId, txProposalId), function(err, data) { |
|
|
|
if (err) { |
|
|
|
if (err.notFound) return cb(); |
|
|
|
return cb(err); |
|
|
|
} |
|
|
|
return cb(null, Notification.fromObj(data)); |
|
|
|
return self._completeTxData(walletId, TxProposal.fromObj(data), cb); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Storage.prototype.fetchPendingTxs = function(walletId, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var txs = []; |
|
|
|
var key = KEY.PENDING_TXP(walletId); |
|
|
|
this.db.createReadStream({ |
|
|
@ -143,7 +158,7 @@ Storage.prototype.fetchPendingTxs = function(walletId, cb) { |
|
|
|
return cb(err); |
|
|
|
}) |
|
|
|
.on('end', function() { |
|
|
|
return cb(null, txs); |
|
|
|
return self._completeTxData(walletId, txs, cb); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
@ -156,6 +171,8 @@ Storage.prototype.fetchPendingTxs = function(walletId, cb) { |
|
|
|
* @param opts.limit |
|
|
|
*/ |
|
|
|
Storage.prototype.fetchTxs = function(walletId, opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var txs = []; |
|
|
|
opts = opts || {}; |
|
|
|
opts.limit = _.isNumber(opts.limit) ? parseInt(opts.limit) : -1; |
|
|
@ -179,7 +196,7 @@ Storage.prototype.fetchTxs = function(walletId, opts, cb) { |
|
|
|
return cb(err); |
|
|
|
}) |
|
|
|
.on('end', function() { |
|
|
|
return cb(null, txs); |
|
|
|
return self._completeTxData(walletId, txs, cb); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|