Skip to content

Commit

Permalink
remove _ from files names
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 15, 2025
1 parent d75e8dc commit cbc0580
Show file tree
Hide file tree
Showing 47 changed files with 139 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ledger,
util,
)
from counterpartycore.lib.api import api_watcher, dbbuilder, queries, wsgi
from counterpartycore.lib.api import apiwatcher, dbbuilder, queries, wsgi
from counterpartycore.lib.api.routes import ROUTES
from counterpartycore.lib.api.util import (
clean_rowids_and_confirmed_fields,
Expand Down Expand Up @@ -86,7 +86,7 @@ def api_root():
network = "regtest"

with StateDBConnectionPool().connection() as state_db:
counterparty_height = api_watcher.get_last_block_parsed(state_db)
counterparty_height = apiwatcher.get_last_block_parsed(state_db)

backend_height = util.CURRENT_BACKEND_HEIGHT
if backend_height is None:
Expand Down Expand Up @@ -243,7 +243,7 @@ def prepare_args(route, **kwargs):
def execute_api_function(rule, route, function_args):
# cache everything for one block
with StateDBConnectionPool().connection() as state_db:
current_block_index = api_watcher.get_last_block_parsed(state_db)
current_block_index = apiwatcher.get_last_block_parsed(state_db)
cache_key = f"{current_block_index}:{request.url}"
# except for blocks and transactions cached forever
if (
Expand Down Expand Up @@ -490,7 +490,7 @@ def check_database_version(state_db):
database.update_version(state_db)


def run_api_server(args, server_ready_value, stop_event, parent_pid):
def run_apiserver(args, server_ready_value, stop_event, parent_pid):
logger.info("Starting API Server process...")

def handle_interrupt_signal(signum, frame):
Expand All @@ -517,7 +517,7 @@ def handle_interrupt_signal(signum, frame):
)
check_database_version(state_db)

watcher = api_watcher.APIWatcher(state_db)
watcher = apiwatcher.APIWatcher(state_db)
watcher.start()

app = init_flask_app()
Expand Down Expand Up @@ -597,7 +597,7 @@ def start(self, args):
raise Exception("API Server is already running")
self.process = Process(
name="API",
target=run_api_server,
target=run_apiserver,
args=(vars(args), self.server_ready_value, self.stop_event, os.getpid()),
)
self.process.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)
from counterpartycore.lib.api import composer
from counterpartycore.lib.api import util as api_util
from counterpartycore.lib.api.api_watcher import STATE_DB_TABLES
from counterpartycore.lib.api.apiwatcher import STATE_DB_TABLES
from counterpartycore.lib.messages import (
bet, # noqa: F401
broadcast, # noqa: F401
Expand All @@ -51,14 +51,14 @@
send,
sweep, # noqa: F401
)
from counterpartycore.lib.messages.versions import enhanced_send # noqa: E402
from counterpartycore.lib.messages.versions import enhancedsend # noqa: E402
from counterpartycore.lib.monitors import sentry
from counterpartycore.lib.monitors.telemetry.util import ( # noqa: E402
get_uptime,
is_docker,
is_force_enabled,
)
from counterpartycore.lib.parser import deserialize, gettxinfo, message_type
from counterpartycore.lib.parser import deserialize, gettxinfo, messagetype
from counterpartycore.lib.utils import helpers
from counterpartycore.lib.utils.database import LedgerDBConnectionPool, StateDBConnectionPool

Expand Down Expand Up @@ -1004,14 +1004,14 @@ def get_tx_info(tx_hex, block_index=None):
@dispatcher.add_method
def unpack(data_hex):
data = binascii.unhexlify(data_hex)
message_type_id, message = message_type.unpack(data)
message_type_id, message = messagetype.unpack(data)

