tsort coins by age in get_unspent_coins() - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 428fbf1f63a21295cae586336412e9df93fd66e3 DIR parent 36011fbaa4e7d0d71c0846e156362d92e3566a4b HTML Author: ThomasV <thomasv@gitorious> Date: Sun, 15 Sep 2013 23:37:40 +0200 sort coins by age in get_unspent_coins() Diffstat: M lib/wallet.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -948,8 +948,16 @@ class Wallet: key = tx_hash + ":%d" % output.get('index') if key in self.spent_outputs: continue output['tx_hash'] = tx_hash - coins.append(output) - return coins + output['height'] = tx_height + coins.append((tx_height, output)) + + # sort by age + if coins: + coins = sorted(coins) + if coins[-1][0] != 0: + while coins[0][0] == 0: + coins = coins[1:] + [ coins[0] ] + return [x[1] for x in coins]