Skip to content

Commit 28d38c0

Browse files
committed
refactor(settings): rename get_settings to get_global_settings
1 parent 126bae3 commit 28d38c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+141
-141
lines changed

hathor/builder/builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from structlog import get_logger
1919

2020
from hathor.checkpoint import Checkpoint
21-
from hathor.conf.get_settings import get_settings
21+
from hathor.conf.get_settings import get_global_settings
2222
from hathor.conf.settings import HathorSettings as HathorSettingsType
2323
from hathor.consensus import ConsensusAlgorithm
2424
from hathor.daa import DifficultyAdjustmentAlgorithm
@@ -285,7 +285,7 @@ def set_peer_id(self, peer_id: PeerId) -> 'Builder':
285285
def _get_or_create_settings(self) -> HathorSettingsType:
286286
"""Return the HathorSettings instance set on this builder, or a new one if not set."""
287287
if self._settings is None:
288-
self._settings = get_settings()
288+
self._settings = get_global_settings()
289289
return self._settings
290290

291291
def _get_reactor(self) -> Reactor:

hathor/builder/cli_builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def check_or_raise(self, condition: bool, message: str) -> None:
6161

6262
def create_manager(self, reactor: Reactor) -> HathorManager:
6363
import hathor
64-
from hathor.conf.get_settings import get_settings, get_settings_source
64+
from hathor.conf.get_settings import get_global_settings, get_settings_source
6565
from hathor.daa import TestMode
6666
from hathor.event.storage import EventMemoryStorage, EventRocksDBStorage, EventStorage
6767
from hathor.event.websocket.factory import EventWebsocketFactory
@@ -79,7 +79,7 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
7979
)
8080
from hathor.util import get_environment_info
8181

82-
settings = get_settings()
82+
settings = get_global_settings()
8383

8484
# only used for logging its location
8585
settings_source = get_settings_source()

hathor/builder/resources_builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def create_prometheus(self) -> PrometheusMetricsExporter:
7777
return prometheus
7878

7979
def create_resources(self) -> server.Site:
80-
from hathor.conf.get_settings import get_settings
80+
from hathor.conf.get_settings import get_global_settings
8181
from hathor.debug_resources import (
8282
DebugCrashResource,
8383
DebugLogResource,
@@ -142,7 +142,7 @@ def create_resources(self) -> server.Site:
142142
)
143143
from hathor.websocket import HathorAdminWebsocketFactory, WebsocketStatsResource
144144

145-
settings = get_settings()
145+
settings = get_global_settings()
146146
cpu = get_cpu_profiler()
147147

148148
# TODO get this from a file. How should we do with the factory?

hathor/cli/db_export.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def register_signal_handlers(self) -> None:
3434

3535
@classmethod
3636
def create_parser(cls) -> ArgumentParser:
37-
from hathor.conf.get_settings import get_settings
38-
settings = get_settings()
37+
from hathor.conf.get_settings import get_global_settings
38+
settings = get_global_settings()
3939

4040
def max_height(arg: str) -> Optional[int]:
4141
if arg.lower() == 'checkpoint':
@@ -80,8 +80,8 @@ def prepare(self, *, register_resources: bool = True) -> None:
8080
self.skip_voided = self._args.export_skip_voided
8181

8282
def iter_tx(self) -> Iterator['BaseTransaction']:
83-
from hathor.conf.get_settings import get_settings
84-
settings = get_settings()
83+
from hathor.conf.get_settings import get_global_settings
84+
settings = get_global_settings()
8585
soft_voided_ids = set(settings.SOFT_VOIDED_TX_IDS)
8686

8787
for tx in self._iter_tx:

hathor/cli/events_simulator/scenario.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def simulate_single_chain_one_block(simulator: 'Simulator', manager: 'HathorMana
5252

5353

5454
def simulate_single_chain_blocks_and_transactions(simulator: 'Simulator', manager: 'HathorManager') -> None:
55-
from hathor.conf.get_settings import get_settings
55+
from hathor.conf.get_settings import get_global_settings
5656
from hathor.simulator.utils import add_new_blocks, gen_new_tx
5757

58-
settings = get_settings()
58+
settings = get_global_settings()
5959
assert manager.wallet is not None
6060
address = manager.wallet.get_unused_address(mark_as_used=False)
6161

@@ -97,11 +97,11 @@ def simulate_reorg(simulator: 'Simulator', manager: 'HathorManager') -> None:
9797

9898

9999
def simulate_unvoided_transaction(simulator: 'Simulator', manager: 'HathorManager') -> None:
100-
from hathor.conf.get_settings import get_settings
100+
from hathor.conf.get_settings import get_global_settings
101101
from hathor.simulator.utils import add_new_block, add_new_blocks, gen_new_tx
102102
from hathor.util import not_none
103103

104-
settings = get_settings()
104+
settings = get_global_settings()
105105
assert manager.wallet is not None
106106
address = manager.wallet.get_unused_address(mark_as_used=False)
107107

hathor/cli/mining.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ def execute(args: Namespace) -> None:
135135
block.nonce, block.weight))
136136

