Skip to content

Commit

Permalink
Merge pull request #2901 from CounterpartyXCP/fixes
Browse files Browse the repository at this point in the history
Fix `transaction_type` field
  • Loading branch information
ouziel-slama authored Jan 5, 2025
2 parents 39315ef + ec1fddf commit bdd5f71
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 17 deletions.
23 changes: 16 additions & 7 deletions counterparty-core/counterpartycore/lib/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")

Expand Down
4 changes: 3 additions & 1 deletion counterparty-core/counterpartycore/lib/gettxinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
14 changes: 11 additions & 3 deletions counterparty-core/counterpartycore/lib/message_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
28 changes: 22 additions & 6 deletions counterparty-core/counterpartycore/test/fixtures/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7560,44 +7560,60 @@
],
"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},
},
{
"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": {
Expand Down

0 comments on commit bdd5f71

Please sign in to comment.