Skip to content
Snippets Groups Projects
Commit dba56f74 authored by matograine's avatar matograine
Browse files

[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
......@@ -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(
......
......@@ -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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment