Skip to content

Commit

Permalink
Fix make_change to not create half-satoshis
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinandresen authored and morcos committed Sep 5, 2014
1 parent b8d9223 commit 3a7c348
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions qa/rpc-tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "python-bitcoinrpc"))

from decimal import Decimal
from decimal import Decimal, ROUND_DOWN
import json
import random
import shutil
Expand Down Expand Up @@ -230,10 +230,12 @@ def make_change(from_node, amount_in, amount_out, fee):
change = amount_in - amount
if change > amount*2:
# Create an extra change output to break up big inputs
outputs[from_node.getnewaddress()] = float(change/2)
change = change/2
change_address = from_node.getnewaddress()
# Split change in two, being careful of rounding:
outputs[change_address] = Decimal(change/2).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)
change = amount_in - amount - outputs[change_address]
if change > 0:
outputs[from_node.getnewaddress()] = float(change)
outputs[from_node.getnewaddress()] = change
return outputs

def send_zeropri_transaction(from_node, to_node, amount, fee):
Expand Down

0 comments on commit 3a7c348

Please sign in to comment.