From de52c12080f75694169281eef18117e5bdb531fe Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Mon, 25 Apr 2022 19:14:45 +0200 Subject: [PATCH] [mod] #397: Get rid of CurrencySymbol() singleton --- silkaj/commands.py | 6 +++--- silkaj/money.py | 4 ++-- silkaj/tools.py | 25 +++++++------------------ silkaj/tx.py | 2 +- silkaj/tx_history.py | 4 ++-- tests/patched/tools.py | 4 ++-- tests/test_unit_tx.py | 4 ++-- 7 files changed, 19 insertions(+), 30 deletions(-) diff --git a/silkaj/commands.py b/silkaj/commands.py index e7b7e0f0..1c050d57 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -27,7 +27,7 @@ from websocket._exceptions import WebSocketConnectionClosedException from silkaj.blockchain_tools import HeadBlock from silkaj.constants import ALL, HOUR from silkaj.network_tools import ClientInstance, determine_endpoint -from silkaj.tools import CurrencySymbol +from silkaj.tools import get_currency_symbol from silkaj.wot_tools import identity_of @@ -44,7 +44,7 @@ def currency_info(): "\nCurrent block number:", head_block["number"], "\nCurrency name:", - CurrencySymbol().symbol, + get_currency_symbol(), "\nNumber of members:", head_block["membersCount"], "\nMinimal Proof-of-Work:", @@ -197,7 +197,7 @@ def list_blocks(number, detailed): @command("argos", help="Display currency information formatted for Argos or BitBar") def argos_info(): head_block = HeadBlock().head_block - currency_symbol = CurrencySymbol().symbol + currency_symbol = get_currency_symbol() print(currency_symbol, "|") print("---") ep = determine_endpoint() diff --git a/silkaj/money.py b/silkaj/money.py index 9baa33d2..ddc566ee 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -29,7 +29,7 @@ from silkaj.crypto_tools import ( validate_checksum, ) from silkaj.network_tools import ClientInstance -from silkaj.tools import CurrencySymbol +from silkaj.tools import get_currency_symbol from silkaj.tui import display_amount, display_pubkey_and_checksum @@ -78,7 +78,7 @@ def show_amount_from_pubkey(label, inputs_balance): """ totalAmountInput = inputs_balance[0] balance = inputs_balance[1] - currency_symbol = CurrencySymbol().symbol + currency_symbol = get_currency_symbol() ud_value = UDValue().ud_value average, monetary_mass = get_average() member = False diff --git a/silkaj/tools.py b/silkaj/tools.py index d3cf793a..d0a36691 100644 --- a/silkaj/tools.py +++ b/silkaj/tools.py @@ -21,24 +21,13 @@ from silkaj.constants import FAILURE_EXIT_STATUS, G1_SYMBOL, GTEST_SYMBOL from silkaj.network_tools import ClientInstance -class CurrencySymbol: - __instance = None - - def __new__(cls): - if CurrencySymbol.__instance is None: - CurrencySymbol.__instance = object.__new__(cls) - return CurrencySymbol.__instance - - def __init__(self): - self.symbol = self.get_symbol() - - def get_symbol(self): - client = ClientInstance().client - params = client(blockchain.parameters) - if params["currency"] == "g1": - return G1_SYMBOL - elif params["currency"] == "g1-test": - return GTEST_SYMBOL +def get_currency_symbol(): + client = ClientInstance().client + params = client(blockchain.parameters) + if params["currency"] == "g1": + return G1_SYMBOL + elif params["currency"] == "g1-test": + return GTEST_SYMBOL def message_exit(message): diff --git a/silkaj/tx.py b/silkaj/tx.py index 65702fa8..62c4d584 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -312,7 +312,7 @@ def gen_confirmation_table( Generate transaction confirmation """ - currency_symbol = tools.CurrencySymbol().symbol + currency_symbol = tools.get_currency_symbol() ud_value = money.UDValue().ud_value total_tx_amount = sum(tx_amounts) tx = list() diff --git a/silkaj/tx_history.py b/silkaj/tx_history.py index d84130db..93e6d65a 100644 --- a/silkaj/tx_history.py +++ b/silkaj/tx_history.py @@ -28,7 +28,7 @@ from silkaj.constants import ALL, ALL_DIGITAL from silkaj.crypto_tools import check_pubkey_format, validate_checksum from silkaj.money import UDValue, amount_in_current_base, get_amount_from_pubkey from silkaj.network_tools import ClientInstance -from silkaj.tools import CurrencySymbol +from silkaj.tools import get_currency_symbol from silkaj.tui import display_pubkey_and_checksum @@ -42,7 +42,7 @@ def transaction_history(pubkey, uids, full_pubkey): client = ClientInstance().client ud_value = UDValue().ud_value - currency_symbol = CurrencySymbol().symbol + currency_symbol = get_currency_symbol() header = generate_header(pubkey, currency_symbol, ud_value) received_txs, sent_txs = list(), list() diff --git a/tests/patched/tools.py b/tests/patched/tools.py index dba0c6e9..c37e13ff 100644 --- a/tests/patched/tools.py +++ b/tests/patched/tools.py @@ -16,6 +16,6 @@ from silkaj.constants import G1_SYMBOL -# mock CurrencySymbol().symbol -def patched_currency_symbol(self): +# mock get_currency_symbol().symbol +def patched_get_currency_symbol(): return G1_SYMBOL diff --git a/tests/test_unit_tx.py b/tests/test_unit_tx.py index abd83674..6a05d12c 100644 --- a/tests/test_unit_tx.py +++ b/tests/test_unit_tx.py @@ -30,7 +30,7 @@ from patched.auth import patched_auth_method from patched.blockchain_tools import fake_block_id, patched_head_block from patched.money import patched_get_sources, patched_ud_value from patched.test_constants import mock_ud_value -from patched.tools import patched_currency_symbol +from patched.tools import patched_get_currency_symbol from patched.tx import ( patched_gen_confirmation_table, patched_handle_intermediaries_transactions, @@ -124,7 +124,7 @@ def test_gen_confirmation_table( # patched functions monkeypatch.setattr(wot_tools, "is_member", patched_is_member) monkeypatch.setattr(money.UDValue, "get_ud_value", patched_ud_value) - monkeypatch.setattr(tools.CurrencySymbol, "get_symbol", patched_currency_symbol) + monkeypatch.setattr(tools, "get_currency_symbol", patched_get_currency_symbol) # creating expected list expected = list() -- GitLab