rpc: sort txs and coins.

This commit is contained in:
Christopher Jeffrey 2016-10-05 05:41:00 -07:00
parent 80aa8f8c4c
commit 80b6968318
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -2381,7 +2381,7 @@ RPC.prototype._createRedeem = co(function* _createRedeem(args) {
if (!hash)
throw new RPCError('Invalid key.');
ring = yield this.node.wallet.getKey(hash);
ring = yield this.wallet.getKey(hash);
if (!ring)
throw new RPCError('Invalid key.');
@ -2468,14 +2468,14 @@ RPC.prototype.validateaddress = co(function* validateaddress(args) {
};
}
path = yield this.wallet.getPath(address.getHash('hex'));
path = yield this.wallet.getPath(address);
json = {
isvalid: true,
address: address.toBase58(this.network),
scriptPubKey: address.toScript().toJSON(),
ismine: path ? true : false,
iswatchonly: false
iswatchonly: path ? this.wallet.watchOnly : false
};
if (!path)
@ -3408,7 +3408,7 @@ RPC.prototype._listReceived = co(function* _listReceived(minconf, empty, account
for (i = 0; i < paths.length; i++) {
path = paths[i];
map[path.hash] = {
involvesWatchonly: false,
involvesWatchonly: this.wallet.watchOnly,
address: path.toAddress().toBase58(this.network),
account: path.name,
amount: 0,
@ -3646,6 +3646,8 @@ RPC.prototype.listtransactions = co(function* listtransactions(args) {
txs = yield this.wallet.getHistory();
sortTX(txs);
for (i = 0; i < txs.length; i++) {
tx = txs[i];
json = yield this._toListTX(tx);
@ -3693,6 +3695,8 @@ RPC.prototype.listunspent = co(function* listunspent(args) {
coins = yield this.wallet.getCoins();
sortCoins(coins);
for (i = 0; i < coins.length; i++ ) {
coin = coins[i];
@ -4185,6 +4189,20 @@ function readFile(file, enc) {
});
}
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;
});
}
/*
* Expose
*/