Skip to content

Commit

Permalink
Merge pull request #2739 from CounterpartyXCP/develop
Browse files Browse the repository at this point in the history
v10.7.2-alpha.1
  • Loading branch information
ouziel-slama authored Nov 19, 2024
2 parents 0c67b18 + 77b8f5a commit e5a0e74
Show file tree
Hide file tree
Showing 54 changed files with 6,040 additions and 5,433 deletions.
3,988 changes: 2,021 additions & 1,967 deletions apiary.apib

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion counterparty-core/counterpartycore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def float_range_checker(arg):
},
],
[
("--check-asset-conservation",),
("--skip-asset-conservation-check",),
{
"action": "store_true",
"default": False,
Expand Down Expand Up @@ -475,6 +475,10 @@ def main():
parser.print_help()
exit(0)

if args.action is None:
parser.print_help()
exit(1)

# Configuration and logging
server.initialise_log_and_config(args)

Expand Down
2 changes: 0 additions & 2 deletions counterparty-core/counterpartycore/lib/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def pack(address):
script.validate(address) # This will check if the address is valid
short_address_bytes = bitcoin.base58.decode(address)[:-4]
return short_address_bytes
except bitcoin.base58.InvalidBase58Error as e:
raise e
except Exception as e: # noqa: F841
raise script.AddressError( # noqa: B904
f"The address {address} is not a valid bitcoin address ({'testnet' if config.TESTNET or config.REGTEST else 'mainnet'})"
Expand Down
24 changes: 20 additions & 4 deletions counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,35 @@ def init_flask_app():
# Get the last block index
with APIDBConnectionPool().connection() as db:
util.CURRENT_BLOCK_INDEX = ledger.last_db_index(db)
methods = ["OPTIONS", "GET"]
# Add routes
app.add_url_rule("/v2/", view_func=handle_route, strict_slashes=False)
app.add_url_rule(
"/v2/blueprint", view_func=handle_doc, methods=["GET"], strict_slashes=False
"/v2/",
view_func=handle_route,
methods=methods,
strict_slashes=False,
provide_automatic_options=False,
)
app.add_url_rule(
"/v2/blueprint",
view_func=handle_doc,
methods=methods,
strict_slashes=False,
provide_automatic_options=False,
)

for path in ROUTES:
methods = ["OPTIONS", "GET"]
if path == "/v2/bitcoin/transactions":
methods = ["OPTIONS", "POST"]
if not path.startswith("/v2/"):
methods = ["OPTIONS", "GET", "POST"]
app.add_url_rule(path, view_func=handle_route, methods=methods, strict_slashes=False)
app.add_url_rule(
path,
view_func=handle_route,
methods=methods,
strict_slashes=False,
provide_automatic_options=False,
)

app.register_error_handler(404, handle_not_found)

Expand Down
31 changes: 31 additions & 0 deletions counterparty-core/counterpartycore/lib/api/api_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ def get_event_previous_state(api_db, event):
return previous_state


def get_event_count(api_db, event):
cursor = api_db.cursor()
cursor.execute("SELECT count FROM events_count WHERE event = ?", (event["event"],))
count = cursor.fetchone()
if count is None:
return None
return count["count"]


def increment_event_count(api_db, event):
current_count = get_event_count(api_db, event)
cursor = api_db.cursor()
if current_count is None:
cursor.execute("INSERT INTO events_count (event, count) VALUES (?, 1)", (event["event"],))
else:
cursor.execute(
"UPDATE events_count SET count = count + 1 WHERE event = ?", (event["event"],)
)


def decrement_event_count(api_db, event):
current_count = get_event_count(api_db, event)
if current_count is None or current_count == 0:
return
cursor = api_db.cursor()
cursor.execute("UPDATE events_count SET count = count - 1 WHERE event = ?", (event["event"],))


def insert_event(api_db, event):
previous_state = get_event_previous_state(api_db, event)
if previous_state is not None:
Expand All @@ -227,6 +255,7 @@ def insert_event(api_db, event):
"""
cursor = api_db.cursor()
cursor.execute(sql, event)
increment_event_count(api_db, event)


def rollback_event(api_db, event):
Expand All @@ -235,6 +264,7 @@ def rollback_event(api_db, event):
if event["event"] in SKIP_EVENTS:
sql = "DELETE FROM messages WHERE message_index = ?"
delete_all(api_db, sql, (event["message_index"],))
decrement_event_count(api_db, event)
return
if event["previous_state"] is None or event["previous_state"] == "null":
sql = f"DELETE FROM {event['category']} WHERE rowid = ?" # noqa: S608
Expand Down Expand Up @@ -273,6 +303,7 @@ def rollback_event(api_db, event):

sql = "DELETE FROM messages WHERE message_index = ?"
delete_all(api_db, sql, (event["message_index"],))
decrement_event_count(api_db, event)


def rollback_events(api_db, block_index):
Expand Down
Empty file.
21 changes: 14 additions & 7 deletions counterparty-core/counterpartycore/lib/api/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,17 @@ def info(db, rawtransaction: str, block_index: int = None):
except Exception as e:
raise exceptions.ComposeError("Invalid rawtransaction") from e

source, destination, btc_amount, fee, data, _dispensers_outs, _utxos_info = (
gettxinfo.get_tx_info(
db,
decoded_tx,
block_index=block_index,
try:
source, destination, btc_amount, fee, data, _dispensers_outs, _utxos_info = (
gettxinfo.get_tx_info(
db,
decoded_tx,
block_index=block_index,
)
)
)
except exceptions.BitcoindRPCError:
source, destination, btc_amount, fee, data = None, None, None, None, None

del decoded_tx["__data__"]
result = {
"source": source,
Expand All @@ -803,7 +807,10 @@ def unpack(db, datahex: str, block_index: int = None):
:param datahex: Data in hex format (e.g. 020000000001016a65c1624e53f4d33ce02e726a6606faed60cc014d5b1a578ba3e09b4b3f8f890100000000ffffffff020000000000000000176a150d55e8b6118808b7b663b365473f142274028b8af60245092701000000160014a3df8a5a83d4e2827b59b43f5ce6ce5d2e52093f0247304402204b7a2859cbce34e725a1132fec2dd4b075503dadff0a0c407ae7c22a7712fe4d0220563ceb2ceebdf649343bb24819fc808639cce7781305b4588ffbe4a20390d2780121020ace9adf60fe4ec05dab922ccdc5727cbf664cafc7cdb845de534855266314c800000000)
:param block_index: Block index of the transaction containing this data
"""
data = binascii.unhexlify(datahex)
try:
data = binascii.unhexlify(datahex)
except Exception as e: # noqa
raise exceptions.UnpackError("Data must be in hexadecimal format") from e
if data[: len(config.PREFIX)] == config.PREFIX:
data = data[len(config.PREFIX) :]
message_type_id, message = message_type.unpack(data)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# file: counterpartycore/lib/api/migrations/0016.fix2_asset_longname_field.py
#
import logging

from counterpartycore.lib import config
from yoyo import step

logger = logging.getLogger(config.LOGGER_NAME)

__depends__ = {"0015.fix_asset_longname_field"}


def dict_factory(cursor, row):
fields = [column[0] for column in cursor.description]
return {key: value for key, value in zip(fields, row)}


def apply(db):
logger.info("Update `asset_longname` field...")
db.row_factory = dict_factory

cursor = db.cursor()
cursor.execute("UPDATE fairminters SET asset_longname = NULL WHERE asset_longname = ''")
cursor.execute("UPDATE fairminters SET asset_parent = NULL WHERE asset_parent = ''")
cursor.execute("UPDATE issuances SET asset_longname = NULL WHERE asset_longname = ''")
cursor.execute("UPDATE assets_info SET asset_longname = NULL WHERE asset_longname = ''")

logger.info("`asset_longname` field updated...")


def rollback(db):
pass


steps = [step(apply, rollback)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- depends: 0016.fix2_asset_longname_field
CREATE TABLE IF NOT EXISTS events_count(
event TEXT PRIMARY KEY,
count INTEGER);
CREATE INDEX IF NOT EXISTS events_count_count_idx ON events_count (count);

INSERT INTO events_count (event, count)
SELECT event, COUNT(*) AS counter
FROM messages
GROUP BY event;
Loading

0 comments on commit e5a0e74

Please sign in to comment.