wallet: account cache + locking issue.
This commit is contained in:
parent
d77215009f
commit
3cef641780
@ -245,6 +245,9 @@ Account.prototype.open = function open() {
|
||||
if (!this.initialized)
|
||||
return Promise.resolve(null);
|
||||
|
||||
if (this.receive)
|
||||
return Promise.resolve(null);
|
||||
|
||||
this.receive = this.deriveReceive(this.receiveDepth - 1);
|
||||
this.change = this.deriveChange(this.changeDepth - 1);
|
||||
|
||||
|
||||
@ -64,6 +64,7 @@ function Wallet(db, options) {
|
||||
this.db = db;
|
||||
this.network = db.network;
|
||||
this.logger = db.logger;
|
||||
this.readLock = new Locker.Mapped();
|
||||
this.writeLock = new Locker();
|
||||
this.fundLock = new Locker();
|
||||
|
||||
@ -745,14 +746,35 @@ Wallet.prototype.getAddressHashes = function getAddressHashes() {
|
||||
*/
|
||||
|
||||
Wallet.prototype.getAccount = co(function* getAccount(acct) {
|
||||
var account;
|
||||
var index, unlock;
|
||||
|
||||
if (this.account) {
|
||||
if (acct === 0 || acct === 'default')
|
||||
return this.account;
|
||||
}
|
||||
|
||||
account = yield this.db.getAccount(this.wid, acct);
|
||||
index = yield this.db.getAccountIndex(this.wid, acct);
|
||||
|
||||
if (index === -1)
|
||||
return;
|
||||
|
||||
unlock = yield this.readLock.lock(index);
|
||||
|
||||
try {
|
||||
return yield this._getAccount(index);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieve an account from the database without a lock.
|
||||
* @param {Number} index
|
||||
* @returns {Promise} - Returns {@link Account}.
|
||||
*/
|
||||
|
||||
Wallet.prototype._getAccount = co(function* _getAccount(index) {
|
||||
var account = yield this.db.getAccount(this.wid, index);
|
||||
|
||||
if (!account)
|
||||
return;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user