implement check
This commit is contained in:
parent
63a7e47543
commit
4575262513
|
@ -385,14 +385,33 @@ Storage.prototype.fetchAddresses = function(walletId, cb) {
|
||||||
|
|
||||||
Storage.prototype.storeAddressAndWallet = function(wallet, addresses, cb) {
|
Storage.prototype.storeAddressAndWallet = function(wallet, addresses, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var addresses = [].concat(addresses);
|
var addresses = [].concat(addresses);
|
||||||
if (addresses.length == 0) return cb();
|
if (addresses.length == 0) return cb();
|
||||||
this.db.collection(collections.ADDRESSES).insert(addresses, {
|
|
||||||
|
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
|
w: 1
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
self.storeWallet(wallet, cb);
|
self.storeWallet(wallet, cb);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Storage.prototype.fetchAddress = function(address, cb) {
|
Storage.prototype.fetchAddress = function(address, cb) {
|
||||||
|
|
Loading…
Reference in New Issue