From 3552f58418b63758be726a8197803a23faeafbc4 Mon Sep 17 00:00:00 2001 From: Daniel McGregor Date: Mon, 15 Dec 2025 20:43:45 +0800 Subject: [PATCH 1/2] fix: take has_genesis_hash and has_genesis_id into account for transactions in an algod Block --- .../renderer/templates/models/block.py.j2 | 17 +++++++++++ src/algokit_algod_client/models/_block.py | 17 +++++++++++ .../modules/algod_client/manual/test_tx_id.py | 29 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 tests/modules/algod_client/manual/test_tx_id.py diff --git a/api/oas-generator/src/oas_generator/renderer/templates/models/block.py.j2 b/api/oas-generator/src/oas_generator/renderer/templates/models/block.py.j2 index 440272dd..281b4b3c 100644 --- a/api/oas-generator/src/oas_generator/renderer/templates/models/block.py.j2 +++ b/api/oas-generator/src/oas_generator/renderer/templates/models/block.py.j2 @@ -336,6 +336,23 @@ class Block: ), ) + def __post_init__(self) -> None: + # populates genesis id and hash on transactions if required to ensure + # tx id's are correct + genesis_id = self.header.genesis_id + genesis_hash = self.header.genesis_hash + set_frozen_field = object.__setattr__ + for txn_in_block in self.payset or []: + txn = txn_in_block.signed_transaction.signed_transaction.txn + + if txn_in_block.has_genesis_id and txn.genesis_id is None: + set_frozen_field(txn, "genesis_id", genesis_id) + + # the following assumes that Consensus.RequireGenesisHash is true + # so assigns genesis hash unless explicitly set to False + if txn_in_block.has_genesis_hash is not False and txn.genesis_hash is None: + set_frozen_field(txn, "genesis_hash", genesis_hash) + @dataclass(slots=True) class BlockResponse: diff --git a/src/algokit_algod_client/models/_block.py b/src/algokit_algod_client/models/_block.py index 7e34a560..310d1aa8 100644 --- a/src/algokit_algod_client/models/_block.py +++ b/src/algokit_algod_client/models/_block.py @@ -337,6 +337,23 @@ class Block: ), ) + def __post_init__(self) -> None: + # populates genesis id and hash on transactions if required to ensure + # tx id's are correct + genesis_id = self.header.genesis_id + genesis_hash = self.header.genesis_hash + set_frozen_field = object.__setattr__ + for txn_in_block in self.payset or []: + txn = txn_in_block.signed_transaction.signed_transaction.txn + + if txn_in_block.has_genesis_id and txn.genesis_id is None: + set_frozen_field(txn, "genesis_id", genesis_id) + + # the following assumes that Consensus.RequireGenesisHash is true + # so assigns genesis hash unless explicitly set to False + if txn_in_block.has_genesis_hash is not False and txn.genesis_hash is None: + set_frozen_field(txn, "genesis_hash", genesis_hash) + @dataclass(slots=True) class BlockResponse: diff --git a/tests/modules/algod_client/manual/test_tx_id.py b/tests/modules/algod_client/manual/test_tx_id.py new file mode 100644 index 00000000..4f6d9c08 --- /dev/null +++ b/tests/modules/algod_client/manual/test_tx_id.py @@ -0,0 +1,29 @@ +import algokit_algod_client +import algokit_indexer_client + +_ROUND = 24098947 + + +def test_algod_tx_id_matches_indexer() -> None: + algod_client = algokit_algod_client.AlgodClient( + algokit_algod_client.ClientConfig( + base_url="https://mainnet-api.algonode.cloud", + token=None, + ) + ) + indexer_client = algokit_indexer_client.IndexerClient( + algokit_indexer_client.ClientConfig( + base_url="https://mainnet-idx.algonode.cloud", + token=None, + ) + ) + + algod_txns = algod_client.get_block(_ROUND).block.payset + assert algod_txns is not None + algod_txn = algod_txns[0].signed_transaction.signed_transaction.txn + + idx_txns = indexer_client.lookup_block(_ROUND).transactions + assert idx_txns is not None + idx_txn = idx_txns[0] + + assert algod_txn.tx_id() == idx_txn.id_ From 6ad5f1c72cf045d242853250fc2c6191fedac6ae Mon Sep 17 00:00:00 2001 From: Daniel McGregor Date: Wed, 17 Dec 2025 14:57:08 +0800 Subject: [PATCH 2/2] chore: bump filelock to 3.20.1 --- uv.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uv.lock b/uv.lock index 5dbb0e86..27e870e9 100644 --- a/uv.lock +++ b/uv.lock @@ -653,11 +653,11 @@ wheels = [ [[package]] name = "filelock" -version = "3.20.0" +version = "3.20.1" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/58/46/0028a82567109b5ef6e4d2a1f04a583fb513e6cf9527fcdd09afd817deeb/filelock-3.20.0.tar.gz", hash = "sha256:711e943b4ec6be42e1d4e6690b48dc175c822967466bb31c0c293f34334c13f4", size = 18922, upload-time = "2025-10-08T18:03:50.056Z" } +sdist = { url = "https://files.pythonhosted.org/packages/a7/23/ce7a1126827cedeb958fc043d61745754464eb56c5937c35bbf2b8e26f34/filelock-3.20.1.tar.gz", hash = "sha256:b8360948b351b80f420878d8516519a2204b07aefcdcfd24912a5d33127f188c", size = 19476, upload-time = "2025-12-15T23:54:28.027Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/76/91/7216b27286936c16f5b4d0c530087e4a54eead683e6b0b73dd0c64844af6/filelock-3.20.0-py3-none-any.whl", hash = "sha256:339b4732ffda5cd79b13f4e2711a31b0365ce445d95d243bb996273d072546a2", size = 16054, upload-time = "2025-10-08T18:03:48.35Z" }, + { url = "https://files.pythonhosted.org/packages/e3/7f/a1a97644e39e7316d850784c642093c99df1290a460df4ede27659056834/filelock-3.20.1-py3-none-any.whl", hash = "sha256:15d9e9a67306188a44baa72f569d2bfd803076269365fdea0934385da4dc361a", size = 16666, upload-time = "2025-12-15T23:54:26.874Z" }, ] [[package]]