# TODO: Enabled only for `send`.
if message_type_id == send.ID:
with LedgerDBConnectionPool().connection() as db:
unpacked = send.unpack(db, message, util.CURRENT_BLOCK_INDEX)
elif message_type_id == enhanced_send.ID:
unpacked = enhanced_send.unpack(message, util.CURRENT_BLOCK_INDEX)
elif message_type_id == enhancedsend.ID:
unpacked = enhancedsend.unpack(message, util.CURRENT_BLOCK_INDEX)
else:
raise APIError("unsupported message type")
return message_type_id, unpacked
Expand Down
8 changes: 4 additions & 4 deletions counterparty-core/counterpartycore/lib/api/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from counterpartycore.lib.api import composer
from counterpartycore.lib.messages import gas
from counterpartycore.lib.messages.attach import ID as UTXO_ID
from counterpartycore.lib.parser import deserialize, gettxinfo, message_type
from counterpartycore.lib.parser import deserialize, gettxinfo, messagetype

D = decimal.Decimal

Expand Down Expand Up @@ -610,7 +610,7 @@ def unpack(db, datahex: str, block_index: int = None):

if data[: len(config.PREFIX)] == config.PREFIX:
data = data[len(config.PREFIX) :]
message_type_id, message = message_type.unpack(data)
message_type_id, message = messagetype.unpack(data)
block_index = block_index or util.CURRENT_BLOCK_INDEX

