Skip to content
Snippets Groups Projects
Commit 1f25b74d authored by inso's avatar inso
Browse files

Fix issue #516

parent 4ea34851
No related branches found
No related tags found
No related merge requests found
...@@ -190,38 +190,39 @@ class Wallet(QObject): ...@@ -190,38 +190,39 @@ class Wallet(QObject):
amount, amount_base = reduce_base(amount, 0) amount, amount_base = reduce_base(amount, 0)
cache = self.caches[community.currency] cache = self.caches[community.currency]
current_base = max([src['base'] for src in cache.available_sources]) if cache.available_sources:
value = 0 current_base = max([src['base'] for src in cache.available_sources])
sources = [] value = 0
outputs = [] sources = []
overheads = [] outputs = []
buf_sources = list(cache.available_sources) overheads = []
while current_base >= 0: buf_sources = list(cache.available_sources)
for s in [src for src in cache.available_sources if src['base'] == current_base]: while current_base >= 0:
test_sources = sources + [s] for s in [src for src in cache.available_sources if src['base'] == current_base]:
val = current_value(test_sources, overheads) test_sources = sources + [s]
# if we have to compute an overhead val = current_value(test_sources, overheads)
if current_value(test_sources, overheads) > amount * (10**amount_base): # if we have to compute an overhead
overhead = current_value(test_sources, overheads) - int(amount) * (10**amount_base) if current_value(test_sources, overheads) > amount * (10**amount_base):
# we round the overhead in the current base overhead = current_value(test_sources, overheads) - int(amount) * (10**amount_base)
# exemple : 12 in base 1 -> 1*10^1 # we round the overhead in the current base
overhead = int(round(float(overhead) / (10**current_base))) # exemple : 12 in base 1 -> 1*10^1
source_value = s['amount'] * (10**s['base']) overhead = int(round(float(overhead) / (10**current_base)))
out = int((source_value - (overhead * (10**current_base)))/(10**current_base)) source_value = s['amount'] * (10**s['base'])
if out * (10**current_base) <= amount * (10**amount_base): out = int((source_value - (overhead * (10**current_base)))/(10**current_base))
if out * (10**current_base) <= amount * (10**amount_base):
sources.append(s)
buf_sources.remove(s)
overheads.append((overhead, current_base))
outputs.append((out, current_base))
# else just add the output
else:
sources.append(s) sources.append(s)
buf_sources.remove(s) buf_sources.remove(s)
overheads.append((overhead, current_base)) outputs.append((s['amount'] , s['base']))
outputs.append((out, current_base)) if current_value(sources, overheads) == amount * (10 ** amount_base):
# else just add the output return sources, outputs, overheads, buf_sources
else:
sources.append(s) current_base -= 1
buf_sources.remove(s)
outputs.append((s['amount'] , s['base']))
if current_value(sources, overheads) == amount * (10 ** amount_base):
return sources, outputs, overheads, buf_sources
current_base -= 1
raise NotEnoughMoneyError(value, community.currency, raise NotEnoughMoneyError(value, community.currency,
len(sources), amount * pow(10, amount_base)) len(sources), amount * pow(10, amount_base))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment