wallet: improve ensureAccount.

This commit is contained in:
Christopher Jeffrey 2016-10-05 02:21:42 -07:00
parent c866598e85
commit ac483eaedd
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 8 additions and 22 deletions

View File

@ -1484,7 +1484,7 @@ TXDB.prototype.getLast = function getLast(account, limit) {
start: 0,
end: 0xffffffff,
reverse: true,
limit: limit
limit: limit || 10
});
};
@ -1529,7 +1529,7 @@ TXDB.prototype.getAccountHistory = co(function* getAccountHistory(account) {
txs.push(tx);
}
return sortTX(txs);
return txs;
});
/**
@ -1554,7 +1554,7 @@ TXDB.prototype.getUnconfirmed = co(function* getUnconfirmed(account) {
txs.push(tx);
}
return sortTX(txs);
return txs;
});
/**
@ -2038,20 +2038,6 @@ Balance.prototype.toString = function toString() {
* Helpers
*/
function sortTX(txs) {
return txs.sort(function(a, b) {
return a.ps - b.ps;
});
}
function sortCoins(coins) {
return coins.sort(function(a, b) {
a = a.height === -1 ? 0x7fffffff : a.height;
b = b.height === -1 ? 0x7fffffff : b.height;
return a - b;
});
}
function Conflict(tx, info) {
this.tx = tx;
this.info = info;

View File

@ -753,17 +753,17 @@ Wallet.prototype._createAccount = co(function* createAccount(options) {
Wallet.prototype.ensureAccount = co(function* ensureAccount(options) {
var name = options.account;
var exists;
var account;
if (typeof options.name === 'string')
name = options.name;
exists = yield this.hasAccount(name);
account = yield this.getAccount(name);
if (exists)
return yield this.getAccount(name);
if (!account)
return yield this.createAccount(options);
return this.createAccount(options);
return account;
});
/**