diff --git a/silkaj/commands.py b/silkaj/commands.py index 2daa81ac7b79eaff53b6aaf8e11eed254d50a492..623ddee51415b785f5194db782fe5d8e328d5aa5 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -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"], "\nCurrent block number:", head_block["number"], - "\nCurrency name:", get_currency_symbol(head_block["currency"]), + "\nCurrency name:", currency_symbol, "\nNumber of members:", head_block["membersCount"], "\nMinimal Proof-of-Work:", head_block["powMin"], "\nCurrent 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, "\nCurrent block number:", head_block["number"], - "\nCurrency name:", get_currency_symbol(head_block["currency"]), + "\nCurrency name:", currency_symbol, "\nNumber of members:", head_block["membersCount"], "\nMinimal Proof-of-Work:", head_block["powMin"], "\nCurrent time:", convert_time(head_block["time"], "all"), diff --git a/silkaj/money.py b/silkaj/money.py index 21c67e82bf0194918225812c42a24529e7913f6a..e32386557ebbdc5c5d4d7b358ebef0dee4f859b0 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -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 / UDvalue, 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) / UDvalue, 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 / UDvalue, 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") diff --git a/silkaj/silkaj.py b/silkaj/silkaj.py index d514df44d1cdb5b21b13c2a70e79138bb1ecf918..a4ad8c66fa0bb764bb456242bc28931ed550d99e 100644 --- a/silkaj/silkaj.py +++ b/silkaj/silkaj.py @@ -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) diff --git a/silkaj/tx.py b/silkaj/tx.py index befcb2bf3a7053d8944e71bff53af01280254f0f..80b1148c59bb80765261e7054818009cf124fcf0 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -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") + "\nDo 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])