137137
try:
138-
from hathor.conf.get_settings import get_settings
138+
from hathor.conf.get_settings import get_global_settings
139139
from hathor.daa import DifficultyAdjustmentAlgorithm
140140
from hathor.verification.verification_service import VerificationService, VertexVerifiers
141-
settings = get_settings()
141+
settings = get_global_settings()
142142
daa = DifficultyAdjustmentAlgorithm(settings=settings)
143143
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa)
144144
verification_service = VerificationService(verifiers=verifiers)

hathor/cli/nginx_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def generate_nginx_config(openapi: dict[str, Any], *, out_file: TextIO, rate_k:
114114
"""
115115
from datetime import datetime
116116

117-
from hathor.conf.get_settings import get_settings
117+
from hathor.conf.get_settings import get_global_settings
118118

119-
settings = get_settings()
119+
settings = get_global_settings()
120120
api_prefix = settings.API_VERSION_PREFIX
121121

122122
locations: dict[str, dict[str, Any]] = {}

hathor/cli/run_node.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def prepare(self, *, register_resources: bool = True) -> None:
162162
assert self.manager.stratum_factory is not None
163163
self.reactor.listenTCP(self._args.stratum, self.manager.stratum_factory)
164164

165-
from hathor.conf.get_settings import get_settings
166-
settings = get_settings()
165+
from hathor.conf.get_settings import get_global_settings
166+
settings = get_global_settings()
167167

168168
if register_resources:
169169
resources_builder = ResourcesBuilder(
@@ -208,8 +208,8 @@ def start_sentry_if_possible(self) -> None:
208208
sys.exit(-3)
209209

210210
import hathor
211-
from hathor.conf.get_settings import get_settings
212-
settings = get_settings()
211+
from hathor.conf.get_settings import get_global_settings
212+
settings = get_global_settings()
213213
sentry_sdk.init(
214214
dsn=self._args.sentry_dsn,
215215
release=hathor.__version__,
@@ -270,8 +270,8 @@ def check_unsafe_arguments(self) -> None:
270270
'',
271271
]
272272

273-
from hathor.conf.get_settings import get_settings
274-
settings = get_settings()
273+
from hathor.conf.get_settings import get_global_settings
274+
settings = get_global_settings()
275275

276276
if self._args.unsafe_mode != settings.NETWORK_NAME:
277277
message.extend([
@@ -351,7 +351,7 @@ def check_python_version(self) -> None:
351351
def __init__(self, *, argv=None):
352352
from hathor.cli.run_node_args import RunNodeArgs
353353
from hathor.conf import TESTNET_SETTINGS_FILEPATH
354-
from hathor.conf.get_settings import get_settings
354+
from hathor.conf.get_settings import get_global_settings
355355
self.log = logger.new()
356356

357357
if argv is None:
@@ -369,7 +369,7 @@ def __init__(self, *, argv=None):
369369
os.environ['HATHOR_CONFIG_YAML'] = TESTNET_SETTINGS_FILEPATH
370370

371371
try:
372-
get_settings()
372+
get_global_settings()
373373
except (TypeError, ValidationError) as e:
374374
from hathor.exception import PreInitializationError
375375
raise PreInitializationError(

hathor/conf/get_settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class _SettingsMetadata(NamedTuple):
3333
_settings_singleton: Optional[_SettingsMetadata] = None
3434

3535

36-
def get_settings() -> Settings:
36+
def get_global_settings() -> Settings:
3737
return HathorSettings()
3838

3939

hathor/consensus/block_consensus.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from structlog import get_logger
1919

20-
from hathor.conf.get_settings import get_settings
20+
from hathor.conf.get_settings import get_global_settings
2121
from hathor.profiler import get_cpu_profiler
2222
from hathor.transaction import BaseTransaction, Block, Transaction, sum_weights
2323
from hathor.util import classproperty, not_none
@@ -35,7 +35,7 @@ class BlockConsensusAlgorithm:
3535
"""Implement the consensus algorithm for blocks."""
3636

3737
def __init__(self, context: 'ConsensusAlgorithmContext') -> None:
38-
self._settings = get_settings()
38+
self._settings = get_global_settings()
3939
self.context = context
4040

4141
@classproperty

hathor/consensus/consensus.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from structlog import get_logger
1616

17-
from hathor.conf.get_settings import get_settings
17+
from hathor.conf.get_settings import get_global_settings
1818
from hathor.consensus.block_consensus import BlockConsensusAlgorithmFactory
1919
from hathor.consensus.context import ConsensusAlgorithmContext
2020
from hathor.consensus.transaction_consensus import TransactionConsensusAlgorithmFactory
@@ -56,7 +56,7 @@ class ConsensusAlgorithm:
5656
"""
5757

5858
def __init__(self, soft_voided_tx_ids: set[bytes], pubsub: PubSubManager) -> None:
59-
self._settings = get_settings()
59+
self._settings = get_global_settings()
6060
self.log = logger.new()
6161
self._pubsub = pubsub
6262
self.soft_voided_tx_ids = frozenset(soft_voided_tx_ids)

hathor/consensus/transaction_consensus.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from structlog import get_logger
1818

19-
from hathor.conf.get_settings import get_settings
19+
from hathor.conf.get_settings import get_global_settings
2020
from hathor.profiler import get_cpu_profiler
2121
from hathor.transaction import BaseTransaction, Block, Transaction, TxInput, sum_weights
2222
from hathor.util import classproperty
@@ -34,7 +34,7 @@ class TransactionConsensusAlgorithm:
3434
"""Implement the consensus algorithm for transactions."""
3535

3636
def __init__(self, context: 'ConsensusAlgorithmContext') -> None:
37-
self._settings = get_settings()
37+
self._settings = get_global_settings()
3838
self.context = context
3939

4040
@classproperty

hathor/crypto/util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
load_der_private_key,
2828
)
2929

30-
from hathor.conf.get_settings import get_settings
30+
from hathor.conf.get_settings import get_global_settings
3131
from hathor.util import not_none
3232

3333
_BACKEND = default_backend()
@@ -129,7 +129,7 @@ def get_address_from_public_key_hash(public_key_hash: bytes, version_byte: Optio
129129
:return: address in bytes
130130
:rtype: bytes
131131
"""
132-
settings = get_settings()
132+
settings = get_global_settings()
133133
address = b''
134134
actual_version_byte: bytes = version_byte if version_byte is not None else settings.P2PKH_VERSION_BYTE
135135
# Version byte
@@ -208,7 +208,7 @@ def get_address_b58_from_redeem_script_hash(redeem_script_hash: bytes, version_b
208208
:return: address in base 58
209209
:rtype: string
210210
"""
211-
settings = get_settings()
211+
settings = get_global_settings()
212212
actual_version_byte: bytes = version_byte if version_byte is not None else settings.MULTISIG_VERSION_BYTE
213213
address = get_address_from_redeem_script_hash(redeem_script_hash, actual_version_byte)
214214
return base58.b58encode(address).decode('utf-8')
@@ -226,7 +226,7 @@ def get_address_from_redeem_script_hash(redeem_script_hash: bytes, version_byte:
226226
:return: address in bytes
227227
:rtype: bytes
228228
"""
229-
settings = get_settings()
229+
settings = get_global_settings()
230230
actual_version_byte: bytes = version_byte if version_byte is not None else settings.MULTISIG_VERSION_BYTE
231231
address = b''
232232
# Version byte

hathor/graphviz.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
from graphviz import Digraph
2020

21-
from hathor.conf.get_settings import get_settings
21+
from hathor.conf.get_settings import get_global_settings
2222
from hathor.transaction import BaseTransaction
2323
from hathor.transaction.storage import TransactionStorage
2424

2525

2626
class GraphvizVisualizer:
2727
def __init__(self, storage: TransactionStorage, include_funds: bool = False,
2828
include_verifications: bool = False, only_blocks: bool = False):
29-
self._settings = get_settings()
29+
self._settings = get_global_settings()
3030
self.storage = storage
3131

3232
# Indicate whether it should show fund edges

hathor/indexes/base_index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from structlog import get_logger
1919

20-
from hathor.conf.get_settings import get_settings
20+
from hathor.conf.get_settings import get_global_settings
2121
from hathor.indexes.scope import Scope
2222
from hathor.transaction.base_transaction import BaseTransaction
2323

@@ -34,7 +34,7 @@ class BaseIndex(ABC):
3434
created to generalize how we initialize indexes and keep track of which ones are up-to-date.
3535
"""
3636
def __init__(self) -> None:
37-
self._settings = get_settings()
37+
self._settings = get_global_settings()
3838
self.log = logger.new()
3939

4040
def init_start(self, indexes_manager: 'IndexesManager') -> None:

hathor/indexes/rocksdb_tokens_index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from structlog import get_logger
2020

21-
from hathor.conf.get_settings import get_settings
21+
from hathor.conf.get_settings import get_global_settings
2222
from hathor.indexes.rocksdb_utils import (
2323
InternalUid,
2424
RocksDBIndexUtils,
@@ -85,7 +85,7 @@ class RocksDBTokensIndex(TokensIndex, RocksDBIndexUtils):
8585
"""
8686

8787
def __init__(self, db: 'rocksdb.DB', *, cf_name: Optional[bytes] = None) -> None:
88-
self._settings = get_settings()
88+
self._settings = get_global_settings()
8989
self.log = logger.new()
9090
RocksDBIndexUtils.__init__(self, db, cf_name or _CF_NAME_TOKENS_INDEX)
9191

hathor/indexes/rocksdb_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from collections.abc import Collection
1616
from typing import TYPE_CHECKING, Iterable, Iterator, NewType
1717

18-
from hathor.conf.get_settings import get_settings
18+
from hathor.conf.get_settings import get_global_settings
1919

2020
if TYPE_CHECKING: # pragma: no cover
2121
import rocksdb
@@ -30,7 +30,7 @@
3030

3131
def to_internal_token_uid(token_uid: bytes) -> InternalUid:
3232
"""Normalizes a token_uid so that the native token (\x00) will have the same length as custom tokens."""
33-
settings = get_settings()
33+
settings = get_global_settings()
3434
if token_uid == settings.HATHOR_TOKEN_UID:
3535
return _INTERNAL_HATHOR_TOKEN_UID
3636
assert len(token_uid) == 32
@@ -40,7 +40,7 @@ def to_internal_token_uid(token_uid: bytes) -> InternalUid:
4040
def from_internal_token_uid(token_uid: InternalUid) -> bytes:
4141
"""De-normalizes the token_uid so that the native token is b'\x00' as expected"""
4242
assert len(token_uid) == 32
43-
settings = get_settings()
43+
settings = get_global_settings()
4444
if token_uid == _INTERNAL_HATHOR_TOKEN_UID:
4545
return settings.HATHOR_TOKEN_UID
4646
return token_uid

hathor/indexes/utxo_index.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from structlog import get_logger
2020

21-
from hathor.conf.get_settings import get_settings
21+
from hathor.conf.get_settings import get_global_settings
2222
from hathor.indexes.base_index import BaseIndex
2323
from hathor.indexes.scope import Scope
2424
from hathor.transaction import BaseTransaction, Block, TxOutput
@@ -60,7 +60,7 @@ def __repr__(self):
6060
@classmethod
6161
def from_tx_output(cls, tx: BaseTransaction, index: int, tx_output: TxOutput) -> 'UtxoIndexItem':
6262
assert tx.hash is not None
63-
settings = get_settings()
63+
settings = get_global_settings()
6464

6565
if tx_output.is_token_authority():
6666
raise ValueError('UtxoIndexItem cannot be used with a token authority output')
@@ -206,7 +206,7 @@ def iter_utxos(self, *, address: str, target_amount: int, token_uid: Optional[by
206206
target_height: Optional[int] = None) -> Iterator[UtxoIndexItem]:
207207
""" Search UTXOs for a given token_uid+address+target_value, if no token_uid is given, HTR is assumed.
208208
"""
209-
settings = get_settings()
209+
settings = get_global_settings()
210210
actual_token_uid = token_uid if token_uid is not None else settings.HATHOR_TOKEN_UID
211211
iter_nolock = self._iter_utxos_nolock(token_uid=actual_token_uid, address=address,
212212
target_amount=target_amount)

0 commit comments

Comments
 (0)