issuance_ids = [
Expand Down Expand Up @@ -670,9 +670,9 @@ def unpack(db, datahex: str, block_index: int = None):
message_type_name = "send"
message_data = messages.send.unpack(db, message, block_index)
# Enhanced send
elif message_type_id == messages.versions.enhanced_send.ID:
elif message_type_id == messages.versions.enhancedsend.ID:
message_type_name = "enhanced_send"
message_data = messages.versions.enhanced_send.unpack(message, block_index)
message_data = messages.versions.enhancedsend.unpack(message, block_index)
# MPMA send
elif message_type_id == messages.versions.mpma.ID:
message_type_name = "mpma_send"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time

from counterpartycore.lib import config
from counterpartycore.lib.api.api_watcher import EVENTS_ADDRESS_FIELDS, update_address_events
from counterpartycore.lib.api.apiwatcher import EVENTS_ADDRESS_FIELDS, update_address_events
from yoyo import step

logger = logging.getLogger(config.LOGGER_NAME)
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def get_routes():
return ROUTES


# Define the API routes except root (`/`) defined in `api_server.py`
# Define the API routes except root (`/`) defined in `apiserver.py`
ROUTES = util.prepare_routes(
{
### /blocks ###
Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/api/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from werkzeug.serving import make_server

from counterpartycore.lib import config, ledger, util
from counterpartycore.lib.api import api_watcher
from counterpartycore.lib.api import apiwatcher
from counterpartycore.lib.api.util import BackendHeight
from counterpartycore.lib.cli import log
from counterpartycore.lib.utils import database
Expand All @@ -25,7 +25,7 @@


def refresh_current_state(ledger_db, state_db):
util.CURRENT_BLOCK_INDEX = api_watcher.get_last_block_parsed(state_db)
util.CURRENT_BLOCK_INDEX = apiwatcher.get_last_block_parsed(state_db)
util.CURRENT_BACKEND_HEIGHT = BackendHeight().get()
if util.CURRENT_BLOCK_INDEX:
last_block = ledger.ledger.get_block(ledger_db, util.CURRENT_BLOCK_INDEX)
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/cli/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from termcolor import colored, cprint

from counterpartycore.lib import config
from counterpartycore.lib.cli.public_keys import PUBLIC_KEYS
from counterpartycore.lib.cli.publickeys import PUBLIC_KEYS


def download_zst(data_dir, zst_url):
Expand Down
26 changes: 13 additions & 13 deletions counterparty-core/counterpartycore/lib/cli/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
exceptions,
ledger,
)
from counterpartycore.lib.api import api_server as api_v2
from counterpartycore.lib.api import api_v1, dbbuilder
from counterpartycore.lib.api import apiserver as api_v2
from counterpartycore.lib.api import apiv1, dbbuilder
from counterpartycore.lib.cli import bootstrap, log
from counterpartycore.lib.parser import blocks, check, follow
from counterpartycore.lib.utils import database, helpers
Expand Down Expand Up @@ -648,8 +648,8 @@ def stop(self):

def start_all(args):
api_status_poller = None
api_server_v1 = None
api_server_v2 = None
apiserver_v1 = None
apiserver_v2 = None
follower_daemon = None
asset_conservation_checker = None
db = None
Expand Down Expand Up @@ -689,24 +689,24 @@ def start_all(args):

# API Server v2
api_stop_event = multiprocessing.Event()
api_server_v2 = api_v2.APIServer(api_stop_event)
api_server_v2.start(args)
while not api_server_v2.is_ready() and not api_server_v2.has_stopped():
apiserver_v2 = api_v2.APIServer(api_stop_event)
apiserver_v2.start(args)
while not apiserver_v2.is_ready() and not apiserver_v2.has_stopped():
logger.trace("Waiting for API server to start...")
time.sleep(0.1)

# Backend
connect_to_backend()

# API Status Poller
api_status_poller = api_v1.APIStatusPoller()
api_status_poller = apiv1.APIStatusPoller()
api_status_poller.daemon = True
api_status_poller.start()

# API Server v1
api_server_v1 = api_v1.APIServer()
api_server_v1.daemon = True
api_server_v1.start()
apiserver_v1 = apiv1.APIServer()
apiserver_v1.daemon = True
apiserver_v1.start()

# delete blocks with no ledger hashes
# in case of reparse interrupted
Expand Down Expand Up @@ -739,8 +739,8 @@ def start_all(args):
api_stop_event.set()
if api_status_poller:
api_status_poller.stop()
if api_server_v1:
api_server_v1.stop()
if apiserver_v1:
apiserver_v1.stop()
if follower_daemon:
follower_daemon.stop()
if asset_conservation_checker:
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/messages/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from counterpartycore.lib import config, exceptions, ledger, util
from counterpartycore.lib.messages import gas
from counterpartycore.lib.messages.utils import address
from counterpartycore.lib.parser import utxosinfo
from counterpartycore.lib.utils import address

logger = logging.getLogger(config.LOGGER_NAME)

Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/bet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ledger,
util,
)
from counterpartycore.lib.parser import message_type, protocol
from counterpartycore.lib.parser import messagetype, protocol
from counterpartycore.lib.utils import database, helpers

D = decimal.Decimal
Expand Down Expand Up @@ -407,7 +407,7 @@ def compose(
if problems and not skip_validation:
raise exceptions.ComposeError(problems)

data = message_type.pack(ID)
data = messagetype.pack(ID)
data += struct.pack(
FORMAT,
bet_type,
Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
ledger,
util,
)
from counterpartycore.lib.parser import message_type, protocol
from counterpartycore.lib.parser import messagetype, protocol
from counterpartycore.lib.utils import database, helpers

from . import bet
Expand Down Expand Up @@ -174,7 +174,7 @@ def compose(
if problems and not skip_validation:
raise exceptions.ComposeError(problems)

data = message_type.pack(ID)
data = messagetype.pack(ID)

# always use custom length byte instead of problematic usage of 52p format and make sure to encode('utf-8') for length
if protocol.enabled("broadcast_pack_text"):
Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/btcpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ledger,
util,
)
from counterpartycore.lib.parser import message_type, protocol
from counterpartycore.lib.parser import messagetype, protocol
from counterpartycore.lib.utils import database, helpers

logger = logging.getLogger(config.LOGGER_NAME)
Expand Down Expand Up @@ -127,7 +127,7 @@ def compose(db, source: str, order_match_id: str, skip_validation: bool = False)
binascii.unhexlify(bytes(tx0_hash, "utf-8")),
binascii.unhexlify(bytes(tx1_hash, "utf-8")),
)
data = message_type.pack(ID)
data = messagetype.pack(ID)
data += struct.pack(FORMAT, tx0_hash_bytes, tx1_hash_bytes)
return (source, [(destination, btc_quantity)], data)

Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import struct

from counterpartycore.lib import config, exceptions, ledger
from counterpartycore.lib.parser import message_type
from counterpartycore.lib.parser import messagetype
from counterpartycore.lib.utils import database

from . import bet, order
Expand Down Expand Up @@ -85,7 +85,7 @@ def compose(db, source: str, offer_hash: str, skip_validation: bool = False):
raise exceptions.ComposeError(problems)

offer_hash_bytes = binascii.unhexlify(bytes(offer_hash, "utf-8"))
data = message_type.pack(ID)
data = messagetype.pack(ID)
data += struct.pack(FORMAT, offer_hash_bytes)
return (source, [], data)

Expand Down
7 changes: 3 additions & 4 deletions counterparty-core/counterpartycore/lib/messages/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from counterpartycore.lib import config, ledger, util
from counterpartycore.lib.exceptions import * # noqa: F403
from counterpartycore.lib.exceptions import AddressError
from counterpartycore.lib.messages.utils import address
from counterpartycore.lib.parser import message_type
from counterpartycore.lib.utils import database
from counterpartycore.lib.parser import messagetype
from counterpartycore.lib.utils import address, database

logger = logging.getLogger(config.LOGGER_NAME)

Expand Down Expand Up @@ -61,7 +60,7 @@ def initialise(db):


def pack(db, asset, quantity, tag):
data = message_type.pack(ID)
data = messagetype.pack(ID)
if isinstance(tag, str):
tag = bytes(tag.encode("utf8"))[0:MAX_TAG_LENGTH]
elif isinstance(tag, bytes):
Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/detach.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import struct

from counterpartycore.lib import config, exceptions, ledger
from counterpartycore.lib.messages.utils import address
from counterpartycore.lib.parser import utxosinfo
from counterpartycore.lib.utils import address

logger = logging.getLogger(config.LOGGER_NAME)

Expand Down Expand Up @@ -38,7 +38,7 @@ def compose(db, source, destination=None, skip_validation=False):
if destination is not None:
data_content = destination.encode("utf-8")
else:
data_content = b"0" # not empty to avoid a protocol change in `message_type.unpack()`
data_content = b"0" # not empty to avoid a protocol change in `messagetype.unpack()`
data += struct.pack(f">{len(data_content)}s", data_content)

return (source, [], data)
Expand Down
8 changes: 4 additions & 4 deletions counterparty-core/counterpartycore/lib/messages/dispenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
ledger,
util,
)
from counterpartycore.lib.messages.utils.address import pack as address_pack
from counterpartycore.lib.messages.utils.address import unpack as address_unpack
from counterpartycore.lib.parser import message_type, protocol
from counterpartycore.lib.parser import messagetype, protocol
from counterpartycore.lib.utils import database, helpers
from counterpartycore.lib.utils.address import pack as address_pack
from counterpartycore.lib.utils.address import unpack as address_unpack

logger = logging.getLogger(config.LOGGER_NAME)

Expand Down Expand Up @@ -473,7 +473,7 @@ def compose(
assetid = ledger.ledger.generate_asset_id(asset, block_index=util.CURRENT_BLOCK_INDEX)

destination = []
data = message_type.pack(ID)
data = messagetype.pack(ID)
data += struct.pack(FORMAT, assetid, give_quantity, escrow_quantity, mainchainrate, status)
if (status == STATUS_OPEN_EMPTY_ADDRESS and open_address) or (
protocol.enabled("dispenser_origin_permission_extended")
Expand Down
Loading

0 comments on commit cbc0580

Please sign in to comment.