Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
silkaj
Commits
652eb059
Commit
652eb059
authored
6 years ago
by
Moul
Committed by
Mael
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#184
: add generic f() to calculate amount in current base…
… from input or output source - Use it in balance and tx commands
parent
31d51df2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
silkaj/money.py
+9
-2
9 additions, 2 deletions
silkaj/money.py
silkaj/tx.py
+8
-3
8 additions, 3 deletions
silkaj/tx.py
with
17 additions
and
5 deletions
silkaj/money.py
+
9
−
2
View file @
652eb059
...
@@ -120,7 +120,7 @@ async def get_amount_from_pubkey(pubkey):
...
@@ -120,7 +120,7 @@ async def get_amount_from_pubkey(pubkey):
totalAmountInput
=
0
totalAmountInput
=
0
for
input
in
listinput
:
for
input
in
listinput
:
totalAmountInput
+=
input
.
amount
*
10
**
input
.
base
totalAmountInput
+=
amount_in_current_base
(
input
)
return
totalAmountInput
,
amount
return
totalAmountInput
,
amount
...
@@ -133,7 +133,6 @@ async def get_sources(pubkey):
...
@@ -133,7 +133,6 @@ async def get_sources(pubkey):
amount
=
0
amount
=
0
for
source
in
sources
[
"
sources
"
]:
for
source
in
sources
[
"
sources
"
]:
if
source
[
"
conditions
"
]
==
"
SIG(
"
+
pubkey
+
"
)
"
:
if
source
[
"
conditions
"
]
==
"
SIG(
"
+
pubkey
+
"
)
"
:
amount
+=
source
[
"
amount
"
]
*
10
**
source
[
"
base
"
]
listinput
.
append
(
listinput
.
append
(
InputSource
(
InputSource
(
amount
=
source
[
"
amount
"
],
amount
=
source
[
"
amount
"
],
...
@@ -143,6 +142,7 @@ async def get_sources(pubkey):
...
@@ -143,6 +142,7 @@ async def get_sources(pubkey):
index
=
source
[
"
noffset
"
],
index
=
source
[
"
noffset
"
],
)
)
)
)
amount
+=
amount_in_current_base
(
listinput
[
-
1
])
# pending source
# pending source
history
=
await
client
(
tx
.
pending
,
pubkey
)
history
=
await
client
(
tx
.
pending
,
pubkey
)
...
@@ -204,3 +204,10 @@ class UDValue(object):
...
@@ -204,3 +204,10 @@ class UDValue(object):
NBlastUDblock
=
blockswithud
[
"
result
"
][
"
blocks
"
][
-
1
]
NBlastUDblock
=
blockswithud
[
"
result
"
][
"
blocks
"
][
-
1
]
lastUDblock
=
await
client
(
blockchain
.
block
,
NBlastUDblock
)
lastUDblock
=
await
client
(
blockchain
.
block
,
NBlastUDblock
)
return
lastUDblock
[
"
dividend
"
]
*
10
**
lastUDblock
[
"
unitbase
"
]
return
lastUDblock
[
"
dividend
"
]
*
10
**
lastUDblock
[
"
unitbase
"
]
def
amount_in_current_base
(
source
):
"""
Get amount in current base from input or output source
"""
return
source
.
amount
*
10
**
source
.
base
This diff is collapsed.
Click to expand it.
silkaj/tx.py
+
8
−
3
View file @
652eb059
...
@@ -26,7 +26,12 @@ from silkaj.crypto_tools import check_public_key
...
@@ -26,7 +26,12 @@ from silkaj.crypto_tools import check_public_key
from
silkaj.tools
import
message_exit
,
CurrencySymbol
,
coroutine
from
silkaj.tools
import
message_exit
,
CurrencySymbol
,
coroutine
from
silkaj.auth
import
auth_method
from
silkaj.auth
import
auth_method
from
silkaj.wot
import
get_uid_from_pubkey
from
silkaj.wot
import
get_uid_from_pubkey
from
silkaj.money
import
get_sources
,
get_amount_from_pubkey
,
UDValue
from
silkaj.money
import
(
get_sources
,
get_amount_from_pubkey
,
UDValue
,
amount_in_current_base
,
)
from
silkaj.constants
import
NO_MATCHING_ID
from
silkaj.constants
import
NO_MATCHING_ID
from
duniterpy.api.bma.tx
import
process
from
duniterpy.api.bma.tx
import
process
...
@@ -326,8 +331,8 @@ async def get_list_input_for_transaction(pubkey, TXamount):
...
@@ -326,8 +331,8 @@ async def get_list_input_for_transaction(pubkey, TXamount):
intermediatetransaction
=
False
intermediatetransaction
=
False
for
input
in
listinput
:
for
input
in
listinput
:
listinputfinal
.
append
(
input
)
listinputfinal
.
append
(
input
)
totalAmountInput
+=
input
.
amount
*
10
**
input
.
base
totalAmountInput
+=
amount_in_current_base
(
input
)
TXamount
-=
input
.
amount
*
10
**
input
.
base
TXamount
-=
amount_in_current_base
(
input
)
# if more 40 sources, it's an intermediate transaction
# if more 40 sources, it's an intermediate transaction
if
len
(
listinputfinal
)
>=
40
:
if
len
(
listinputfinal
)
>=
40
:
intermediatetransaction
=
True
intermediatetransaction
=
True
...
...
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