Browse Source

delete txp and wallet

activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
db1d1dd463
  1. 88
      lib/storage.js

88
lib/storage.js

@ -182,6 +182,94 @@ Storage.prototype.storeTx = function(walletId, txp, cb) {
this.db.batch(ops, cb); this.db.batch(ops, cb);
}; };
Storage.prototype.removeTx = function(walletId, txProposalId, cb) {
var ops = [{
type: 'del',
key: KEY.TXP(walletId, txp.id),
}, {
type: 'del',
key: KEY.PENDING_TXP(walletId, txp.id),
value: txp,
}];
this.db.batch(ops, cb);
};
Storage.prototype.removeAllPendingTxs = function(walletId, cb) {
var key = KEY.PENDING_TXP(walletId);
this.db.createWriteStream({
gt: key,
lt: key + '~',
})
.on('error', function(err) {
if (err.notFound) return cb();
return cb(err);
})
.on('end', function() {
return cb(null);
});
};
Storage.prototype.removeAllTxs = function(walletId, cb) {
var key = KEY.TXP(walletId);
this.db.createWriteStream({
gt: key,
lt: key + '~',
})
.on('error', function(err) {
if (err.notFound) return cb();
return cb(err);
})
.on('end', function() {
return cb(null);
});
};
Storage.prototype._removeAllAddresses = function(walletId, cb) {
var key = KEY.ADDRESS(walletId);
this.db.createWriteStream({
gte: key,
lt: key + '~',
type: 'del',
})
.on('error', function(err) {
if (err.notFound) return cb();
return cb(err);
})
.on('end', function() {
return cb(null);
});
};
Storage.prototype.removeWallet = function(walletId, cb) {
var self = this;
async.series([
function(next) {
self._removeAllAddresses(walletId, next);
},
function(next) {
self.removeAllPendingTxs(walletId, next);
},
function(next) {
self.removeAllTxs(walletId, next);
},
function(next) {
var ops = [{
type: 'del',
key: KEY.WALLET(walletId),
}];
self.db.batch(ops, next);
},
], 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);

Loading…
Cancel
Save