Skip to content

Commit

Permalink
Better check to avoid creating dust transactions. Gathers more inputs…
Browse files Browse the repository at this point in the history
… if the change is below the dust limit.
  • Loading branch information
wdl1908 committed May 13, 2015
1 parent e8eb5b8 commit ed9bc32
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions openassets/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ def asset_asset_swap(
return self.transfer(
[(asset1_id, asset1_transfer_spec), (asset2_id, asset2_transfer_spec)], btc_transfer_spec, fees)

@staticmethod
def _collect_uncolored_outputs(unspent_outputs, amount):
def _collect_uncolored_outputs(self, unspent_outputs, amount):
"""
Returns a list of uncolored outputs for the specified amount.
Expand All @@ -191,10 +190,14 @@ def _collect_uncolored_outputs(unspent_outputs, amount):
result.append(output)
total_amount += output.output.value

if total_amount >= amount:
# Make sure we don't create dust outputs
if total_amount == amount or total_amount >= amount and (total_amount - amount) >= self._dust_amount:
return result, total_amount

raise InsufficientFundsError
if total_amount >= amount and (total_amount - amount) < self._dust_amount:
raise DustOutputError
else:
raise InsufficientFundsError

@staticmethod
def _collect_colored_outputs(unspent_outputs, asset_id, asset_quantity):
Expand Down

0 comments on commit ed9bc32

Please sign in to comment.