Skip to content
Snippets Groups Projects
Commit 8fb0a404 authored by inso's avatar inso
Browse files

Fix transaction builder algorithm

parent 455ddcce
No related branches found
No related tags found
No related merge requests found
......@@ -175,18 +175,18 @@ class Wallet(QObject):
:return: The list of inputs to use in the transaction document
"""
value = 0
amount, amount_base = reduce_base(amount, 0)
cache = self.caches[community.currency]
current_base = amount_base
while current_base >= 0:
value = 0
sources = []
buf_sources = list(cache.available_sources)
while current_base >= 0:
for s in [src for src in cache.available_sources if src['base'] == current_base]:
value += s['amount'] * pow(10, s['base'])
sources.append(s)
buf_sources.remove(s)
if value >= amount:
if value >= amount * pow(10, amount_base):
overhead = value - int(amount)
overhead, overhead_max_base = reduce_base(overhead, 0)
if overhead_max_base >= current_base:
......
......@@ -72,8 +72,8 @@ class TestWallet(unittest.TestCase, QuamashTest):
self.assertEqual(tx.inputs[1].source, "D")
self.assertEqual(tx.inputs[1].index, 4)
self.assertEqual(len(tx.outputs), 1)
self.assertEqual(tx.outputs[0].amount, 1)
self.assertEqual(tx.outputs[0].base, 2)
self.assertEqual(tx.outputs[0].amount, 100)
self.assertEqual(tx.outputs[0].base, 0)
self.assertEqual(pypeg2.compose(tx.outputs[0].conditions, output.Condition),
"SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)")
self.assertEqual(len(tx.unlocks), 2)
......@@ -94,5 +94,5 @@ Unlocks:
0:SIG(0)
1:SIG(0)
Outputs:
1:2:SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)
100:0:SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)
Comment:""" + " \n")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment