wallet: improve ensureAccount.
This commit is contained in:
parent
c866598e85
commit
ac483eaedd
@ -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;
|
||||
|
||||
@ -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;
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user