Browse Source
avoid storing empty collection
feat/estimateFee-limit
Ivan Socolsky
8 years ago
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
1 changed files with
8 additions and
3 deletions
-
lib/storage.js
|
|
@ -463,6 +463,13 @@ Storage.prototype.storeAddress = function(address, cb) { |
|
|
|
Storage.prototype.storeAddressAndWallet = function(wallet, addresses, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
function saveAddresses(addresses, cb) { |
|
|
|
if (_.isEmpty(addresses)) return cb(); |
|
|
|
self.db.collection(collections.ADDRESSES).insert(addresses, { |
|
|
|
w: 1 |
|
|
|
}, cb); |
|
|
|
}; |
|
|
|
|
|
|
|
var addresses = [].concat(addresses); |
|
|
|
if (addresses.length == 0) return cb(); |
|
|
|
|
|
|
@ -484,9 +491,7 @@ Storage.prototype.storeAddressAndWallet = function(wallet, addresses, cb) { |
|
|
|
if (newAddresses.length < addresses.length) { |
|
|
|
log.warn('Attempted to store already existing addresses on wallet ' + wallet.id); |
|
|
|
} |
|
|
|
self.db.collection(collections.ADDRESSES).insert(newAddresses, { |
|
|
|
w: 1 |
|
|
|
}, function(err) { |
|
|
|
saveAddresses(newAddresses, function(err) { |
|
|
|
if (err) return cb(err); |
|
|
|
self.storeWallet(wallet, cb); |
|
|
|
}); |
|
|
|