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
dba56f74
Commit
dba56f74
authored
4 years ago
by
matograine
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#218
add option "full-pubkey" to command `history`
* modify related test.
parent
015b2273
No related branches found
No related tags found
No related merge requests found
Pipeline
#10864
passed
4 years ago
Stage: checks
Stage: tests
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
silkaj/tx_history.py
+16
-11
16 additions, 11 deletions
silkaj/tx_history.py
tests/test_tx_history.py
+17
-2
17 additions, 2 deletions
tests/test_tx_history.py
with
33 additions
and
13 deletions
silkaj/tx_history.py
+
16
−
11
View file @
dba56f74
...
...
@@ -33,8 +33,9 @@ from silkaj.tools import CurrencySymbol
@command
(
"
history
"
,
help
=
"
Display transaction history
"
)
@argument
(
"
pubkey
"
)
@option
(
"
--uids
"
,
"
-u
"
,
is_flag
=
True
,
help
=
"
Display uids
"
)
@option
(
"
--full-pubkey
"
,
"
-f
"
,
is_flag
=
True
,
help
=
"
Display full-length pubkeys
"
)
@coroutine
async
def
transaction_history
(
pubkey
,
uids
):
async
def
transaction_history
(
pubkey
,
uids
,
full_pubkey
):
if
check_pubkey_format
(
pubkey
):
pubkey
=
validate_checksum
(
pubkey
)
...
...
@@ -47,7 +48,7 @@ async def transaction_history(pubkey, uids):
await
get_transactions_history
(
client
,
pubkey
,
received_txs
,
sent_txs
)
remove_duplicate_txs
(
received_txs
,
sent_txs
)
txs_list
=
await
generate_table
(
received_txs
,
sent_txs
,
pubkey
,
ud_value
,
currency_symbol
,
uids
received_txs
,
sent_txs
,
pubkey
,
ud_value
,
currency_symbol
,
uids
,
full_pubkey
)
table
=
Texttable
(
max_width
=
get_terminal_size
()[
0
])
table
.
add_rows
(
txs_list
)
...
...
@@ -100,7 +101,7 @@ def remove_duplicate_txs(received_txs, sent_txs):
async
def
generate_table
(
received_txs
,
sent_txs
,
pubkey
,
ud_value
,
currency_symbol
,
uids
received_txs
,
sent_txs
,
pubkey
,
ud_value
,
currency_symbol
,
uids
,
full_pubkey
):
"""
Generate information in a list of lists for texttabe
...
...
@@ -110,8 +111,10 @@ async def generate_table(
"""
received_txs_table
,
sent_txs_table
=
list
(),
list
()
await
parse_received_tx
(
received_txs_table
,
received_txs
,
pubkey
,
ud_value
,
uids
)
await
parse_sent_tx
(
sent_txs_table
,
sent_txs
,
pubkey
,
ud_value
,
uids
)
await
parse_received_tx
(
received_txs_table
,
received_txs
,
pubkey
,
ud_value
,
uids
,
full_pubkey
)
await
parse_sent_tx
(
sent_txs_table
,
sent_txs
,
pubkey
,
ud_value
,
uids
,
full_pubkey
)
txs_table
=
received_txs_table
+
sent_txs_table
table_titles
=
[
...
...
@@ -127,7 +130,9 @@ async def generate_table(
return
txs_table
async
def
parse_received_tx
(
received_txs_table
,
received_txs
,
pubkey
,
ud_value
,
uids
):
async
def
parse_received_tx
(
received_txs_table
,
received_txs
,
pubkey
,
ud_value
,
uids
,
full_pubkey
):
"""
Extract issuers’ pubkeys
Get identities from pubkeys
...
...
@@ -147,7 +152,7 @@ async def parse_received_tx(received_txs_table, received_txs, pubkey, ud_value,
tx_list
.
append
(
str
())
for
i
,
issuer
in
enumerate
(
received_tx
.
issuers
):
tx_list
[
1
]
+=
prefix
(
None
,
None
,
i
)
+
assign_idty_from_pubkey
(
issuer
,
identities
issuer
,
identities
,
full_pubkey
)
amounts
=
tx_amount
(
received_tx
,
pubkey
,
received_func
)[
0
]
tx_list
.
append
(
amounts
/
100
)
...
...
@@ -156,7 +161,7 @@ async def parse_received_tx(received_txs_table, received_txs, pubkey, ud_value,
received_txs_table
.
append
(
tx_list
)
async
def
parse_sent_tx
(
sent_txs_table
,
sent_txs
,
pubkey
,
ud_value
,
uids
):
async
def
parse_sent_tx
(
sent_txs_table
,
sent_txs
,
pubkey
,
ud_value
,
uids
,
full_pubkey
):
"""
Extract recipients’ pubkeys from outputs
Get identities from pubkeys
...
...
@@ -196,7 +201,7 @@ async def parse_sent_tx(sent_txs_table, sent_txs, pubkey, ud_value, uids):
round
(
neg
(
amount_in_current_base
(
output
))
/
ud_value
,
2
)
)
tx_list
[
1
]
+=
prefix
(
tx_list
[
1
],
outputs
,
0
)
+
assign_idty_from_pubkey
(
output
.
condition
.
left
.
pubkey
,
identities
output
.
condition
.
left
.
pubkey
,
identities
,
full_pubkey
)
tx_list
.
append
(
amounts
)
tx_list
.
append
(
amounts_ud
)
...
...
@@ -241,8 +246,8 @@ def output_available(condition, comparison, value):
return
False
def
assign_idty_from_pubkey
(
pubkey
,
identities
):
idty
=
display_pubkey_and_checksum
(
pubkey
,
True
)
def
assign_idty_from_pubkey
(
pubkey
,
identities
,
full_pubkey
):
idty
=
display_pubkey_and_checksum
(
pubkey
,
short
=
not
full_pubkey
)
for
identity
in
identities
:
if
pubkey
==
identity
[
"
pubkey
"
]:
idty
=
"
{0} - {1}
"
.
format
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_tx_history.py
+
17
−
2
View file @
dba56f74
...
...
@@ -32,16 +32,31 @@ async def test_tx_history_generate_table():
pubkey
=
"
78ZwwgpgdH5uLZLbThUQH7LKwPgjMunYfLiCfUCySkM8
"
received_txs
,
sent_txs
=
list
(),
list
()
await
tx_history
.
get_transactions_history
(
client
,
pubkey
,
received_txs
,
sent_txs
)
await
tx_history
.
get_transactions_history
(
client
,
pubkey
,
received_txs
,
sent_txs
,
)
tx_history
.
remove_duplicate_txs
(
received_txs
,
sent_txs
)
txs_list
=
await
tx_history
.
generate_table
(
received_txs
,
sent_txs
,
pubkey
,
ud_value
,
currency
,
uids
received_txs
,
sent_txs
,
pubkey
,
ud_value
,
currency
,
uids
,
full_pubkey
=
False
)
txs_list_full
=
await
tx_history
.
generate_table
(
received_txs
,
sent_txs
,
pubkey
,
ud_value
,
currency
,
uids
,
full_pubkey
=
True
)
await
client
.
close
()
for
tx_list
in
txs_list
:
assert
len
(
tx_list
)
==
table_columns
assert
"
…:
"
in
txs_list
[
1
][
1
]
assert
len
(
txs_list
[
1
][
1
])
==
13
assert
not
"
…:
"
in
txs_list_full
[
1
][
1
]
assert
"
:
"
in
txs_list_full
[
1
][
1
]
# this length is not true for multisig txs, which are very unlikely for now.
assert
len
(
txs_list_full
[
1
][
1
])
==
47
or
len
(
txs_list_full
[
1
][
1
])
==
48
@pytest.mark.parametrize
(
...
...
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