From 80b69683189ea4a11f445e48e3e1322f2917059c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 5 Oct 2016 05:41:00 -0700 Subject: [PATCH] rpc: sort txs and coins. --- lib/http/rpc.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index b053c03a..f36de44d 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -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 */