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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
silkaj
Commits
9a33175a
Commit
9a33175a
authored
5 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[enh] add smiths command
parent
664c4430
No related branches found
No related tags found
No related merge requests found
Pipeline
#9381
passed
5 years ago
Stage: checks
Stage: tests
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
silkaj/cli.py
+2
-0
2 additions, 0 deletions
silkaj/cli.py
silkaj/commands.py
+88
-0
88 additions, 0 deletions
silkaj/commands.py
with
90 additions
and
0 deletions
silkaj/cli.py
+
2
−
0
View file @
9a33175a
...
...
@@ -29,6 +29,7 @@ from silkaj.commands import (
network_info
,
argos_info
,
list_blocks
,
smiths
,
)
from
silkaj.wot
import
received_sent_certifications
,
id_pubkey_correspondence
from
silkaj.auth
import
generate_auth_file
...
...
@@ -101,6 +102,7 @@ cli.add_command(argos_info)
cli
.
add_command
(
generate_auth_file
)
cli
.
add_command
(
cmd_amount
)
cli
.
add_command
(
list_blocks
)
cli
.
add_command
(
smiths
)
cli
.
add_command
(
send_certification
)
cli
.
add_command
(
difficulties
)
cli
.
add_command
(
transaction_history
)
...
...
This diff is collapsed.
Click to expand it.
silkaj/commands.py
+
88
−
0
View file @
9a33175a
...
...
@@ -249,6 +249,92 @@ async def network_info(discover, sort):
print
(
tabulate
(
infos
,
headers
=
"
keys
"
,
tablefmt
=
"
orgtbl
"
,
stralign
=
"
center
"
))
@command
(
"
smiths
"
,
help
=
"
Display smiths informations (version, blocks on frame, diff)
"
)
@coroutine
async
def
smiths
():
head_block
=
await
HeadBlock
().
head_block
current_nbr
=
head_block
[
"
number
"
]
frame_size
=
head_block
[
"
issuersFrame
"
]
client
=
ClientInstance
().
client
# Get current frame blocks
blocks
=
await
client
(
bma
.
blockchain
.
blocks
,
frame_size
,
current_nbr
-
frame_size
+
1
)
# Get issuers difficulties
difficulties_obj
=
await
client
(
bma
.
blockchain
.
difficulties
)
difficulties_dict
=
dict
()
for
entry
in
difficulties_obj
[
"
levels
"
]:
difficulties_dict
[
entry
[
"
uid
"
]]
=
entry
[
"
level
"
]
# Get ws2p heads
heads_obj
=
await
client
(
bma
.
network
.
ws2p_heads
)
heads_dict
=
dict
()
for
entry
in
heads_obj
[
"
heads
"
]:
head_v2
=
entry
[
"
messageV2
"
].
split
(
"
:
"
)
heads_dict
[
head_v2
[
3
]]
=
head_v2
# Collect issuers and count number of forged blocks for each
issuers_dict
=
dict
()
versions_dict
=
dict
()
for
block
in
blocks
:
if
block
[
"
issuer
"
]
in
issuers_dict
:
# Update issuer
issuer
=
issuers_dict
[
block
[
"
issuer
"
]]
issuer
[
"
blocks_on_frame
"
]
+=
1
else
:
# Create issuer
issuer
=
OrderedDict
()
# get issuer version
version
=
"
unknown
"
if
block
[
"
issuer
"
]
in
heads_dict
:
version
=
heads_dict
[
block
[
"
issuer
"
]][
7
]
# Counting version occurrences
if
version
in
versions_dict
:
versions_dict
[
version
]
+=
1
else
:
versions_dict
[
version
]
=
1
# Fill issuer infos
issuer
[
"
uid
"
]
=
""
issuer
[
"
version
"
]
=
version
issuer
[
"
blocks_on_frame
"
]
=
1
issuer
[
"
diff
"
]
=
0
issuers_dict
[
block
[
"
issuer
"
]]
=
issuer
# Get username of each issuer (and fill their difficulty)
for
pubkey
,
issuer
in
issuers_dict
.
items
():
idty
=
await
identity_of
(
pubkey
)
issuer
[
"
uid
"
]
=
idty
[
"
uid
"
]
issuer
[
"
diff
"
]
=
difficulties_dict
[
issuer
[
"
uid
"
]]
await
sleep
(
ASYNC_SLEEP
)
await
client
.
close
()
# print datas
print
(
"
Current frame: {0} issuers [{1} blocks (#{2} to #{3})]
\n
"
.
format
(
len
(
issuers_dict
),
frame_size
,
current_nbr
-
frame_size
+
1
,
current_nbr
)
)
for
version
,
count
in
versions_dict
.
items
():
print
(
"
{0}: {1} smiths [{2} %]
"
.
format
(
version
,
count
,
round
(
count
/
len
(
issuers_dict
)
*
100
,
2
)
)
)
sorted_list
=
sorted
(
issuers_dict
.
values
(),
key
=
itemgetter
(
"
blocks_on_frame
"
),
reverse
=
True
)
print
(
"
{0}
"
.
format
(
tabulate
(
sorted_list
,
headers
=
"
keys
"
,
tablefmt
=
"
orgtbl
"
,
floatfmt
=
"
.1f
"
,
stralign
=
"
center
"
,
),
)
)
@command
(
"
blocks
"
,
help
=
"
Display blocks: default: 0 for current window size
"
)
@argument
(
"
number
"
,
default
=
0
,
type
=
IntRange
(
0
,
5000
))
@option
(
...
...
@@ -278,6 +364,7 @@ async def list_blocks(number, detailed):
issuer
[
"
powMin
"
]
=
block
[
"
powMin
"
]
issuers_dict
[
issuer
[
"
pubkey
"
]]
=
issuer
issuers
.
append
(
issuer
)
# Get username of each issuer
for
pubkey
in
issuers_dict
.
keys
():
issuer
=
issuers_dict
[
pubkey
]
idty
=
await
identity_of
(
issuer
[
"
pubkey
"
])
...
...
@@ -291,6 +378,7 @@ async def list_blocks(number, detailed):
issuer2
.
pop
(
"
pubkey
"
)
await
sleep
(
ASYNC_SLEEP
)
await
client
.
close
()
print
(
"
Last {0} blocks from n°{1} to n°{2}
"
.
format
(
number
,
current_nbr
-
number
+
1
,
current_nbr
...
...
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