dont save wallet until it has an id.
This commit is contained in:
parent
c8f5913477
commit
8d8952add7
@ -105,6 +105,8 @@ Wallet.prototype._init = function _init() {
|
|||||||
|
|
||||||
this.id = this.getID();
|
this.id = this.getID();
|
||||||
|
|
||||||
|
this.emit('init');
|
||||||
|
|
||||||
if (Object.keys(this.addressMap).length === 0) {
|
if (Object.keys(this.addressMap).length === 0) {
|
||||||
for (i = 0; i < this.receiveDepth - 1; i++)
|
for (i = 0; i < this.receiveDepth - 1; i++)
|
||||||
this.deriveReceive(i);
|
this.deriveReceive(i);
|
||||||
@ -127,6 +129,12 @@ Wallet.prototype._init = function _init() {
|
|||||||
assert(this.changeAddress.change);
|
assert(this.changeAddress.change);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.onInit = function onInit(callback) {
|
||||||
|
if (this._initialized)
|
||||||
|
return callback();
|
||||||
|
this.once('init', callback);
|
||||||
|
};
|
||||||
|
|
||||||
Wallet.prototype.addKey = function addKey(key) {
|
Wallet.prototype.addKey = function addKey(key) {
|
||||||
var has, i;
|
var has, i;
|
||||||
|
|
||||||
|
|||||||
@ -291,11 +291,18 @@ WalletDB.prototype.save = function save(options, callback) {
|
|||||||
options.on('add address', self._onAddress(options, options.id));
|
options.on('add address', self._onAddress(options, options.id));
|
||||||
options.provider = self;
|
options.provider = self;
|
||||||
}
|
}
|
||||||
if (options instanceof bcoin.wallet)
|
options.onInit(function() {
|
||||||
options = options.toJSON();
|
if (options instanceof bcoin.wallet)
|
||||||
|
options = options.toJSON();
|
||||||
|
self.saveJSON(options.id, options, function(err) {
|
||||||
|
if (err)
|
||||||
|
self.emit('error', err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return callback(null, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.saveJSON(options.id, options, callback);
|
this.saveJSON(options.id, options, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.remove = function remove(id, callback) {
|
WalletDB.prototype.remove = function remove(id, callback) {
|
||||||
@ -346,7 +353,13 @@ WalletDB.prototype.create = function create(options, callback) {
|
|||||||
} else {
|
} else {
|
||||||
options.provider = self;
|
options.provider = self;
|
||||||
wallet = new bcoin.wallet(options);
|
wallet = new bcoin.wallet(options);
|
||||||
self.saveJSON(wallet.id, wallet.toJSON(), done);
|
wallet.onInit(function() {
|
||||||
|
self.saveJSON(wallet.id, wallet.toJSON(), function(err) {
|
||||||
|
if (err)
|
||||||
|
self.emit('error', err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return done();
|
||||||
}
|
}
|
||||||
|
|
||||||
function done(err) {
|
function done(err) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user