1
0

Use bucketing to choose coins

Bucketing is generalization of coin chooser logic that makes it easy
to implement other algorithms.

- Put core coin chooser functionality in base class.
- Specialize derived class to implement classic electrum algorithm of
  oldest coins first.  One bucket per output.

No intended change in behaviour.
Coin chooser now sorts the coins as it wants; remove redundant sorting
from get_spendable_coins().
This commit is contained in:
Neil Booth
2015-11-29 17:59:36 +09:00
parent 93bb09230c
commit 9a6dcf7b1e
2 changed files with 71 additions and 38 deletions

View File

@@ -627,15 +627,9 @@ class Abstract_Wallet(PrintError):
'height':tx_height,
'coinbase':is_cb
}
coins.append((tx_height, output))
coins.append(output)
continue
# sort by age
if coins:
coins = sorted(coins)
if coins[-1][0] != 0:
while coins[0][0] == 0:
coins = coins[1:] + [ coins[0] ]
return [value for height, value in coins]
return coins
def get_max_amount(self, config, inputs, fee):
sendable = sum(map(lambda x:x['value'], inputs))