|
|
@ -775,20 +775,15 @@ WalletService.prototype.createAddress = function(opts, cb) { |
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
function createNewAddress(wallet, cb) { |
|
|
|
self._canCreateAddress(opts.ignoreMaxGap, function(err, canCreate) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!canCreate) return cb(Errors.MAIN_ADDRESS_GAP_REACHED); |
|
|
|
|
|
|
|
var address = wallet.createAddress(false); |
|
|
|
var address = wallet.createAddress(false); |
|
|
|
|
|
|
|
self.storage.storeAddressAndWallet(wallet, address, function(err) { |
|
|
|
if (err) return cb(err); |
|
|
|
self.storage.storeAddressAndWallet(wallet, address, function(err) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
self._notify('NewAddress', { |
|
|
|
address: address.address, |
|
|
|
}, function() { |
|
|
|
return cb(null, address); |
|
|
|
}); |
|
|
|
self._notify('NewAddress', { |
|
|
|
address: address.address, |
|
|
|
}, function() { |
|
|
|
return cb(null, address); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -801,13 +796,18 @@ WalletService.prototype.createAddress = function(opts, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
self._runLocked(cb, function(cb) { |
|
|
|
self.getWallet({}, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!wallet.isComplete()) return cb(Errors.WALLET_NOT_COMPLETE); |
|
|
|
self._canCreateAddress(opts.ignoreMaxGap, function(err, canCreate) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!canCreate) return cb(Errors.MAIN_ADDRESS_GAP_REACHED); |
|
|
|
|
|
|
|
var createFn = wallet.singleAddress ? getFirstAddress : createNewAddress; |
|
|
|
return createFn(wallet, cb); |
|
|
|
self._runLocked(cb, function(cb) { |
|
|
|
self.getWallet({}, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!wallet.isComplete()) return cb(Errors.WALLET_NOT_COMPLETE); |
|
|
|
|
|
|
|
var createFn = wallet.singleAddress ? getFirstAddress : createNewAddress; |
|
|
|
return createFn(wallet, cb); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|