From b7c9c49f0f0e7d2b8501af6df42f26b3523abaf8 Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Tue, 7 Jan 2025 17:45:50 +0000 Subject: [PATCH] remove useless parameter --- .../counterpartycore/lib/api/api_v1.py | 3 +-- .../counterpartycore/lib/api/compose.py | 1 - .../counterpartycore/lib/backend/bitcoind.py | 5 ++--- counterparty-core/counterpartycore/lib/blocks.py | 1 - .../counterpartycore/lib/composer.py | 2 +- .../counterpartycore/lib/deserialize.py | 15 ++++++--------- counterparty-core/counterpartycore/lib/follow.py | 3 +-- counterparty-core/counterpartycore/lib/mempool.py | 2 +- .../counterpartycore/test/deserialize_test.py | 12 +++++------- .../test/fixtures/contract_vectors/gettxinfo.py | 13 ------------- .../counterpartycore/test/p2sh_encoding_test.py | 4 ++-- .../counterpartycore/test/util_test.py | 6 ++++-- counterparty-rs/src/indexer/bitcoin_client.rs | 13 ++++++------- counterparty-rs/src/indexer/mod.rs | 8 ++++---- 14 files changed, 33 insertions(+), 55 deletions(-) diff --git a/counterparty-core/counterpartycore/lib/api/api_v1.py b/counterparty-core/counterpartycore/lib/api/api_v1.py index 22b886e85a..7e810c8463 100644 --- a/counterparty-core/counterpartycore/lib/api/api_v1.py +++ b/counterparty-core/counterpartycore/lib/api/api_v1.py @@ -980,9 +980,8 @@ def getrawtransaction_batch(txhash_list, verbose=False): @dispatcher.add_method def get_tx_info(tx_hex, block_index=None): # block_index mandatory for transactions before block 335000 - use_txid = util.enabled("correct_segwit_txids", block_index=block_index) with LedgerDBConnectionPool().connection() as db: - decoded_tx = deserialize.deserialize_tx(tx_hex, use_txid=use_txid, parse_vouts=True) + decoded_tx = deserialize.deserialize_tx(tx_hex, parse_vouts=True) source, destination, btc_amount, fee, data, _dispensers_outs, _utxos_info = ( gettxinfo.get_tx_info( db, diff --git a/counterparty-core/counterpartycore/lib/api/compose.py b/counterparty-core/counterpartycore/lib/api/compose.py index 2ede6d1e78..fdefb16da8 100644 --- a/counterparty-core/counterpartycore/lib/api/compose.py +++ b/counterparty-core/counterpartycore/lib/api/compose.py @@ -548,7 +548,6 @@ def info(db, rawtransaction: str, block_index: int = None): try: decoded_tx = deserialize.deserialize_tx( rawtransaction, - use_txid=util.enabled("correct_segwit_txids", block_index), parse_vouts=True, block_index=block_index, ) diff --git a/counterparty-core/counterpartycore/lib/backend/bitcoind.py b/counterparty-core/counterpartycore/lib/backend/bitcoind.py index cae4b1a6cf..d530bd2a63 100644 --- a/counterparty-core/counterpartycore/lib/backend/bitcoind.py +++ b/counterparty-core/counterpartycore/lib/backend/bitcoind.py @@ -357,8 +357,7 @@ def get_decoded_transaction(tx_hash, block_index=None): return TRANSACTIONS_CACHE[tx_hash] raw_tx = getrawtransaction(tx_hash) - use_txid = util.enabled("correct_segwit_txids", block_index=block_index) - tx = deserialize.deserialize_tx(raw_tx, use_txid=use_txid, block_index=block_index) + tx = deserialize.deserialize_tx(raw_tx, block_index=block_index) add_transaction_in_cache(tx_hash, tx) @@ -387,7 +386,7 @@ def decoderawtransaction(rawtx: str): Proxy to `decoderawtransaction` RPC call. :param rawtx: The raw transaction hex. (e.g. 0200000000010199c94580cbea44aead18f429be20552e640804dc3b4808e39115197f1312954d000000001600147c6b1112ed7bc76fd03af8b91d02fd6942c5a8d0ffffffff0280f0fa02000000001976a914a11b66a67b3ff69671c8f82254099faf374b800e88ac70da0a27010000001600147c6b1112ed7bc76fd03af8b91d02fd6942c5a8d002000000000000) """ - return deserialize.deserialize_tx(rawtx, False) + return deserialize.deserialize_tx(rawtx) def search_pubkey_in_transactions(pubkeyhash, tx_hashes): diff --git a/counterparty-core/counterpartycore/lib/blocks.py b/counterparty-core/counterpartycore/lib/blocks.py index 4124c273e1..0de59f917f 100644 --- a/counterparty-core/counterpartycore/lib/blocks.py +++ b/counterparty-core/counterpartycore/lib/blocks.py @@ -1306,7 +1306,6 @@ def parse_new_block(db, decoded_block, tx_index=None): raw_current_block = backend.bitcoind.getblock(current_block_hash) decoded_block = deserialize.deserialize_block( raw_current_block, - use_txid=util.enabled("correct_segwit_txids"), parse_vouts=True, block_index=previous_block_index + 1, ) diff --git a/counterparty-core/counterpartycore/lib/composer.py b/counterparty-core/counterpartycore/lib/composer.py index 93220877c6..5082b83784 100644 --- a/counterparty-core/counterpartycore/lib/composer.py +++ b/counterparty-core/counterpartycore/lib/composer.py @@ -833,7 +833,7 @@ def construct(db, tx_info, construct_params): def check_transaction_sanity(tx_info, composed_tx, construct_params): tx_hex = composed_tx["rawtransaction"] source, destinations, data = tx_info - decoded_tx = deserialize.deserialize_tx(tx_hex, use_txid=True, parse_vouts=True) + decoded_tx = deserialize.deserialize_tx(tx_hex, parse_vouts=True) # check if source address matches the first input address first_utxo_txid = decoded_tx["vin"][0]["hash"] diff --git a/counterparty-core/counterpartycore/lib/deserialize.py b/counterparty-core/counterpartycore/lib/deserialize.py index bb76d52720..d0a27bcac3 100644 --- a/counterparty-core/counterpartycore/lib/deserialize.py +++ b/counterparty-core/counterpartycore/lib/deserialize.py @@ -3,7 +3,7 @@ from counterpartycore.lib import config, util -def deserialize_tx(tx_hex, use_txid, parse_vouts=False, block_index=None): +def deserialize_tx(tx_hex, parse_vouts=False, block_index=None): deserializer = indexer.Deserializer( { "rpc_address": "", @@ -15,13 +15,11 @@ def deserialize_tx(tx_hex, use_txid, parse_vouts=False, block_index=None): "prefix": config.PREFIX, } ) - return deserializer.parse_transaction( - tx_hex, block_index or util.CURRENT_BLOCK_INDEX, parse_vouts, use_txid - ) + current_block_index = block_index or util.CURRENT_BLOCK_INDEX + return deserializer.parse_transaction(tx_hex, current_block_index, parse_vouts) -def deserialize_block(block_hex, use_txid, parse_vouts=False, block_index=None): - # block_hex = ("00" * 8) + block_hex # fake magic bytes and block size +def deserialize_block(block_hex, parse_vouts=False, block_index=None): deserializer = indexer.Deserializer( { "rpc_address": "", @@ -33,6 +31,5 @@ def deserialize_block(block_hex, use_txid, parse_vouts=False, block_index=None): "prefix": config.PREFIX, } ) - return deserializer.parse_block( - block_hex, block_index or util.CURRENT_BLOCK_INDEX, parse_vouts, use_txid - ) + current_block_index = block_index or util.CURRENT_BLOCK_INDEX + return deserializer.parse_block(block_hex, current_block_index, parse_vouts) diff --git a/counterparty-core/counterpartycore/lib/follow.py b/counterparty-core/counterpartycore/lib/follow.py index 988b88c957..461bbe3f45 100644 --- a/counterparty-core/counterpartycore/lib/follow.py +++ b/counterparty-core/counterpartycore/lib/follow.py @@ -125,7 +125,6 @@ def receive_rawblock(self, body): # parse blocks as they come in decoded_block = deserialize.deserialize_block( body.hex(), - use_txid=True, parse_vouts=True, block_index=util.CURRENT_BLOCK_INDEX + 1, ) @@ -150,7 +149,7 @@ def receive_rawtx(self, body, sequence): tx_hash = self.hash_by_sequence.get(sequence) if tx_hash is None: # when tx never seen in the mempool is included in a block - decoded_tx = deserialize.deserialize_tx(body.hex(), use_txid=True) + decoded_tx = deserialize.deserialize_tx(body.hex()) tx_hash = decoded_tx["tx_hash"] if sequence in self.hash_by_sequence: self.hash_by_sequence.pop(sequence) diff --git a/counterparty-core/counterpartycore/lib/mempool.py b/counterparty-core/counterpartycore/lib/mempool.py index 42e5f013f4..6cea602b54 100644 --- a/counterparty-core/counterpartycore/lib/mempool.py +++ b/counterparty-core/counterpartycore/lib/mempool.py @@ -45,7 +45,7 @@ def parse_mempool_transactions(db, raw_tx_list, timestamps=None): # list_tx decoded_tx_count = 0 for raw_tx in raw_tx_list: - decoded_tx = deserialize.deserialize_tx(raw_tx, use_txid=True, parse_vouts=True) + decoded_tx = deserialize.deserialize_tx(raw_tx, parse_vouts=True) existing_tx = ledger.get_transaction(db, decoded_tx["tx_hash"]) not_supported_txs.append(decoded_tx["tx_hash"]) if existing_tx: diff --git a/counterparty-core/counterpartycore/test/deserialize_test.py b/counterparty-core/counterpartycore/test/deserialize_test.py index 1f7fcf1ccd..16ea0ab458 100644 --- a/counterparty-core/counterpartycore/test/deserialize_test.py +++ b/counterparty-core/counterpartycore/test/deserialize_test.py @@ -12,9 +12,9 @@ def deserialize_bitcoinlib(tx_hex): return bitcoinlib.core.CTransaction.deserialize(binascii.unhexlify(tx_hex)) -def deserialize_rust(tx_hex, use_txid=False): +def deserialize_rust(tx_hex): # config.NETWORK_NAME = "mainnet" - return deserialize.deserialize_tx(tx_hex, use_txid, parse_vouts=True, block_index=900000) + return deserialize.deserialize_tx(tx_hex, parse_vouts=True, block_index=900000) def create_block_hex(transactions_hex): @@ -36,7 +36,7 @@ def create_block_hex(transactions_hex): def test_deserialize(): hex = "0100000001db3acf37743ac015808f7911a88761530c801819b3b907340aa65dfb6d98ce24030000006a473044022002961f4800cb157f8c0913084db0ee148fa3e1130e0b5e40c3a46a6d4f83ceaf02202c3dd8e631bf24f4c0c5341b3e1382a27f8436d75f3e0a095915995b0bf7dc8e01210395c223fbf96e49e5b9e06a236ca7ef95b10bf18c074bd91a5942fc40360d0b68fdffffff040000000000000000536a4c5058325bd61325dc633fadf05bec9157c23106759cee40954d39d9dbffc17ec5851a2d1feb5d271da422e0e24c7ae8ad29d2eeabf7f9ca3de306bd2bc98e2a39e47731aa000caf400053000c1283000149c8000000000000001976a91462bef4110f98fdcb4aac3c1869dbed9bce8702ed88acc80000000000000017a9144317f779c0a2ccf8f6bc3d440bd9e536a5bff75287fa3e5100000000001976a914bf2646b8ba8b4a143220528bde9c306dac44a01c88ac00000000" - decoded_tx = deserialize_rust(hex, use_txid=True) + decoded_tx = deserialize_rust(hex) _parsed_vouts = decoded_tx.pop("parsed_vouts") # assert str(parsed_vouts) == "Not Parsed" @@ -90,9 +90,7 @@ def test_deserialize(): ] # create a block with the transactions block_hex = create_block_hex(transactions_hex) - block_info = deserialize.deserialize_block( - block_hex, use_txid=False, parse_vouts=True, block_index=900000 - ) + block_info = deserialize.deserialize_block(block_hex, parse_vouts=True, block_index=900000) for i, hex in enumerate(transactions_hex): decoded_tx_bitcoinlib = deserialize_bitcoinlib(hex) @@ -123,7 +121,7 @@ def test_deserialize(): start_time = time.time() for i in range(iterations): # noqa: B007 for hex in transactions_hex: - deserialize_rust(hex, use_txid=True) + deserialize_rust(hex) end_time = time.time() print( f"Time to deserialize {4 * iterations} transactions with Rust: {end_time - start_time} seconds" diff --git a/counterparty-core/counterpartycore/test/fixtures/contract_vectors/gettxinfo.py b/counterparty-core/counterpartycore/test/fixtures/contract_vectors/gettxinfo.py index 8d4ed21c68..208eeeb2ea 100644 --- a/counterparty-core/counterpartycore/test/fixtures/contract_vectors/gettxinfo.py +++ b/counterparty-core/counterpartycore/test/fixtures/contract_vectors/gettxinfo.py @@ -16,7 +16,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0636150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac36150000000000001976a9147da51ea175f108a1c63588683dc4c43a7146c46788ac36150000000000001976a9147da51ea175f108a1c6358868173e34e8ca75a06788ac36150000000000001976a9147da51ea175f108a1c637729895c4c468ca75a06788ac36150000000000001976a9147fa51ea175f108a1c63588682ed4c468ca7fa06788ace24ff505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -43,7 +42,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0336150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -70,7 +68,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -99,7 +96,6 @@ "in": ( deserialize.deserialize_tx( "0100000002ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff5ef833190e74ad47d8ae693f841a8b1b500ded7e23ee66b29898b72ec4914fdc0100000000ffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753aed2fe7c11000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -126,7 +122,6 @@ "in": ( deserialize.deserialize_tx( "0100000002ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff5ef833190e74ad47d8ae693f841a8b1b500ded7e23ee66b29898b72ec4914fdc0100000000ffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753aed2fe7c11000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -155,7 +150,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0636150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac36150000000000001976a9147da51ea175f108a1c63588683dc4c43a7146c46788ac36150000000000001976a9147da51ea175f108a1c6358868173e34e8ca75a06788ac36150000000000001976a9147da51ea175f108a1c637729895c4c468ca75a06788ac36150000000000001976a9147fa51ea175f108a1c63588682ed4c468ca7fa06788ace24ff505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -187,7 +181,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0636150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac36150000000000001976a9147da51ea175f108a1c63588683dc4c43a7146c46788ac36150000000000001976a9147da51ea175f108a1c6358868173e34e8ca75a06788ac36150000000000001976a9147da51ea175f108a1c637729895c4c468ca75a06788ac36150000000000001976a9147fa51ea175f108a1c63588682ed4c468ca7fa06788ace24ff505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -209,7 +202,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0336150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -231,7 +223,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -254,7 +245,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0636150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac36150000000000001976a9147da51ea175f108a1c63588683dc4c43a7146c46788ac36150000000000001976a9147da51ea175f108a1c6358868173e34e8ca75a06788ac36150000000000001976a9147da51ea175f108a1c637729895c4c468ca75a06788ac36150000000000001976a9147fa51ea175f108a1c63588682ed4c468ca7fa06788ace24ff505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -276,7 +266,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0336150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -298,7 +287,6 @@ "in": ( deserialize.deserialize_tx( "0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), @@ -319,7 +307,6 @@ "in": ( deserialize.deserialize_tx( "0100000001aee668de98ef5f37d4962b620b0ec3deed8bbd4c2fb8ddedaf36c2e8ca5e51a7060000001976a914f3a6b6e4a093e5a5b9da76977a5270fd4d62553e88acffffffff04781e000000000000695121027c6a5e4412be80b5ccd5aa0ea685a21e7a577a5e390d138288841d06514b47992103b00007171817fb044e8a5464e3e274210dd64cf68cca9ea9c3e06df384aae6b22103d928d7d5bbe6f435da935ed382a0061c4a22bdc9b60a2ce6deb7d0f134d22eef53ae781e000000000000695121037c6a5e4412be80b5cc13bde2d9b04fd2cd1fc7ff664c0d3b6d8133163857b08f2103bb6fba40bee91bb02b54835b32f14b9e04016bfa34411ec64f09e3a9586efd5d2103d928d7d5bbe6f435da935ed382a0061c4a22bdc9b60a2ce6deb7d0f134d22eef53ae781e00000000000069512102696a5e4412be80b5ccd6aa0ac9a95e43ca49a21d40f762fadc1aab1c25909fb02102176c68252c6b855d7967aee372f14b772c963b2aa0411ec64f09e3a951eefd3e2103d928d7d5bbe6f435da935ed382a0061c4a22bdc9b60a2ce6deb7d0f134d22eef53aea8d37700000000001976a914f3a6b6e4a093e5a5b9da76977a5270fd4d62553e88ac00000000", - use_txid=True, parse_vouts=True, block_index=DP["default_block_index"], ), diff --git a/counterparty-core/counterpartycore/test/p2sh_encoding_test.py b/counterparty-core/counterpartycore/test/p2sh_encoding_test.py index 439c1dda6d..0544e19f41 100644 --- a/counterparty-core/counterpartycore/test/p2sh_encoding_test.py +++ b/counterparty-core/counterpartycore/test/p2sh_encoding_test.py @@ -45,7 +45,7 @@ def test_p2sh_encoding_composed(server_db): parsed_source, parsed_destination, parsed_btc_amount, parsed_fee, parsed_data, extra = ( gettxinfo._get_tx_info( server_db, - deserialize.deserialize_tx(datatxhex, use_txid=True, parse_vouts=True), + deserialize.deserialize_tx(datatxhex, parse_vouts=True), util.CURRENT_BLOCK_INDEX, ) ) @@ -101,7 +101,7 @@ def test_p2sh_signed_multisig_script_decoding(): with util_test.ConfigContext(PREFIX=b"CNTRPRTY"): txHex = "0100000001bae95e59f83e55035f566dc0e3034f79f0d670dc6d6a0d207a11b4e49e9baecf00000000fd0301483045022100d2d38c2d98285e44a271e91894622fa85044469257dbfc15a49e1ba98cddaf8002202b06bf0ca9d65af9f9c96db13c7585b4cd66cabedba269f9b70659dd8e456c46014cb84c8d434e5452505254591e5a3ae08000000000000000000000000073434950203620737570706f727473207573696e672070327368206164647265737365732061732074686520736f7572636520616464726573732062757420726571756972657320616e206164646974696f6e616c20696e70757420696e207468652064617461207472616e73616374696f6e2e752102e53b79237cacdc221cff4c0fb320223cac3e0fe30a682a22f19a70a3975aa3f8ad0075740087ffffffff0100000000000000000e6a0c804e42751677319b884a2d1b00000000" - ctx = deserialize.deserialize_tx(txHex, True, True) + ctx = deserialize.deserialize_tx(txHex, parse_vouts=True) vin = ctx["vin"][0] asm = script.script_to_asm(vin["script_sig"]) new_source, new_destination, new_data = p2sh.decode_p2sh_input(asm) diff --git a/counterparty-core/counterpartycore/test/util_test.py b/counterparty-core/counterpartycore/test/util_test.py index 458f4f7665..29a34b4116 100644 --- a/counterparty-core/counterpartycore/test/util_test.py +++ b/counterparty-core/counterpartycore/test/util_test.py @@ -210,7 +210,9 @@ def insert_raw_transaction(raw_transaction, db): tx = None tx_index = block_index - config.BURN_START + 1 try: - deserialized_tx = deserialize.deserialize_tx(raw_transaction, True, True, 999999999) + deserialized_tx = deserialize.deserialize_tx( + raw_transaction, parse_vouts=True, block_index=999999999 + ) source, destination, btc_amount, fee, data, extra = gettxinfo._get_tx_info( db, deserialized_tx, block_index, composing=True ) @@ -261,7 +263,7 @@ def insert_unconfirmed_raw_transaction(raw_transaction, db): tx_index = tx_index + 1 deserialized_tx = deserialize.deserialize_tx( - raw_transaction, True, True, config.MEMPOOL_BLOCK_INDEX + raw_transaction, parse_vouts=True, block_index=config.MEMPOOL_BLOCK_INDEX ) source, destination, btc_amount, fee, data, extra = gettxinfo._get_tx_info( db, deserialized_tx, util.CURRENT_BLOCK_INDEX, composing=True diff --git a/counterparty-rs/src/indexer/bitcoin_client.rs b/counterparty-rs/src/indexer/bitcoin_client.rs index 5ad8422cfc..650c27a2bc 100644 --- a/counterparty-rs/src/indexer/bitcoin_client.rs +++ b/counterparty-rs/src/indexer/bitcoin_client.rs @@ -382,7 +382,6 @@ fn create_transaction( config: &Config, height: u32, parse_vouts: bool, - use_txid: bool ) -> Transaction { let tx_bytes = serialize(tx); let mut vins = Vec::new(); @@ -485,7 +484,7 @@ fn create_transaction( } let tx_id = tx.compute_txid().to_string(); let tx_hash; - if segwit && use_txid { + if segwit && config.correct_segwit_txids_enabled(height) { tx_hash = tx_id.clone(); } else { tx_hash = Sha256dHash::hash(&tx_bytes).to_string(); @@ -505,13 +504,13 @@ fn create_transaction( } -pub fn parse_transaction(tx_hex: &str, config: &Config, height: u32, parse_vouts: bool, use_txid: bool) -> Transaction { +pub fn parse_transaction(tx_hex: &str, config: &Config, height: u32, parse_vouts: bool) -> Transaction { let decoded_tx = hex::decode(tx_hex).expect("Failed to decode hex string"); let transaction: bitcoin::blockdata::transaction::Transaction = deserialize(&decoded_tx).expect("Failed to deserialize transaction"); - return create_transaction(&transaction, config, height, parse_vouts, use_txid); + return create_transaction(&transaction, config, height, parse_vouts); } @@ -519,7 +518,7 @@ impl ToBlock for Block { fn to_block(&self, config: Config, height: u32) -> CrateBlock { let mut transactions = Vec::new(); for tx in self.txdata.iter() { - transactions.push(create_transaction(tx, &config, height, true, config.correct_segwit_txids_enabled(height))); + transactions.push(create_transaction(tx, &config, height, true)); } CrateBlock { height, @@ -537,13 +536,13 @@ impl ToBlock for Block { } -pub fn parse_block(hex: &str, config: &Config, height: u32, parse_vouts: bool, use_txid: bool) -> Result { +pub fn parse_block(hex: &str, config: &Config, height: u32, parse_vouts: bool) -> Result { let decoded_block = hex::decode(hex).map_err(|e| Error::ParseVout(format!("Failed to decode hex string: {}", e)))?; let block: Block = deserialize(&decoded_block).map_err(|e| Error::ParseVout(format!("Failed to deserialize block: {}", e)))?; let mut transactions = Vec::new(); for tx in block.txdata.iter() { - transactions.push(create_transaction(tx, config, height, parse_vouts, use_txid)); + transactions.push(create_transaction(tx, config, height, parse_vouts)); } Ok(CrateBlock { height, diff --git a/counterparty-rs/src/indexer/mod.rs b/counterparty-rs/src/indexer/mod.rs index 1cc4afb63d..b51b59e161 100644 --- a/counterparty-rs/src/indexer/mod.rs +++ b/counterparty-rs/src/indexer/mod.rs @@ -96,13 +96,13 @@ impl Deserializer { Ok(Deserializer { config }) } - pub fn parse_transaction(&self, tx_hex: &str, height: u32, parse_vouts: bool, use_txid: bool, py: Python<'_>) -> PyResult { - let tx = self::bitcoin_client::parse_transaction(tx_hex, &self.config, height, parse_vouts, use_txid); + pub fn parse_transaction(&self, tx_hex: &str, height: u32, parse_vouts: bool, py: Python<'_>) -> PyResult { + let tx = self::bitcoin_client::parse_transaction(tx_hex, &self.config, height, parse_vouts); return Ok(tx.into_py(py)) } - pub fn parse_block(&self, block_hex: &str, height: u32, parse_vouts: bool, use_txid: bool, py: Python<'_>) -> PyResult { - let block = self::bitcoin_client::parse_block(block_hex, &self.config, height, parse_vouts, use_txid); + pub fn parse_block(&self, block_hex: &str, height: u32, parse_vouts: bool, py: Python<'_>) -> PyResult { + let block = self::bitcoin_client::parse_block(block_hex, &self.config, height, parse_vouts); return Ok(block?.into_py(py)) } }