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
6dc7640d
Commit
6dc7640d
authored
6 years ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#42
: retrieve head_block and currency params at the beginning.
parent
f119922c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
silkaj/commands.py
+5
-5
5 additions, 5 deletions
silkaj/commands.py
silkaj/money.py
+16
-9
16 additions, 9 deletions
silkaj/money.py
silkaj/silkaj.py
+9
-8
9 additions, 8 deletions
silkaj/silkaj.py
silkaj/tx.py
+4
-6
4 additions, 6 deletions
silkaj/tx.py
with
34 additions
and
28 deletions
silkaj/commands.py
+
5
−
5
View file @
6dc7640d
...
...
@@ -7,11 +7,11 @@ from operator import itemgetter
from
silkaj.wot
import
get_uid_from_pubkey
from
silkaj.network_tools
import
discover_peers
,
get_request
,
best_node
,
get_current_block
from
silkaj.tools
import
convert_time
,
get_currency_symbol
,
message_exit
from
silkaj.tools
import
convert_time
,
message_exit
from
silkaj.constants
import
NO_MATCHING_ID
def
currency_info
(
ep
,
head_block
):
def
currency_info
(
ep
,
head_block
,
currency_symbol
):
info_type
=
[
"
newcomers
"
,
"
certs
"
,
"
actives
"
,
"
leavers
"
,
"
excluded
"
,
"
ud
"
,
"
tx
"
]
i
,
info_data
=
0
,
dict
()
while
(
i
<
len
(
info_type
)):
...
...
@@ -20,7 +20,7 @@ def currency_info(ep, head_block):
system
(
"
clear
"
)
print
(
"
Connected to node:
"
,
ep
[
best_node
(
ep
,
False
)],
ep
[
"
port
"
],
"
\n
Current block number:
"
,
head_block
[
"
number
"
],
"
\n
Currency name:
"
,
get_
currency_symbol
(
head_block
[
"
currency
"
])
,
"
\n
Currency name:
"
,
currency_symbol
,
"
\n
Number of members:
"
,
head_block
[
"
membersCount
"
],
"
\n
Minimal Proof-of-Work:
"
,
head_block
[
"
powMin
"
],
"
\n
Current time:
"
,
convert_time
(
head_block
[
"
time
"
],
"
all
"
),
...
...
@@ -215,7 +215,7 @@ def list_issuers(ep, head_block, nbr, last):
tabulate
(
sorted_list
,
headers
=
"
keys
"
,
tablefmt
=
"
orgtbl
"
,
floatfmt
=
"
.1f
"
,
stralign
=
"
center
"
)))
def
argos_info
(
ep
,
head_block
):
def
argos_info
(
ep
,
head_block
,
currency_symbol
):
info_type
=
[
"
newcomers
"
,
"
certs
"
,
"
actives
"
,
"
leavers
"
,
"
excluded
"
,
"
ud
"
,
"
tx
"
]
pretty_names
=
{
'
g1
'
:
'
Ğ1
'
,
'
gtest
'
:
'
Ğtest
'
}
i
,
info_data
=
0
,
dict
()
...
...
@@ -230,7 +230,7 @@ def argos_info(ep, head_block):
href
=
'
href=http://%s:%s/
'
%
(
ep
[
best_node
(
ep
,
False
)],
ep
[
"
port
"
])
print
(
"
Connected to node:
"
,
ep
[
best_node
(
ep
,
False
)],
ep
[
"
port
"
],
"
|
"
,
href
,
"
\n
Current block number:
"
,
head_block
[
"
number
"
],
"
\n
Currency name:
"
,
get_
currency_symbol
(
head_block
[
"
currency
"
])
,
"
\n
Currency name:
"
,
currency_symbol
,
"
\n
Number of members:
"
,
head_block
[
"
membersCount
"
],
"
\n
Minimal Proof-of-Work:
"
,
head_block
[
"
powMin
"
],
"
\n
Current time:
"
,
convert_time
(
head_block
[
"
time
"
],
"
all
"
),
...
...
This diff is collapsed.
Click to expand it.
silkaj/money.py
+
16
−
9
View file @
6dc7640d
...
...
@@ -4,7 +4,7 @@ from silkaj.auth import auth_method
from
silkaj.wot
import
check_public_key
def
cmd_amount
(
ep
,
cli_args
,
config
,
head_block
,
ud_value
,
currency_symbol
):
def
cmd_amount
(
ep
,
cli_args
,
head_block
,
ud_value
,
currency_symbol
):
if
not
cli_args
.
subsubcmd
.
startswith
(
"
--
"
):
pubkeys
=
cli_args
.
subsubcmd
.
split
(
"
:
"
)
for
pubkey
in
pubkeys
:
...
...
@@ -18,35 +18,42 @@ def cmd_amount(ep, cli_args, config, head_block, ud_value, currency_symbol):
total
[
0
]
+=
value
[
0
]
total
[
1
]
+=
value
[
1
]
if
(
len
(
pubkeys
)
>
1
):
show_amount_from_pubkey
(
ep
,
"
Total
"
,
total
)
show_amount_from_pubkey
(
"
Total
"
,
total
,
ud_value
,
currency_symbol
)
else
:
seed
=
auth_method
(
cli_args
)
pubkey
=
get_publickey_from_seed
(
seed
)
show_amount_from_pubkey
(
pubkey
,
get_amount_from_pubkey
(
ep
,
head_block
,
pubkey
),
ud_value
,
currency_symbol
)
def
show_amount_from_pubkey
(
ep
,
pubkey
,
value
):
def
wallets_conf
(
ep
,
config
):
member_id
=
config
[
"
member_id
"
]
if
member_id
!=
''
:
member_pubkey
=
get_pubkey_from_id
(
ep
,
member_id
)
wallets
=
config
[
"
wallets
"
].
split
(
"
:
"
)
if
member_id
!=
''
and
member_pubkey
!=
NO_MATCHING_ID
and
member_pubkey
not
in
wallets
:
wallets
.
insert
(
0
,
member_pubkey
)
return
wallets
def
show_amount_from_pubkey
(
pubkey
,
value
,
ud_value
,
currency_symbol
):
totalAmountInput
=
value
[
0
]
amount
=
value
[
1
]
# output
UDvalue
=
get_last_ud_value
(
ep
)
current_blk
=
get_current_block
(
ep
)
currency_symbol
=
get_currency_symbol
(
current_blk
[
"
currency
"
])
if
totalAmountInput
-
amount
!=
0
:
print
(
"
Blockchain:
"
)
print
(
"
-----------
"
)
print
(
"
Relative =
"
,
round
(
amount
/
UD
value
,
2
),
"
UD
"
,
currency_symbol
)
print
(
"
Relative =
"
,
round
(
amount
/
ud_
value
,
2
),
"
UD
"
,
currency_symbol
)
print
(
"
Quantitative =
"
,
round
(
amount
/
100
,
2
),
currency_symbol
+
"
\n
"
)
print
(
"
Pending Transaction:
"
)
print
(
"
--------------------
"
)
print
(
"
Relative =
"
,
round
((
totalAmountInput
-
amount
)
/
UD
value
,
2
),
"
UD
"
,
currency_symbol
)
print
(
"
Relative =
"
,
round
((
totalAmountInput
-
amount
)
/
ud_
value
,
2
),
"
UD
"
,
currency_symbol
)
print
(
"
Quantitative =
"
,
round
((
totalAmountInput
-
amount
)
/
100
,
2
),
currency_symbol
+
"
\n
"
)
print
(
"
Total amount of:
"
+
pubkey
)
print
(
"
----------------------------------------------------------------
"
)
print
(
"
Total Relative =
"
,
round
(
totalAmountInput
/
UD
value
,
2
),
"
UD
"
,
currency_symbol
)
print
(
"
Total Relative =
"
,
round
(
totalAmountInput
/
ud_
value
,
2
),
"
UD
"
,
currency_symbol
)
print
(
"
Total Quantitative =
"
,
round
(
totalAmountInput
/
100
,
2
),
currency_symbol
+
"
\n
"
)
...
...
This diff is collapsed.
Click to expand it.
silkaj/silkaj.py
+
9
−
8
View file @
6dc7640d
...
...
@@ -3,11 +3,11 @@
from
sys
import
stderr
from
commandlines
import
Command
from
silkaj.tx
import
send_transaction
from
silkaj.money
import
cmd_amount
from
silkaj.money
import
cmd_amount
,
get_last_ud_value
from
silkaj.cert
import
send_certification
from
silkaj.commands
import
currency_info
,
difficulties
,
set_network_sort_keys
,
\
network_info
,
argos_info
,
list_issuers
from
silkaj.tools
import
message_exit
from
silkaj.tools
import
get_currency_symbol
,
message_exit
from
silkaj.network_tools
import
get_request
,
get_current_block
from
silkaj.wot
import
received_sent_certifications
,
id_pubkey_correspondence
from
silkaj.auth
import
generate_auth_file
...
...
@@ -99,15 +99,16 @@ def cli():
def
get_parameters
(
ep
):
head_block
=
get_current_block
(
ep
)
params
=
get_request
(
ep
,
"
blockchain/parameters
"
)
return
params
,
head_block
currency_symbol
=
get_currency_symbol
(
params
[
"
currency
"
])
ud_value
=
get_last_ud_value
(
ep
)
return
params
,
head_block
,
currency_symbol
,
ud_value
def
manage_cmd
(
ep
,
cli_args
):
params
,
head_block
=
get_parameters
(
ep
)
params
,
head_block
,
currency_symbol
,
ud_value
=
get_parameters
(
ep
)
if
cli_args
.
subcmd
==
"
about
"
:
about
()
elif
cli_args
.
subcmd
==
"
info
"
:
currency_info
(
ep
,
head_block
)
currency_info
(
ep
,
head_block
,
currency_symbol
)
elif
cli_args
.
subcmd
==
"
diffi
"
:
difficulties
(
ep
)
...
...
@@ -123,10 +124,10 @@ def manage_cmd(ep, cli_args):
list_issuers
(
ep
,
head_block
,
int
(
cli_args
.
subsubcmd
),
cli_args
.
contains_switches
(
'
last
'
))
elif
cli_args
.
subcmd
==
"
argos
"
:
argos_info
(
ep
,
head_block
)
argos_info
(
ep
,
head_block
,
currency_symbol
)
elif
cli_args
.
subcmd
==
"
amount
"
:
cmd_amount
(
ep
,
cli_args
,
currency_config
,
head_block
,
ud_value
,
currency_symbol
)
cmd_amount
(
ep
,
cli_args
,
head_block
,
ud_value
,
currency_symbol
)
elif
cli_args
.
subcmd
==
"
tx
"
or
cli_args
.
subcmd
==
"
transaction
"
:
send_transaction
(
ep
,
cli_args
,
head_block
,
ud_value
,
currency_symbol
)
...
...
This diff is collapsed.
Click to expand it.
silkaj/tx.py
+
4
−
6
View file @
6dc7640d
...
...
@@ -9,7 +9,7 @@ from silkaj.tools import get_publickey_from_seed, sign_document_from_seed,\
check_public_key
,
message_exit
from
silkaj.auth
import
auth_method
from
silkaj.wot
import
get_uid_from_pubkey
from
silkaj.money
import
get_last_ud_value
,
get_amount_from_pubkey
from
silkaj.money
import
get_amount_from_pubkey
from
silkaj.constants
import
NO_MATCHING_ID
...
...
@@ -17,8 +17,7 @@ def send_transaction(ep, cli_args, head_block, ud_value, currency_symbol):
"""
Main function
"""
ud
=
get_last_ud_value
(
ep
)
amount
,
output
,
comment
,
allSources
,
outputBackChange
=
cmd_transaction
(
cli_args
,
ud
)
amount
,
output
,
comment
,
allSources
,
outputBackChange
=
cmd_transaction
(
cli_args
,
ud_value
)
seed
=
auth_method
(
cli_args
)
issuer_pubkey
=
get_publickey_from_seed
(
seed
)
...
...
@@ -27,7 +26,7 @@ def send_transaction(ep, cli_args, head_block, ud_value, currency_symbol):
check_transaction_values
(
comment
,
outputAddresses
,
outputBackChange
,
pubkey_amount
<
amount
*
len
(
outputAddresses
),
issuer_pubkey
)
if
cli_args
.
contains_switches
(
'
yes
'
)
or
cli_args
.
contains_switches
(
'
y
'
)
or
\
input
(
tabulate
(
transaction_confirmation
(
ep
,
issuer_pubkey
,
amount
,
ud
,
outputAddresses
,
comment
),
input
(
tabulate
(
transaction_confirmation
(
ep
,
issuer_pubkey
,
amount
,
ud
_value
,
currency_symbol
,
outputAddresses
,
comment
),
tablefmt
=
"
fancy_grid
"
)
+
"
\n
Do you confirm sending this transaction? [yes/no]:
"
)
==
"
yes
"
:
generate_and_send_transaction
(
ep
,
head_block
,
seed
,
issuer_pubkey
,
amount
,
outputAddresses
,
comment
,
allSources
,
outputBackChange
)
...
...
@@ -70,13 +69,12 @@ def check_transaction_values(comment, outputAddresses, outputBackChange, enough_
message_exit
(
issuer_pubkey
+
"
pubkey doesn’t have enough money for this transaction.
"
)
def
transaction_confirmation
(
ep
,
issuer_pubkey
,
amount
,
ud
,
outputAddresses
,
comment
):
def
transaction_confirmation
(
ep
,
issuer_pubkey
,
amount
,
ud
,
currency_symbol
,
outputAddresses
,
comment
):
"""
Generate transaction confirmation
"""
tx
=
list
()
currency_symbol
=
get_currency_symbol
(
get_current_block
(
ep
)[
"
currency
"
])
tx
.
append
([
"
amount (
"
+
currency_symbol
+
"
)
"
,
amount
/
100
*
len
(
outputAddresses
)])
tx
.
append
([
"
amount (UD
"
+
currency_symbol
+
"
)
"
,
amount
/
ud
])
tx
.
append
([
"
from
"
,
issuer_pubkey
])
...
...
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