From 8e61090a2530b7bf5f81ed9947628c28623c82a6 Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Sat, 4 Jan 2025 16:21:22 +0000 Subject: [PATCH] Fix transaction_type field --- .../counterpartycore/lib/blocks.py | 23 +++++++++++++------ .../counterpartycore/lib/gettxinfo.py | 4 +++- .../counterpartycore/lib/message_type.py | 10 +++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/counterparty-core/counterpartycore/lib/blocks.py b/counterparty-core/counterpartycore/lib/blocks.py index 07fca77aa0..b976967a2e 100644 --- a/counterparty-core/counterpartycore/lib/blocks.py +++ b/counterparty-core/counterpartycore/lib/blocks.py @@ -429,22 +429,24 @@ def parse_block( return None, None, None -def update_transaction_type(db): +def update_transaction_type(db, fix_utxo_move=False): start = time.time() logger.info("Updating `transaction_type` column in `transactions` table...") with db: cursor = db.cursor() - cursor.execute("ALTER TABLE transactions ADD COLUMN transaction_type TEXT") - cursor.execute( - "SELECT tx_index, destination, block_index, data, supported FROM transactions" - ) + if not fix_utxo_move: + cursor.execute("ALTER TABLE transactions ADD COLUMN transaction_type TEXT") + sql = "SELECT tx_index, destination, block_index, data, utxos_info, supported FROM transactions" + if fix_utxo_move: + sql += " WHERE transaction_type = 'utxomove'" + cursor.execute(sql) counter = 0 for tx in cursor.fetchall(): transaction_type = "unknown" if tx["supported"]: transaction_type = message_type.get_transaction_type( - tx["data"], tx["destination"], tx["block_index"] + tx["data"], tx["destination"], tx["utxos_info"].split(" "), tx["block_index"] ) cursor.execute( @@ -585,6 +587,11 @@ def initialise(db): if "transaction_type" not in transactions_columns: update_transaction_type(db) + if database.get_config_value(db, "FIX_TRANSACTION_TYPE_1") is None: + with db: + update_transaction_type(db, fix_utxo_move=True) + database.set_config_value(db, "FIX_TRANSACTION_TYPE_1", True) + database.create_indexes( cursor, "transactions", @@ -1055,7 +1062,9 @@ def list_tx(db, block_hash, block_index, block_time, tx_hash, tx_index, decoded_ "fee": fee, "data": data, "utxos_info": " ".join(utxos_info), - "transaction_type": message_type.get_transaction_type(data, destination, block_index), + "transaction_type": message_type.get_transaction_type( + data, destination, utxos_info, block_index + ), } ledger.insert_record(db, "transactions", transaction_bindings, "NEW_TRANSACTION") diff --git a/counterparty-core/counterpartycore/lib/gettxinfo.py b/counterparty-core/counterpartycore/lib/gettxinfo.py index 67a3f80e62..8d1efc8596 100644 --- a/counterparty-core/counterpartycore/lib/gettxinfo.py +++ b/counterparty-core/counterpartycore/lib/gettxinfo.py @@ -761,7 +761,9 @@ def get_utxos_info(db, decoded_tx): def update_utxo_balances_cache(db, utxos_info, data, destination, block_index): if util.enabled("utxo_support", block_index=block_index) and not util.PARSING_MEMPOOL: - transaction_type = message_type.get_transaction_type(data, destination, block_index) + transaction_type = message_type.get_transaction_type( + data, destination, utxos_info, block_index + ) if utxos_info[0] != "": # always remove from cache inputs with balance ledger.UTXOBalancesCache(db).remove_balance(utxos_info[0]) diff --git a/counterparty-core/counterpartycore/lib/message_type.py b/counterparty-core/counterpartycore/lib/message_type.py index 26d7f713dc..bfb81ab6ad 100644 --- a/counterparty-core/counterpartycore/lib/message_type.py +++ b/counterparty-core/counterpartycore/lib/message_type.py @@ -44,7 +44,7 @@ def unpack(packed_data, block_index=None): return (message_type_id, message_remainder) -def get_transaction_type(data: bytes, destination: str, block_index: int): +def get_transaction_type(data: bytes, destination: str, utxos_info: list, block_index: int): TRANSACTION_TYPE_BY_ID = { messages.bet.ID: "bet", messages.broadcast.ID: "broadcast", @@ -75,9 +75,13 @@ def get_transaction_type(data: bytes, destination: str, block_index: int): if not data: if destination == config.UNSPENDABLE and block_index <= config.BURN_END: return "burn" - if block_index >= util.get_change_block_index("utxo_support"): + if block_index >= util.get_change_block_index("utxo_support") and utxos_info[0] != "": return "utxomove" - if block_index >= util.get_change_block_index("dispensers"): + if ( + destination != config.UNSPENDABLE + and block_index >= util.get_change_block_index("dispensers") + and block_index < util.get_change_block_index("disable_vanilla_btc_dispense") + ): return "dispense" return "unknown"