Browse Source

implement check

activeAddress
Ivan Socolsky 9 years ago
parent
commit
4575262513
  1. 29
      lib/storage.js

29
lib/storage.js

@ -385,13 +385,32 @@ Storage.prototype.fetchAddresses = function(walletId, cb) {
Storage.prototype.storeAddressAndWallet = function(wallet, addresses, cb) {
var self = this;
var addresses = [].concat(addresses);
if (addresses.length == 0) return cb();
this.db.collection(collections.ADDRESSES).insert(addresses, {
w: 1
}, function(err) {
if (err) return cb(err);
self.storeWallet(wallet, cb);
async.filter(addresses, function(address, next) {
self.db.collection(collections.ADDRESSES).findOne({
address: address.address,
}, {
walletId: true,
}, function(err, result) {
if (err || !result) return next(true);
if (result.walletId != wallet.id) {
log.warn('Address ' + address.address + ' exists in more than one wallet.');
return next(true);
}
// Ignore if address was already in wallet
return next(false);
});
}, function(newAddresses) {
if (newAddresses.length == 0) return cb();
self.db.collection(collections.ADDRESSES).insert(newAddresses, {
w: 1
}, function(err) {
if (err) return cb(err);
self.storeWallet(wallet, cb);
});
});
};

Loading…
Cancel
Save