Skip to content

Commit ed9bc32

Browse files
committed
Better check to avoid creating dust transactions. Gathers more inputs if the change is below the dust limit.
1 parent e8eb5b8 commit ed9bc32

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

openassets/transactions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ def asset_asset_swap(
174174
return self.transfer(
175175
[(asset1_id, asset1_transfer_spec), (asset2_id, asset2_transfer_spec)], btc_transfer_spec, fees)
176176

177-
@staticmethod
178-
def _collect_uncolored_outputs(unspent_outputs, amount):
177+
def _collect_uncolored_outputs(self, unspent_outputs, amount):
179178
"""
180179
Returns a list of uncolored outputs for the specified amount.
181180
@@ -191,10 +190,14 @@ def _collect_uncolored_outputs(unspent_outputs, amount):
191190
result.append(output)
192191
total_amount += output.output.value
193192

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

197-
raise InsufficientFundsError
197+
if total_amount >= amount and (total_amount - amount) < self._dust_amount:
198+
raise DustOutputError
199+
else:
200+
raise InsufficientFundsError
198201

199202
@staticmethod
200203
def _collect_colored_outputs(unspent_outputs, asset_id, asset_quantity):

0 commit comments

Comments
 (0)