diff --git a/counterparty-core/counterpartycore/lib/blocks.py b/counterparty-core/counterpartycore/lib/blocks.py index 07fca77aa..b976967a2 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 67a3f80e6..8d1efc859 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 26d7f713d..f73b37425 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,17 @@ 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 len(utxos_info) > 0 + 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" diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.log index 963cbf056..d4108a506 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.sql index 6b8a691a5..b41e26816 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_2.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.log index a48807ca9..a0b9289d6 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.sql index fc78446e4..8411ebaec 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_1_of_3.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.log index 6eca07a36..8bbd64506 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.sql index 2a13b3b91..600d337ca 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_2.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.log index 8fbcf852f..6b212eda4 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.sql index 06b17404e..1f9d3a886 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_2_of_3.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.log index ea7729a0a..14f7296fb 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.sql index 979f0cfd0..731464583 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/multisig_3_of_3.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.log index 02e2f4dcd..1f4780737 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.sql index 0ef95d79e..1a6564f40 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/parseblock_unittest_fixture.sql @@ -999,6 +999,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.log index 1a5775194..94858a388 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.sql index 5d39967ac..f27fb5d3a 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/simplesig.sql @@ -301,6 +301,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.log b/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.log index 9aa4119f4..4cce4424d 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.log +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.log @@ -1,4 +1,6 @@ Initializing database... +Updating `transaction_type` column in `transactions` table... +Updated 0 transactions in 0.00 seconds Adding `send_type` column to `sends` table Added `send_type` column to `sends` table in 0.00 seconds Adding `source_address` and `destination_address` column to `sends` table diff --git a/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.sql b/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.sql index e049d6d53..8a9eb5e07 100644 --- a/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.sql +++ b/counterparty-core/counterpartycore/test/fixtures/scenarios/unittest_fixture.sql @@ -998,6 +998,7 @@ CREATE TABLE config ( name TEXT PRIMARY KEY, value TEXT ); +INSERT INTO config VALUES('FIX_TRANSACTION_TYPE_1','1'); INSERT INTO config VALUES('FIX_ASSET_EVENTS_FIELD_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_1','1'); INSERT INTO config VALUES('FIX_ISSUANCES_ASSET_LONGNAME_2','1'); diff --git a/counterparty-core/counterpartycore/test/fixtures/vectors.py b/counterparty-core/counterpartycore/test/fixtures/vectors.py index 1cdac4b6a..9b296a69f 100644 --- a/counterparty-core/counterpartycore/test/fixtures/vectors.py +++ b/counterparty-core/counterpartycore/test/fixtures/vectors.py @@ -7560,27 +7560,37 @@ ], "get_transaction_type": [ { - "in": (b"CNTRPRTY00", "", 3000000), + "in": (b"CNTRPRTY00", "", [], 3000000), "out": "unknown", "mock_protocol_changes": {"short_tx_type_id": True}, }, { - "in": (b"[A95428957753448833|1", "", 3000000), + "in": (b"[A95428957753448833|1", "", [], 3000000), "out": "fairmint", "mock_protocol_changes": {"short_tx_type_id": True}, }, { - "in": (None, "", 3000000), + "in": (None, "", ["txid:0"], 3000000), "out": "utxomove", "mock_protocol_changes": {"short_tx_type_id": True, "utxo_support": True}, }, { - "in": (b"eXCPMEME|25000000000|", "", 3000000), + "in": (None, "", [""], 3000000), + "out": "unknown", + "mock_protocol_changes": {"short_tx_type_id": True}, + }, + { + "in": (None, "", [""], 2900000), + "out": "dispense", + "mock_protocol_changes": {"short_tx_type_id": True}, + }, + { + "in": (b"eXCPMEME|25000000000|", "", [], 3000000), "out": "attach", "mock_protocol_changes": {"short_tx_type_id": True}, }, { - "in": (b"fbc1qcxlwq8x9fnhyhgywlnja35l7znt58tud9duqay", "", 3000000), + "in": (b"fbc1qcxlwq8x9fnhyhgywlnja35l7znt58tud9duqay", "", [], 3000000), "out": "detach", "mock_protocol_changes": {"short_tx_type_id": True}, }, @@ -7588,16 +7598,22 @@ "in": ( b"\x02\x00>\xc7\xd9>|n\x19\x00\x00\x00\x00\x00\x00\x00P\x00%?\x9e\x96I\xb3\xf9u\x15$\xb2\x90\xf93Pra\x0c\xcc\x01", "", + [], 3000000, ), "out": "enhanced_send", "mock_protocol_changes": {"short_tx_type_id": True}, }, { - "in": (None, config.UNSPENDABLE_TESTNET, 3000000), + "in": (None, config.UNSPENDABLE_TESTNET, [""], 3000000), "out": "burn", "mock_protocol_changes": {"short_tx_type_id": True, "utxo_support": True}, }, + { + "in": (None, config.UNSPENDABLE_TESTNET, [""], 5000000), + "out": "unknown", + "mock_protocol_changes": {"short_tx_type_id": True, "utxo_support": True}, + }, ], }, "address": {