diff --git a/silkaj/commands.py b/silkaj/commands.py index 8b6718f73c11b374105ffad3d01cc6789561ad55..9625a75eed4adf742f79e35223bff7644589eac0 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -19,7 +19,7 @@ def currency_info(ep): system("clear") print("Connected to node:", ep[best_node(ep, False)], ep["port"], "\nCurrent block number:", head_block["number"], - "\nCurrency name:", currency_symbol, + "\nCurrency name:", CurrencySymbol().symbol, "\nNumber of members:", head_block["membersCount"], "\nMinimal Proof-of-Work:", head_block["powMin"], "\nCurrent time:", convert_time(head_block["time"], "all"), @@ -231,7 +231,7 @@ def argos_info(ep): 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:", currency_symbol, + "\nCurrency name:", CurrencySymbol().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 8e8a22e28e32a90d6cf7b92fddc2baba682d22d0..c02b62e30b1865525eaf09f26f5369bf40647446 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -18,19 +18,19 @@ def cmd_amount(ep, cli_args): total[0] += value[0] total[1] += value[1] if (len(pubkeys) > 1): - show_amount_from_pubkey(ep, "Total", total, currency_symbol) + show_amount_from_pubkey(ep, "Total", total) else: seed = auth_method(cli_args) pubkey = get_publickey_from_seed(seed) show_amount_from_pubkey(ep, pubkey, get_amount_from_pubkey(ep, pubkey)) -def show_amount_from_pubkey(ep, pubkey, value, currency_symbol): +def show_amount_from_pubkey(ep, pubkey, value): totalAmountInput = value[0] amount = value[1] # output - currency_symbol = CurrencySymbol().symbol + currency_symbol = CurrencySymbol(ep).symbol ud_value = UDValue(ep).ud_value if totalAmountInput - amount != 0: print("Blockchain:") diff --git a/silkaj/tools.py b/silkaj/tools.py index 3f623957cfc73b0115b64315d9c8e5c21d347ca6..db46d6f14bba715e1e7ffde93a4027edb52f6535 100644 --- a/silkaj/tools.py +++ b/silkaj/tools.py @@ -23,11 +23,20 @@ def convert_time(timestamp, kind): return datetime.fromtimestamp(ts).strftime(pattern) -def get_currency_symbol(currency): - if currency == "g1": - return G1_SYMBOL - elif currency == "g1-test": - return GTEST_SYMBOL +class CurrencySymbol(object): + __instance = None + + def __new__(cls, ep): + if CurrencySymbol.__instance is None: + CurrencySymbol.__instance = object.__new__(cls) + return CurrencySymbol.__instance + + def __init__(self, ep): + currency = BlockchainParams(ep).params["currency"] + if currency == "g1": + self.symbol = G1_SYMBOL + elif currency == "g1-test": + self.symbol = GTEST_SYMBOL def sign_document_from_seed(document, seed): diff --git a/silkaj/tx.py b/silkaj/tx.py index 7e78deab24f828885a524bd751b921a07c0e7cdc..49a097b3c5fba84337494471e4e4547d1a2fec11 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -6,7 +6,7 @@ import urllib from tabulate import tabulate from silkaj.network_tools import get_request, post_request, HeadBlock from silkaj.tools import get_publickey_from_seed, sign_document_from_seed,\ - check_public_key, message_exit + check_public_key, message_exit, CurrencySymbol from silkaj.auth import auth_method from silkaj.wot import get_uid_from_pubkey from silkaj.money import get_amount_from_pubkey, UDValue @@ -26,7 +26,7 @@ def send_transaction(ep, cli_args): 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, currency_symbol, outputAddresses, comment), + input(tabulate(transaction_confirmation(ep, issuer_pubkey, amount, outputAddresses, comment), tablefmt="fancy_grid") + "\nDo you confirm sending this transaction? [yes/no]: ") == "yes": generate_and_send_transaction(ep, seed, issuer_pubkey, amount, outputAddresses, comment, allSources, outputBackChange) @@ -69,11 +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, currency_symbol, outputAddresses, comment): +def transaction_confirmation(ep, issuer_pubkey, amount, outputAddresses, comment): """ Generate transaction confirmation """ + currency_symbol = CurrencySymbol(ep).symbol tx = list() tx.append(["amount (" + currency_symbol + ")", amount / 100 * len(outputAddresses)]) tx.append(["amount (UD " + currency_symbol + ")", round(amount / UDValue(ep).ud_value, 4)])