Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
robby-d committed May 17, 2017
1 parent 5cd6bf1 commit afe7cd9
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions counterpartylib/lib/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,9 @@ def get_tx_list(block):

return (tx_hash_list, raw_transactions)

def input_value_weight(amount):
# Prefer outputs less than dust size, then bigger is better.
if amount * config.UNIT <= config.DEFAULT_REGULAR_DUST_SIZE:
return 0
else:
return 1 / amount

def sort_unspent_txouts(unspent, unconfirmed=False):
# Get deterministic results (for multiAPIConsensus type requirements), sort by timestamp and vout index.
# (Oldest to newest so the nodes don’t have to be exactly caught up to each other for consensus to be achieved.)
# searchrawtransactions doesn’t support unconfirmed transactions
try:
unspent = sorted(unspent, key=sortkeypicker(['ts', 'vout']))
except KeyError: # If timestamp isn’t given.
pass

# Sort by amount.
unspent = sorted(unspent, key=lambda x: input_value_weight(x['amount']))
# Sort by amount, using the largest UTXOs available, which avoids dust outputs if at all possible
unspent = sorted(unspent, key=lambda x: x['amount'], reverse=True)

return unspent

Expand Down

0 comments on commit afe7cd9

Please sign in to comment.