Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
1f25b74d
Commit
1f25b74d
authored
8 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Fix issue
#516
parent
4ea34851
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sakia/core/wallet.py
+31
-30
31 additions, 30 deletions
src/sakia/core/wallet.py
with
31 additions
and
30 deletions
src/sakia/core/wallet.py
+
31
−
30
View file @
1f25b74d
...
@@ -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
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment