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

[enh] #301 make `balance` use <pubkey:checksum> format

   * for display
   * as parameter

* Change test_end_to_end.py to match new behavior
parent de5e670e
No related branches found
No related tags found
No related merge requests found
...@@ -17,13 +17,15 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. ...@@ -17,13 +17,15 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
from click import command, argument, pass_context, echo from click import command, argument, pass_context, echo
from tabulate import tabulate from tabulate import tabulate
import re
from silkaj.network_tools import ClientInstance from silkaj.network_tools import ClientInstance
from silkaj.blockchain_tools import HeadBlock from silkaj.blockchain_tools import HeadBlock
from silkaj.tools import CurrencySymbol, message_exit, coroutine from silkaj.tools import CurrencySymbol, message_exit, coroutine
from silkaj.auth import auth_method from silkaj.auth import auth_method
from silkaj.wot import check_public_key from silkaj.wot import check_public_key
from silkaj.tui import display_amount from silkaj.tui import display_amount, pubkey_with_checksum
from silkaj.crypto_tools import PUBKEY_DELIMITED_PATTERN, check_public_key
from duniterpy.api.bma import tx, blockchain from duniterpy.api.bma import tx, blockchain
from duniterpy.documents.transaction import InputSource from duniterpy.documents.transaction import InputSource
...@@ -43,12 +45,14 @@ async def cmd_amount(ctx, pubkeys): ...@@ -43,12 +45,14 @@ async def cmd_amount(ctx, pubkeys):
): ):
if not pubkeys: if not pubkeys:
message_exit("You should specify one or many pubkeys") message_exit("You should specify one or many pubkeys")
checked_pubkeys = list()
for pubkey in pubkeys: for pubkey in pubkeys:
pubkey = check_public_key(pubkey, True) pubkey = check_public_key(pubkey, True)
checked_pubkeys.append(pubkey)
if not pubkey: if not pubkey:
return return
total = [0, 0] total = [0, 0]
for pubkey in pubkeys: for pubkey in checked_pubkeys:
inputs_balance = await get_amount_from_pubkey(pubkey) inputs_balance = await get_amount_from_pubkey(pubkey)
await show_amount_from_pubkey(pubkey, inputs_balance) await show_amount_from_pubkey(pubkey, inputs_balance)
total[0] += inputs_balance[0] total[0] += inputs_balance[0]
...@@ -68,6 +72,9 @@ async def show_amount_from_pubkey(pubkey, inputs_balance): ...@@ -68,6 +72,9 @@ async def show_amount_from_pubkey(pubkey, inputs_balance):
currency_symbol = await CurrencySymbol().symbol currency_symbol = await CurrencySymbol().symbol
ud_value = await UDValue().ud_value ud_value = await UDValue().ud_value
average, monetary_mass = await get_average() average, monetary_mass = await get_average()
# if `pubkey` is a pubkey, get pubkey:checksum
if re.search(re.compile(PUBKEY_DELIMITED_PATTERN), pubkey):
pubkey = pubkey_with_checksum(pubkey)
# display balance table # display balance table
display = list() display = list()
display.append(["Balance of pubkey", pubkey]) display.append(["Balance of pubkey", pubkey])
......
...@@ -52,7 +52,7 @@ def test_balance(): ...@@ -52,7 +52,7 @@ def test_balance():
silkaj + ["--gtest", "balance", "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj"] silkaj + ["--gtest", "balance", "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj"]
).decode() ).decode()
assert ( assert (
"│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj │" "│ Balance of pubkey │ 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj:EyF"
in output in output
) )
assert "│ Total amount (unit|relative) │" in output assert "│ Total amount (unit|relative) │" in output
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment