Skip to content

Commit

Permalink
remove useless parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 7, 2025
1 parent ee63d4f commit b7c9c49
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 55 deletions.
3 changes: 1 addition & 2 deletions counterparty-core/counterpartycore/lib/api/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion counterparty-core/counterpartycore/lib/api/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
5 changes: 2 additions & 3 deletions counterparty-core/counterpartycore/lib/backend/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion counterparty-core/counterpartycore/lib/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
15 changes: 6 additions & 9 deletions counterparty-core/counterpartycore/lib/deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand All @@ -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": "",
Expand All @@ -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)
3 changes: 1 addition & 2 deletions counterparty-core/counterpartycore/lib/follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 5 additions & 7 deletions counterparty-core/counterpartycore/test/deserialize_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0636150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac36150000000000001976a9147da51ea175f108a1c63588683dc4c43a7146c46788ac36150000000000001976a9147da51ea175f108a1c6358868173e34e8ca75a06788ac36150000000000001976a9147da51ea175f108a1c637729895c4c468ca75a06788ac36150000000000001976a9147fa51ea175f108a1c63588682ed4c468ca7fa06788ace24ff505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -43,7 +42,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0336150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -70,7 +68,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand Down Expand Up @@ -99,7 +96,6 @@
"in": (
deserialize.deserialize_tx(
"0100000002ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff5ef833190e74ad47d8ae693f841a8b1b500ded7e23ee66b29898b72ec4914fdc0100000000ffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753aed2fe7c11000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -126,7 +122,6 @@
"in": (
deserialize.deserialize_tx(
"0100000002ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff5ef833190e74ad47d8ae693f841a8b1b500ded7e23ee66b29898b72ec4914fdc0100000000ffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753aed2fe7c11000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand Down Expand Up @@ -155,7 +150,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0636150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac36150000000000001976a9147da51ea175f108a1c63588683dc4c43a7146c46788ac36150000000000001976a9147da51ea175f108a1c6358868173e34e8ca75a06788ac36150000000000001976a9147da51ea175f108a1c637729895c4c468ca75a06788ac36150000000000001976a9147fa51ea175f108a1c63588682ed4c468ca7fa06788ace24ff505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand Down Expand Up @@ -187,7 +181,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0636150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac36150000000000001976a9147da51ea175f108a1c63588683dc4c43a7146c46788ac36150000000000001976a9147da51ea175f108a1c6358868173e34e8ca75a06788ac36150000000000001976a9147da51ea175f108a1c637729895c4c468ca75a06788ac36150000000000001976a9147fa51ea175f108a1c63588682ed4c468ca7fa06788ace24ff505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -209,7 +202,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0336150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -231,7 +223,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -254,7 +245,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0636150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac36150000000000001976a9147da51ea175f108a1c63588683dc4c43a7146c46788ac36150000000000001976a9147da51ea175f108a1c6358868173e34e8ca75a06788ac36150000000000001976a9147da51ea175f108a1c637729895c4c468ca75a06788ac36150000000000001976a9147fa51ea175f108a1c63588682ed4c468ca7fa06788ace24ff505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -276,7 +266,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff0336150000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -298,7 +287,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001ebe3111881a8733ace02271dcf606b7450c41a48c1cb21fd73f4ba787b353ce4000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acffffffff03361500000000000017a9144264cfd7eb65f8cbbdba98bd9815d5461fad8d7e87781e000000000000695121035ca51ea175f108a1c63588683dc4c43a7146c46799f864a300263c0813f5fe352102309a14a1a30202f2e76f46acdb2917752371ca42b97460f7928ade8ecb02ea17210319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b97753ae4286f505000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand All @@ -319,7 +307,6 @@
"in": (
deserialize.deserialize_tx(
"0100000001aee668de98ef5f37d4962b620b0ec3deed8bbd4c2fb8ddedaf36c2e8ca5e51a7060000001976a914f3a6b6e4a093e5a5b9da76977a5270fd4d62553e88acffffffff04781e000000000000695121027c6a5e4412be80b5ccd5aa0ea685a21e7a577a5e390d138288841d06514b47992103b00007171817fb044e8a5464e3e274210dd64cf68cca9ea9c3e06df384aae6b22103d928d7d5bbe6f435da935ed382a0061c4a22bdc9b60a2ce6deb7d0f134d22eef53ae781e000000000000695121037c6a5e4412be80b5cc13bde2d9b04fd2cd1fc7ff664c0d3b6d8133163857b08f2103bb6fba40bee91bb02b54835b32f14b9e04016bfa34411ec64f09e3a9586efd5d2103d928d7d5bbe6f435da935ed382a0061c4a22bdc9b60a2ce6deb7d0f134d22eef53ae781e00000000000069512102696a5e4412be80b5ccd6aa0ac9a95e43ca49a21d40f762fadc1aab1c25909fb02102176c68252c6b855d7967aee372f14b772c963b2aa0411ec64f09e3a951eefd3e2103d928d7d5bbe6f435da935ed382a0061c4a22bdc9b60a2ce6deb7d0f134d22eef53aea8d37700000000001976a914f3a6b6e4a093e5a5b9da76977a5270fd4d62553e88ac00000000",
use_txid=True,
parse_vouts=True,
block_index=DP["default_block_index"],
),
Expand Down
Loading

0 comments on commit b7c9c49

Please sign in to comment.