From d6b08b3ca8b077c114e5967ef3abed5f7bba8d81 Mon Sep 17 00:00:00 2001 From: gonzalezzfelipe Date: Mon, 19 Aug 2024 13:51:28 -0300 Subject: [PATCH 1/2] chore: Add query client --- .gitignore | 1 + Justfile | 3 + examples/async.py | 44 +++++- examples/sync.py | 42 ++++- poetry.lock | 186 +++++++++++------------ pyproject.toml | 4 +- utxorpc/__init__.py | 14 +- utxorpc/cardano.py | 82 +++++++++- utxorpc/generics/__init__.py | 29 +++- utxorpc/generics/clients/__init__.py | 9 +- utxorpc/generics/clients/query_client.py | 67 ++++++++ utxorpc/generics/clients/sync_client.py | 6 +- 12 files changed, 363 insertions(+), 124 deletions(-) create mode 100644 utxorpc/generics/clients/query_client.py diff --git a/.gitignore b/.gitignore index 468722d..88e5b9d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .ruff_cache .mypy_cache .venv +dist diff --git a/Justfile b/Justfile index 87ce290..73651b9 100644 --- a/Justfile +++ b/Justfile @@ -14,6 +14,9 @@ lint: build: source .venv/bin/activate && poetry build +publish token: + source .venv/bin/activate && poetry publish --build --username __token__ --password "{{ token }}" + run-examples api_key: source .venv/bin/activate && DMTR_API_KEY={{api_key}} poetry run python examples/sync.py source .venv/bin/activate && DMTR_API_KEY={{api_key}} poetry run python examples/async.py diff --git a/examples/async.py b/examples/async.py index 6246b2a..86e512a 100644 --- a/examples/async.py +++ b/examples/async.py @@ -10,26 +10,37 @@ import asyncio import os -from utxorpc.cardano import CardanoPoint, CardanoSyncClient +from utxorpc.cardano import ( + CardanoAddress, + CardanoPoint, + CardanoSyncClient, + CardanoTxOutputPattern, + CardanoQueryClient, + CardanoTxoRef, +) from utxorpc.generics.clients.sync_client import FollowTipResponseAction async def main() -> None: - HOST = "preview.utxorpc-v0.demeter.run" + HOST = "api.utxorpc.cloud" API_KEY = os.getenv("DMTR_API_KEY") assert API_KEY is not None, "DMTR_API_KEY must be defined" + # Preprod BLOCK_REF = CardanoPoint( - slot=52375021, - hash="b5db7950eebf33a0dd9de9ab1f2b25187d5ca0c74018b101842ee6797a3e9c65", + slot=68149593, + hash="403986182453766f3843fc6843fdf8f17587cd2ec10cece313b28c2ac88d39e5", + ) + TXO_REF = CardanoTxoRef.from_hex( + index=3, hash="314ad4b3008d8bff0913f97b761ce2d4045514bed79977d88983623acd968e2c" ) - client: CardanoSyncClient = CardanoSyncClient( + sync_client: CardanoSyncClient = CardanoSyncClient( HOST, metadata={"dmtr-api-key": API_KEY} ) - async with client.async_connect() as client: + async with sync_client.async_connect() as client: fetched_block = await client.async_fetch_block(ref=[BLOCK_REF]) print("FetchBlock: {}", fetched_block) dumped_history = await client.async_dump_history(start=BLOCK_REF, max_items=1) @@ -43,9 +54,28 @@ async def main() -> None: print(f"FollowTip {i}: {followed_tip.block.header}") else: print(f"FollowTip {i}: {followed_tip.action}") - if i >= 50: + if i >= 5: break + query_client: CardanoQueryClient = CardanoQueryClient( + HOST, metadata={"dmtr-api-key": API_KEY} + ) + + async with query_client.async_connect() as client: + utxos = await client.async_search_utxos( + match=CardanoTxOutputPattern( + address={ + "exact_address": CardanoAddress.from_base64( + "YEm9mD0SNTpI05rRUhIiDr1x3T+JfrKauJ88tY4=" + ).hash + } + ) + ) + print(f"Utxos: {utxos}") + + utxo = await client.async_read_utxos(keys=[TXO_REF]) + print(f"Utxo: {utxo}") + if __name__ == "__main__": asyncio.get_event_loop().run_until_complete(main()) diff --git a/examples/sync.py b/examples/sync.py index 333bfd5..0a4c137 100644 --- a/examples/sync.py +++ b/examples/sync.py @@ -9,30 +9,60 @@ """ import os -from utxorpc import CardanoPoint, CardanoSyncClient +from utxorpc import ( + CardanoPoint, + CardanoSyncClient, + CardanoTxOutputPattern, + CardanoAddress, + CardanoQueryClient, + CardanoTxoRef, +) def main() -> None: - HOST = "preview.utxorpc-v0.demeter.run" + HOST = "api.utxorpc.cloud" API_KEY = os.getenv("DMTR_API_KEY") assert API_KEY is not None, "DMTR_API_KEY must be defined" + # Preprod BLOCK_REF = CardanoPoint( - slot=52375021, - hash="b5db7950eebf33a0dd9de9ab1f2b25187d5ca0c74018b101842ee6797a3e9c65", + slot=68149593, + hash="403986182453766f3843fc6843fdf8f17587cd2ec10cece313b28c2ac88d39e5", + ) + TXO_REF = CardanoTxoRef.from_hex( + index=3, hash="314ad4b3008d8bff0913f97b761ce2d4045514bed79977d88983623acd968e2c" ) - client: CardanoSyncClient = CardanoSyncClient( + sync_client: CardanoSyncClient = CardanoSyncClient( HOST, metadata={"dmtr-api-key": API_KEY} ) - with client.connect() as client: + with sync_client.connect() as client: fetched_block = client.fetch_block(ref=[BLOCK_REF]) print("FetchBlock: {}", fetched_block) dumped_history = client.dump_history(start=BLOCK_REF, max_items=1) print("DumpHistory: {}", dumped_history) + query_client: CardanoQueryClient = CardanoQueryClient( + HOST, metadata={"dmtr-api-key": API_KEY} + ) + + with query_client.connect() as client: + utxos = client.search_utxos( + match=CardanoTxOutputPattern( + address={ + "exact_address": CardanoAddress.from_base64( + "YEm9mD0SNTpI05rRUhIiDr1x3T+JfrKauJ88tY4=" + ).hash + } + ) + ) + print("Utxos: {}", utxos) + + utxo = client.read_utxos(keys=[TXO_REF]) + print(f"Utxo: {utxo}") + if __name__ == "__main__": main() diff --git a/poetry.lock b/poetry.lock index 6dccf39..67f960f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -16,102 +16,102 @@ grpcio = "*" [[package]] name = "grpcio" -version = "1.64.1" +version = "1.65.5" description = "HTTP/2-based RPC framework" optional = false python-versions = ">=3.8" files = [ - {file = "grpcio-1.64.1-cp310-cp310-linux_armv7l.whl", hash = "sha256:55697ecec192bc3f2f3cc13a295ab670f51de29884ca9ae6cd6247df55df2502"}, - {file = "grpcio-1.64.1-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:3b64ae304c175671efdaa7ec9ae2cc36996b681eb63ca39c464958396697daff"}, - {file = "grpcio-1.64.1-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:bac71b4b28bc9af61efcdc7630b166440bbfbaa80940c9a697271b5e1dabbc61"}, - {file = "grpcio-1.64.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6c024ffc22d6dc59000faf8ad781696d81e8e38f4078cb0f2630b4a3cf231a90"}, - {file = "grpcio-1.64.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e7cd5c1325f6808b8ae31657d281aadb2a51ac11ab081ae335f4f7fc44c1721d"}, - {file = "grpcio-1.64.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:0a2813093ddb27418a4c99f9b1c223fab0b053157176a64cc9db0f4557b69bd9"}, - {file = "grpcio-1.64.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2981c7365a9353f9b5c864595c510c983251b1ab403e05b1ccc70a3d9541a73b"}, - {file = "grpcio-1.64.1-cp310-cp310-win32.whl", hash = "sha256:1262402af5a511c245c3ae918167eca57342c72320dffae5d9b51840c4b2f86d"}, - {file = "grpcio-1.64.1-cp310-cp310-win_amd64.whl", hash = "sha256:19264fc964576ddb065368cae953f8d0514ecc6cb3da8903766d9fb9d4554c33"}, - {file = "grpcio-1.64.1-cp311-cp311-linux_armv7l.whl", hash = "sha256:58b1041e7c870bb30ee41d3090cbd6f0851f30ae4eb68228955d973d3efa2e61"}, - {file = "grpcio-1.64.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:bbc5b1d78a7822b0a84c6f8917faa986c1a744e65d762ef6d8be9d75677af2ca"}, - {file = "grpcio-1.64.1-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:5841dd1f284bd1b3d8a6eca3a7f062b06f1eec09b184397e1d1d43447e89a7ae"}, - {file = "grpcio-1.64.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8caee47e970b92b3dd948371230fcceb80d3f2277b3bf7fbd7c0564e7d39068e"}, - {file = "grpcio-1.64.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:73819689c169417a4f978e562d24f2def2be75739c4bed1992435d007819da1b"}, - {file = "grpcio-1.64.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:6503b64c8b2dfad299749cad1b595c650c91e5b2c8a1b775380fcf8d2cbba1e9"}, - {file = "grpcio-1.64.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:1de403fc1305fd96cfa75e83be3dee8538f2413a6b1685b8452301c7ba33c294"}, - {file = "grpcio-1.64.1-cp311-cp311-win32.whl", hash = "sha256:d4d29cc612e1332237877dfa7fe687157973aab1d63bd0f84cf06692f04c0367"}, - {file = "grpcio-1.64.1-cp311-cp311-win_amd64.whl", hash = "sha256:5e56462b05a6f860b72f0fa50dca06d5b26543a4e88d0396259a07dc30f4e5aa"}, - {file = "grpcio-1.64.1-cp312-cp312-linux_armv7l.whl", hash = "sha256:4657d24c8063e6095f850b68f2d1ba3b39f2b287a38242dcabc166453e950c59"}, - {file = "grpcio-1.64.1-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:62b4e6eb7bf901719fce0ca83e3ed474ae5022bb3827b0a501e056458c51c0a1"}, - {file = "grpcio-1.64.1-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:ee73a2f5ca4ba44fa33b4d7d2c71e2c8a9e9f78d53f6507ad68e7d2ad5f64a22"}, - {file = "grpcio-1.64.1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:198908f9b22e2672a998870355e226a725aeab327ac4e6ff3a1399792ece4762"}, - {file = "grpcio-1.64.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:39b9d0acaa8d835a6566c640f48b50054f422d03e77e49716d4c4e8e279665a1"}, - {file = "grpcio-1.64.1-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:5e42634a989c3aa6049f132266faf6b949ec2a6f7d302dbb5c15395b77d757eb"}, - {file = "grpcio-1.64.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:b1a82e0b9b3022799c336e1fc0f6210adc019ae84efb7321d668129d28ee1efb"}, - {file = "grpcio-1.64.1-cp312-cp312-win32.whl", hash = "sha256:55260032b95c49bee69a423c2f5365baa9369d2f7d233e933564d8a47b893027"}, - {file = "grpcio-1.64.1-cp312-cp312-win_amd64.whl", hash = "sha256:c1a786ac592b47573a5bb7e35665c08064a5d77ab88a076eec11f8ae86b3e3f6"}, - {file = "grpcio-1.64.1-cp38-cp38-linux_armv7l.whl", hash = "sha256:a011ac6c03cfe162ff2b727bcb530567826cec85eb8d4ad2bfb4bd023287a52d"}, - {file = "grpcio-1.64.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:4d6dab6124225496010bd22690f2d9bd35c7cbb267b3f14e7a3eb05c911325d4"}, - {file = "grpcio-1.64.1-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:a5e771d0252e871ce194d0fdcafd13971f1aae0ddacc5f25615030d5df55c3a2"}, - {file = "grpcio-1.64.1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2c3c1b90ab93fed424e454e93c0ed0b9d552bdf1b0929712b094f5ecfe7a23ad"}, - {file = "grpcio-1.64.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:20405cb8b13fd779135df23fabadc53b86522d0f1cba8cca0e87968587f50650"}, - {file = "grpcio-1.64.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:0cc79c982ccb2feec8aad0e8fb0d168bcbca85bc77b080d0d3c5f2f15c24ea8f"}, - {file = "grpcio-1.64.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:a3a035c37ce7565b8f4f35ff683a4db34d24e53dc487e47438e434eb3f701b2a"}, - {file = "grpcio-1.64.1-cp38-cp38-win32.whl", hash = "sha256:1257b76748612aca0f89beec7fa0615727fd6f2a1ad580a9638816a4b2eb18fd"}, - {file = "grpcio-1.64.1-cp38-cp38-win_amd64.whl", hash = "sha256:0a12ddb1678ebc6a84ec6b0487feac020ee2b1659cbe69b80f06dbffdb249122"}, - {file = "grpcio-1.64.1-cp39-cp39-linux_armv7l.whl", hash = "sha256:75dbbf415026d2862192fe1b28d71f209e2fd87079d98470db90bebe57b33179"}, - {file = "grpcio-1.64.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:e3d9f8d1221baa0ced7ec7322a981e28deb23749c76eeeb3d33e18b72935ab62"}, - {file = "grpcio-1.64.1-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:5f8b75f64d5d324c565b263c67dbe4f0af595635bbdd93bb1a88189fc62ed2e5"}, - {file = "grpcio-1.64.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c84ad903d0d94311a2b7eea608da163dace97c5fe9412ea311e72c3684925602"}, - {file = "grpcio-1.64.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:940e3ec884520155f68a3b712d045e077d61c520a195d1a5932c531f11883489"}, - {file = "grpcio-1.64.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:f10193c69fc9d3d726e83bbf0f3d316f1847c3071c8c93d8090cf5f326b14309"}, - {file = "grpcio-1.64.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ac15b6c2c80a4d1338b04d42a02d376a53395ddf0ec9ab157cbaf44191f3ffdd"}, - {file = "grpcio-1.64.1-cp39-cp39-win32.whl", hash = "sha256:03b43d0ccf99c557ec671c7dede64f023c7da9bb632ac65dbc57f166e4970040"}, - {file = "grpcio-1.64.1-cp39-cp39-win_amd64.whl", hash = "sha256:ed6091fa0adcc7e4ff944090cf203a52da35c37a130efa564ded02b7aff63bcd"}, - {file = "grpcio-1.64.1.tar.gz", hash = "sha256:8d51dd1c59d5fa0f34266b80a3805ec29a1f26425c2a54736133f6d87fc4968a"}, + {file = "grpcio-1.65.5-cp310-cp310-linux_armv7l.whl", hash = "sha256:b67d450f1e008fedcd81e097a3a400a711d8be1a8b20f852a7b8a73fead50fe3"}, + {file = "grpcio-1.65.5-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:a70a20eed87bba647a38bedd93b3ce7db64b3f0e8e0952315237f7f5ca97b02d"}, + {file = "grpcio-1.65.5-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:f79c87c114bf37adf408026b9e2e333fe9ff31dfc9648f6f80776c513145c813"}, + {file = "grpcio-1.65.5-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f17f9fa2d947dbfaca01b3ab2c62eefa8240131fdc67b924eb42ce6032e3e5c1"}, + {file = "grpcio-1.65.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:32d60e18ff7c34fe3f6db3d35ad5c6dc99f5b43ff3982cb26fad4174462d10b1"}, + {file = "grpcio-1.65.5-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:fe6505376f5b00bb008e4e1418152e3ad3d954b629da286c7913ff3cfc0ff740"}, + {file = "grpcio-1.65.5-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:33158e56c6378063923c417e9fbdb28660b6e0e2835af42e67f5a7793f587af7"}, + {file = "grpcio-1.65.5-cp310-cp310-win32.whl", hash = "sha256:1cbc208edb9acf1cc339396a1a36b83796939be52f34e591c90292045b579fbf"}, + {file = "grpcio-1.65.5-cp310-cp310-win_amd64.whl", hash = "sha256:bc74f3f745c37e2c5685c9d2a2d5a94de00f286963f5213f763ae137bf4f2358"}, + {file = "grpcio-1.65.5-cp311-cp311-linux_armv7l.whl", hash = "sha256:3207ae60d07e5282c134b6e02f9271a2cb523c6d7a346c6315211fe2bf8d61ed"}, + {file = "grpcio-1.65.5-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:a2f80510f99f82d4eb825849c486df703f50652cea21c189eacc2b84f2bde764"}, + {file = "grpcio-1.65.5-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:a80e9a5e3f93c54f5eb82a3825ea1fc4965b2fa0026db2abfecb139a5c4ecdf1"}, + {file = "grpcio-1.65.5-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0b2944390a496567de9e70418f3742b477d85d8ca065afa90432edc91b4bb8ad"}, + {file = "grpcio-1.65.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c3655139d7be213c32c79ef6fb2367cae28e56ef68e39b1961c43214b457f257"}, + {file = "grpcio-1.65.5-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:05f02d68fc720e085f061b704ee653b181e6d5abfe315daef085719728d3d1fd"}, + {file = "grpcio-1.65.5-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:1c4caafe71aef4dabf53274bbf4affd6df651e9f80beedd6b8e08ff438ed3260"}, + {file = "grpcio-1.65.5-cp311-cp311-win32.whl", hash = "sha256:84c901cdec16a092099f251ef3360d15e29ef59772150fa261d94573612539b5"}, + {file = "grpcio-1.65.5-cp311-cp311-win_amd64.whl", hash = "sha256:11f8b16121768c1cb99d7dcb84e01510e60e6a206bf9123e134118802486f035"}, + {file = "grpcio-1.65.5-cp312-cp312-linux_armv7l.whl", hash = "sha256:ee6ed64a27588a2c94e8fa84fe8f3b5c89427d4d69c37690903d428ec61ca7e4"}, + {file = "grpcio-1.65.5-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:76991b7a6fb98630a3328839755181ce7c1aa2b1842aa085fd4198f0e5198960"}, + {file = "grpcio-1.65.5-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:89c00a18801b1ed9cc441e29b521c354725d4af38c127981f2c950c796a09b6e"}, + {file = "grpcio-1.65.5-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:078038e150a897e5e402ed3d57f1d31ebf604cbed80f595bd281b5da40762a92"}, + {file = "grpcio-1.65.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c97962720489ef31b5ad8a916e22bc31bba3664e063fb9f6702dce056d4aa61b"}, + {file = "grpcio-1.65.5-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:b8270b15b99781461b244f5c81d5c2bc9696ab9189fb5ff86c841417fb3b39fe"}, + {file = "grpcio-1.65.5-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8e5c4c15ac3fe1eb68e46bc51e66ad29be887479f231f8237cf8416058bf0cc1"}, + {file = "grpcio-1.65.5-cp312-cp312-win32.whl", hash = "sha256:f5b5970341359341d0e4c789da7568264b2a89cd976c05ea476036852b5950cd"}, + {file = "grpcio-1.65.5-cp312-cp312-win_amd64.whl", hash = "sha256:238a625f391a1b9f5f069bdc5930f4fd71b74426bea52196fc7b83f51fa97d34"}, + {file = "grpcio-1.65.5-cp38-cp38-linux_armv7l.whl", hash = "sha256:6c4e62bcf297a1568f627f39576dbfc27f1e5338a691c6dd5dd6b3979da51d1c"}, + {file = "grpcio-1.65.5-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:d7df567b67d16d4177835a68d3f767bbcbad04da9dfb52cbd19171f430c898bd"}, + {file = "grpcio-1.65.5-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:b7ca419f1462390851eec395b2089aad1e49546b52d4e2c972ceb76da69b10f8"}, + {file = "grpcio-1.65.5-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fa36dd8496d3af0d40165252a669fa4f6fd2db4b4026b9a9411cbf060b9d6a15"}, + {file = "grpcio-1.65.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a101696f9ece90a0829988ff72f1b1ea2358f3df035bdf6d675dd8b60c2c0894"}, + {file = "grpcio-1.65.5-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:2a6d8169812932feac514b420daffae8ab8e36f90f3122b94ae767e633296b17"}, + {file = "grpcio-1.65.5-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:47d0aaaab82823f0aa6adea5184350b46e2252e13a42a942db84da5b733f2e05"}, + {file = "grpcio-1.65.5-cp38-cp38-win32.whl", hash = "sha256:85ae8f8517d5bcc21fb07dbf791e94ed84cc28f84c903cdc2bd7eaeb437c8f45"}, + {file = "grpcio-1.65.5-cp38-cp38-win_amd64.whl", hash = "sha256:770bd4bd721961f6dd8049bc27338564ba8739913f77c0f381a9815e465ff965"}, + {file = "grpcio-1.65.5-cp39-cp39-linux_armv7l.whl", hash = "sha256:ab5ec837d8cee8dbce9ef6386125f119b231e4333cc6b6d57b6c5c7c82a72331"}, + {file = "grpcio-1.65.5-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:cabd706183ee08d8026a015af5819a0b3a8959bdc9d1f6fdacd1810f09200f2a"}, + {file = "grpcio-1.65.5-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:ec71fc5b39821ad7d80db7473c8f8c2910f3382f0ddadfbcfc2c6c437107eb67"}, + {file = "grpcio-1.65.5-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d3a9e35bcb045e39d7cac30464c285389b9a816ac2067e4884ad2c02e709ef8e"}, + {file = "grpcio-1.65.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d750e9330eb14236ca11b78d0c494eed13d6a95eb55472298f0e547c165ee324"}, + {file = "grpcio-1.65.5-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:2b91ce647b6307f25650872454a4d02a2801f26a475f90d0b91ed8110baae589"}, + {file = "grpcio-1.65.5-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:8da58ff80bc4556cf29bc03f5fff1f03b8387d6aaa7b852af9eb65b2cf833be4"}, + {file = "grpcio-1.65.5-cp39-cp39-win32.whl", hash = "sha256:7a412959aa5f08c5ac04aa7b7c3c041f5e4298cadd4fcc2acff195b56d185ebc"}, + {file = "grpcio-1.65.5-cp39-cp39-win_amd64.whl", hash = "sha256:55714ea852396ec9568f45f487639945ab674de83c12bea19d5ddbc3ae41ada3"}, + {file = "grpcio-1.65.5.tar.gz", hash = "sha256:ec6f219fb5d677a522b0deaf43cea6697b16f338cb68d009e30930c4aa0d2209"}, ] [package.extras] -protobuf = ["grpcio-tools (>=1.64.1)"] +protobuf = ["grpcio-tools (>=1.65.5)"] [[package]] name = "mypy" -version = "1.10.1" +version = "1.11.1" description = "Optional static typing for Python" optional = false python-versions = ">=3.8" files = [ - {file = "mypy-1.10.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e36f229acfe250dc660790840916eb49726c928e8ce10fbdf90715090fe4ae02"}, - {file = "mypy-1.10.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:51a46974340baaa4145363b9e051812a2446cf583dfaeba124af966fa44593f7"}, - {file = "mypy-1.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:901c89c2d67bba57aaaca91ccdb659aa3a312de67f23b9dfb059727cce2e2e0a"}, - {file = "mypy-1.10.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:0cd62192a4a32b77ceb31272d9e74d23cd88c8060c34d1d3622db3267679a5d9"}, - {file = "mypy-1.10.1-cp310-cp310-win_amd64.whl", hash = "sha256:a2cbc68cb9e943ac0814c13e2452d2046c2f2b23ff0278e26599224cf164e78d"}, - {file = "mypy-1.10.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:bd6f629b67bb43dc0d9211ee98b96d8dabc97b1ad38b9b25f5e4c4d7569a0c6a"}, - {file = "mypy-1.10.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:a1bbb3a6f5ff319d2b9d40b4080d46cd639abe3516d5a62c070cf0114a457d84"}, - {file = "mypy-1.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b8edd4e9bbbc9d7b79502eb9592cab808585516ae1bcc1446eb9122656c6066f"}, - {file = "mypy-1.10.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:6166a88b15f1759f94a46fa474c7b1b05d134b1b61fca627dd7335454cc9aa6b"}, - {file = "mypy-1.10.1-cp311-cp311-win_amd64.whl", hash = "sha256:5bb9cd11c01c8606a9d0b83ffa91d0b236a0e91bc4126d9ba9ce62906ada868e"}, - {file = "mypy-1.10.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:d8681909f7b44d0b7b86e653ca152d6dff0eb5eb41694e163c6092124f8246d7"}, - {file = "mypy-1.10.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:378c03f53f10bbdd55ca94e46ec3ba255279706a6aacaecac52ad248f98205d3"}, - {file = "mypy-1.10.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6bacf8f3a3d7d849f40ca6caea5c055122efe70e81480c8328ad29c55c69e93e"}, - {file = "mypy-1.10.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:701b5f71413f1e9855566a34d6e9d12624e9e0a8818a5704d74d6b0402e66c04"}, - {file = "mypy-1.10.1-cp312-cp312-win_amd64.whl", hash = "sha256:3c4c2992f6ea46ff7fce0072642cfb62af7a2484efe69017ed8b095f7b39ef31"}, - {file = "mypy-1.10.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:604282c886497645ffb87b8f35a57ec773a4a2721161e709a4422c1636ddde5c"}, - {file = "mypy-1.10.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:37fd87cab83f09842653f08de066ee68f1182b9b5282e4634cdb4b407266bade"}, - {file = "mypy-1.10.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8addf6313777dbb92e9564c5d32ec122bf2c6c39d683ea64de6a1fd98b90fe37"}, - {file = "mypy-1.10.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:5cc3ca0a244eb9a5249c7c583ad9a7e881aa5d7b73c35652296ddcdb33b2b9c7"}, - {file = "mypy-1.10.1-cp38-cp38-win_amd64.whl", hash = "sha256:1b3a2ffce52cc4dbaeee4df762f20a2905aa171ef157b82192f2e2f368eec05d"}, - {file = "mypy-1.10.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:fe85ed6836165d52ae8b88f99527d3d1b2362e0cb90b005409b8bed90e9059b3"}, - {file = "mypy-1.10.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c2ae450d60d7d020d67ab440c6e3fae375809988119817214440033f26ddf7bf"}, - {file = "mypy-1.10.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6be84c06e6abd72f960ba9a71561c14137a583093ffcf9bbfaf5e613d63fa531"}, - {file = "mypy-1.10.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:2189ff1e39db399f08205e22a797383613ce1cb0cb3b13d8bcf0170e45b96cc3"}, - {file = "mypy-1.10.1-cp39-cp39-win_amd64.whl", hash = "sha256:97a131ee36ac37ce9581f4220311247ab6cba896b4395b9c87af0675a13a755f"}, - {file = "mypy-1.10.1-py3-none-any.whl", hash = "sha256:71d8ac0b906354ebda8ef1673e5fde785936ac1f29ff6987c7483cfbd5a4235a"}, - {file = "mypy-1.10.1.tar.gz", hash = "sha256:1f8f492d7db9e3593ef42d4f115f04e556130f2819ad33ab84551403e97dd4c0"}, + {file = "mypy-1.11.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:a32fc80b63de4b5b3e65f4be82b4cfa362a46702672aa6a0f443b4689af7008c"}, + {file = "mypy-1.11.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c1952f5ea8a5a959b05ed5f16452fddadbaae48b5d39235ab4c3fc444d5fd411"}, + {file = "mypy-1.11.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e1e30dc3bfa4e157e53c1d17a0dad20f89dc433393e7702b813c10e200843b03"}, + {file = "mypy-1.11.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2c63350af88f43a66d3dfeeeb8d77af34a4f07d760b9eb3a8697f0386c7590b4"}, + {file = "mypy-1.11.1-cp310-cp310-win_amd64.whl", hash = "sha256:a831671bad47186603872a3abc19634f3011d7f83b083762c942442d51c58d58"}, + {file = "mypy-1.11.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:7b6343d338390bb946d449677726edf60102a1c96079b4f002dedff375953fc5"}, + {file = "mypy-1.11.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:e4fe9f4e5e521b458d8feb52547f4bade7ef8c93238dfb5bbc790d9ff2d770ca"}, + {file = "mypy-1.11.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:886c9dbecc87b9516eff294541bf7f3655722bf22bb898ee06985cd7269898de"}, + {file = "mypy-1.11.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:fca4a60e1dd9fd0193ae0067eaeeb962f2d79e0d9f0f66223a0682f26ffcc809"}, + {file = "mypy-1.11.1-cp311-cp311-win_amd64.whl", hash = "sha256:0bd53faf56de9643336aeea1c925012837432b5faf1701ccca7fde70166ccf72"}, + {file = "mypy-1.11.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:f39918a50f74dc5969807dcfaecafa804fa7f90c9d60506835036cc1bc891dc8"}, + {file = "mypy-1.11.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0bc71d1fb27a428139dd78621953effe0d208aed9857cb08d002280b0422003a"}, + {file = "mypy-1.11.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b868d3bcff720dd7217c383474008ddabaf048fad8d78ed948bb4b624870a417"}, + {file = "mypy-1.11.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a707ec1527ffcdd1c784d0924bf5cb15cd7f22683b919668a04d2b9c34549d2e"}, + {file = "mypy-1.11.1-cp312-cp312-win_amd64.whl", hash = "sha256:64f4a90e3ea07f590c5bcf9029035cf0efeae5ba8be511a8caada1a4893f5525"}, + {file = "mypy-1.11.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:749fd3213916f1751fff995fccf20c6195cae941dc968f3aaadf9bb4e430e5a2"}, + {file = "mypy-1.11.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b639dce63a0b19085213ec5fdd8cffd1d81988f47a2dec7100e93564f3e8fb3b"}, + {file = "mypy-1.11.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4c956b49c5d865394d62941b109728c5c596a415e9c5b2be663dd26a1ff07bc0"}, + {file = "mypy-1.11.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:45df906e8b6804ef4b666af29a87ad9f5921aad091c79cc38e12198e220beabd"}, + {file = "mypy-1.11.1-cp38-cp38-win_amd64.whl", hash = "sha256:d44be7551689d9d47b7abc27c71257adfdb53f03880841a5db15ddb22dc63edb"}, + {file = "mypy-1.11.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:2684d3f693073ab89d76da8e3921883019ea8a3ec20fa5d8ecca6a2db4c54bbe"}, + {file = "mypy-1.11.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:79c07eb282cb457473add5052b63925e5cc97dfab9812ee65a7c7ab5e3cb551c"}, + {file = "mypy-1.11.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:11965c2f571ded6239977b14deebd3f4c3abd9a92398712d6da3a772974fad69"}, + {file = "mypy-1.11.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a2b43895a0f8154df6519706d9bca8280cda52d3d9d1514b2d9c3e26792a0b74"}, + {file = "mypy-1.11.1-cp39-cp39-win_amd64.whl", hash = "sha256:1a81cf05975fd61aec5ae16501a091cfb9f605dc3e3c878c0da32f250b74760b"}, + {file = "mypy-1.11.1-py3-none-any.whl", hash = "sha256:0624bdb940255d2dd24e829d99a13cfeb72e4e9031f9492148f410ed30bcab54"}, + {file = "mypy-1.11.1.tar.gz", hash = "sha256:f404a0b069709f18bbdb702eb3dcfe51910602995de00bd39cea3050b5772d08"}, ] [package.dependencies] mypy-extensions = ">=1.0.0" tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} -typing-extensions = ">=4.1.0" +typing-extensions = ">=4.6.0" [package.extras] dmypy = ["psutil (>=4.0)"] @@ -132,22 +132,22 @@ files = [ [[package]] name = "protobuf" -version = "5.27.2" +version = "5.27.3" description = "" optional = false python-versions = ">=3.8" files = [ - {file = "protobuf-5.27.2-cp310-abi3-win32.whl", hash = "sha256:354d84fac2b0d76062e9b3221f4abbbacdfd2a4d8af36bab0474f3a0bb30ab38"}, - {file = "protobuf-5.27.2-cp310-abi3-win_amd64.whl", hash = "sha256:0e341109c609749d501986b835f667c6e1e24531096cff9d34ae411595e26505"}, - {file = "protobuf-5.27.2-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:a109916aaac42bff84702fb5187f3edadbc7c97fc2c99c5ff81dd15dcce0d1e5"}, - {file = "protobuf-5.27.2-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:176c12b1f1c880bf7a76d9f7c75822b6a2bc3db2d28baa4d300e8ce4cde7409b"}, - {file = "protobuf-5.27.2-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:b848dbe1d57ed7c191dfc4ea64b8b004a3f9ece4bf4d0d80a367b76df20bf36e"}, - {file = "protobuf-5.27.2-cp38-cp38-win32.whl", hash = "sha256:4fadd8d83e1992eed0248bc50a4a6361dc31bcccc84388c54c86e530b7f58863"}, - {file = "protobuf-5.27.2-cp38-cp38-win_amd64.whl", hash = "sha256:610e700f02469c4a997e58e328cac6f305f649826853813177e6290416e846c6"}, - {file = "protobuf-5.27.2-cp39-cp39-win32.whl", hash = "sha256:9e8f199bf7f97bd7ecebffcae45ebf9527603549b2b562df0fbc6d4d688f14ca"}, - {file = "protobuf-5.27.2-cp39-cp39-win_amd64.whl", hash = "sha256:7fc3add9e6003e026da5fc9e59b131b8f22b428b991ccd53e2af8071687b4fce"}, - {file = "protobuf-5.27.2-py3-none-any.whl", hash = "sha256:54330f07e4949d09614707c48b06d1a22f8ffb5763c159efd5c0928326a91470"}, - {file = "protobuf-5.27.2.tar.gz", hash = "sha256:f3ecdef226b9af856075f28227ff2c90ce3a594d092c39bee5513573f25e2714"}, + {file = "protobuf-5.27.3-cp310-abi3-win32.whl", hash = "sha256:dcb307cd4ef8fec0cf52cb9105a03d06fbb5275ce6d84a6ae33bc6cf84e0a07b"}, + {file = "protobuf-5.27.3-cp310-abi3-win_amd64.whl", hash = "sha256:16ddf3f8c6c41e1e803da7abea17b1793a97ef079a912e42351eabb19b2cffe7"}, + {file = "protobuf-5.27.3-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:68248c60d53f6168f565a8c76dc58ba4fa2ade31c2d1ebdae6d80f969cdc2d4f"}, + {file = "protobuf-5.27.3-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:b8a994fb3d1c11156e7d1e427186662b64694a62b55936b2b9348f0a7c6625ce"}, + {file = "protobuf-5.27.3-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:a55c48f2a2092d8e213bd143474df33a6ae751b781dd1d1f4d953c128a415b25"}, + {file = "protobuf-5.27.3-cp38-cp38-win32.whl", hash = "sha256:043853dcb55cc262bf2e116215ad43fa0859caab79bb0b2d31b708f128ece035"}, + {file = "protobuf-5.27.3-cp38-cp38-win_amd64.whl", hash = "sha256:c2a105c24f08b1e53d6c7ffe69cb09d0031512f0b72f812dd4005b8112dbe91e"}, + {file = "protobuf-5.27.3-cp39-cp39-win32.whl", hash = "sha256:c84eee2c71ed83704f1afbf1a85c3171eab0fd1ade3b399b3fad0884cbcca8bf"}, + {file = "protobuf-5.27.3-cp39-cp39-win_amd64.whl", hash = "sha256:af7c0b7cfbbb649ad26132e53faa348580f844d9ca46fd3ec7ca48a1ea5db8a1"}, + {file = "protobuf-5.27.3-py3-none-any.whl", hash = "sha256:8572c6533e544ebf6899c360e91d6bcbbee2549251643d32c52cf8a5de295ba5"}, + {file = "protobuf-5.27.3.tar.gz", hash = "sha256:82460903e640f2b7e34ee81a947fdaad89de796d324bcbc38ff5430bcdead82c"}, ] [[package]] @@ -200,13 +200,13 @@ files = [ [[package]] name = "utxorpc-spec" -version = "0.5.1" +version = "0.9.0" description = "Auto-generated structs for the UTxO RPC spec." optional = false python-versions = "<4.0,>=3.8" files = [ - {file = "utxorpc_spec-0.5.1-py3-none-any.whl", hash = "sha256:318534fd768be8f40d5d2946e218e36e0f6ad641ba2b3f7e720baa448458dd79"}, - {file = "utxorpc_spec-0.5.1.tar.gz", hash = "sha256:033afda491ba1c76c7ab5c9f2b5abc4fd3de5cffefd3b67742d8e550f4f155ac"}, + {file = "utxorpc_spec-0.9.0-py3-none-any.whl", hash = "sha256:5af4198dec25f86e16a970645c9118709712b6b9a2728eb9756d360ca719ede7"}, + {file = "utxorpc_spec-0.9.0.tar.gz", hash = "sha256:29b8393d31c25aab4fd3dedc9759ebb8eb66de5cfcf69499c2229c36a10e3043"}, ] [package.dependencies] @@ -217,4 +217,4 @@ protobuf = ">=5.27.1,<6.0.0" [metadata] lock-version = "2.0" python-versions = ">=3.8,<4.0" -content-hash = "d66e034190ecbd0edf4a51152e7280349523bb7005f00891734f1d61643cb6c4" +content-hash = "eaa754c51a515866e3d742076b820e21f434261335bd8b2cc957c4cc886f789a" diff --git a/pyproject.toml b/pyproject.toml index 9a85054..f9092b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,9 +13,11 @@ license = "Apache-2.0" [tool.poetry.dependencies] # https://python-poetry.org/docs/dependency-specification/ python = ">=3.8,<4.0" -utxorpc-spec = "0.5.1" typing-extensions = "^4.12.2" +utxorpc-spec = "0.9.0" +# utxorpc-spec = { path="../spec/gen/python" } + [tool.poetry.group.dev.dependencies] mypy = "^1.10.0" ruff = "^0.4.10" diff --git a/utxorpc/__init__.py b/utxorpc/__init__.py index 61c72bd..abc8d3e 100644 --- a/utxorpc/__init__.py +++ b/utxorpc/__init__.py @@ -1,7 +1,19 @@ -from .cardano import CardanoSyncClient, CardanoPoint, CardanoBlock +from .cardano import ( + CardanoAddress, + CardanoBlock, + CardanoPoint, + CardanoQueryClient, + CardanoSyncClient, + CardanoTxOutputPattern, + CardanoTxoRef, +) __all__ = [ + "CardanoAddress", "CardanoBlock", "CardanoPoint", + "CardanoQueryClient", "CardanoSyncClient", + "CardanoTxOutputPattern", + "CardanoTxoRef", ] diff --git a/utxorpc/cardano.py b/utxorpc/cardano.py index 74d5fdf..9193933 100644 --- a/utxorpc/cardano.py +++ b/utxorpc/cardano.py @@ -1,20 +1,45 @@ -from typing import ( - Optional, - Union, -) +import base64 +from typing import Optional, Union from typing_extensions import TypeAlias -from utxorpc_spec.utxorpc.v1alpha.cardano.cardano_pb2 import Block # type: ignore +from utxorpc_spec.utxorpc.v1alpha.cardano.cardano_pb2 import ( # type: ignore + Block, + TxOutput, + TxOutputPattern, +) +from utxorpc_spec.utxorpc.v1alpha.query.query_pb2 import ( # type: ignore + AnyUtxoPattern, + AnyUtxoData, + TxoRef, +) from utxorpc_spec.utxorpc.v1alpha.sync.sync_pb2 import ( # type: ignore AnyChainBlock, BlockRef, ) from utxorpc.generics import Chain +from utxorpc.generics.clients.query_client import QueryClient from utxorpc.generics.clients.sync_client import SyncClient CardanoBlock: TypeAlias = Block +CardanoTxOutputPattern: TypeAlias = TxOutputPattern +CardanoTxOutput: TypeAlias = TxOutput + + +class CardanoAddress: + hash: bytes + + def __init__(self, hash: bytes): + self.hash = hash + + @classmethod + def from_hex(cls, string: str) -> "CardanoAddress": + return CardanoAddress(bytes.fromhex(string)) + + @classmethod + def from_base64(cls, string: str) -> "CardanoAddress": + return CardanoAddress(base64.b64decode(string)) class CardanoPoint: @@ -29,7 +54,32 @@ def __init__(self, slot: int, hash: Union[bytes, str]): self.hash = hash -class CardanoChain(Chain[CardanoBlock, CardanoPoint]): +class CardanoTxoRef: + index: int + hash: bytes + + def __init__(self, index: int, hash: bytes): + self.index = index + self.hash = hash + + @classmethod + def from_hex(cls, index: int, hash: str) -> "CardanoTxoRef": + return cls(index=index, hash=bytes.fromhex(hash)) + + @classmethod + def from_base64(cls, index: int, hash: str) -> "CardanoTxoRef": + return cls(index=index, hash=base64.b64decode(hash)) + + +class CardanoChain( + Chain[ + CardanoBlock, + CardanoPoint, + CardanoTxOutputPattern, + CardanoTxOutput, + CardanoTxoRef, + ] +): @staticmethod def any_chain_to_block(message: AnyChainBlock) -> Optional[CardanoBlock]: try: @@ -45,6 +95,26 @@ def point_to_block_ref(point: CardanoPoint) -> BlockRef: def block_ref_to_point(block_ref: BlockRef) -> CardanoPoint: return CardanoPoint(slot=block_ref.index, hash=block_ref.hash) + @staticmethod + def any_utxo_data_to_tx_output(any_utxo_data: AnyUtxoData) -> CardanoTxOutput: + return any_utxo_data.cardano + + @staticmethod + def tx_output_pattern_to_any_utxo_pattern( + tx_output_pattern: CardanoTxOutputPattern, + ) -> AnyUtxoPattern: + return AnyUtxoPattern(cardano=tx_output_pattern) + + @staticmethod + def chain_txo_ref_to_txo_ref(txo_ref: CardanoTxoRef) -> TxoRef: + return TxoRef(index=txo_ref.index, hash=txo_ref.hash) + + +class CardanoQueryClient( + QueryClient[CardanoTxOutputPattern, CardanoTxOutput, CardanoTxoRef] +): + chain = CardanoChain + class CardanoSyncClient(SyncClient[CardanoBlock, CardanoPoint]): chain = CardanoChain diff --git a/utxorpc/generics/__init__.py b/utxorpc/generics/__init__.py index e02c4e2..fe6a1f8 100644 --- a/utxorpc/generics/__init__.py +++ b/utxorpc/generics/__init__.py @@ -1,15 +1,26 @@ from typing import Optional, Protocol, TypeVar +from utxorpc_spec.utxorpc.v1alpha.query.query_pb2 import ( # type: ignore + AnyUtxoPattern, + AnyUtxoData, + TxoRef, +) from utxorpc_spec.utxorpc.v1alpha.sync.sync_pb2 import ( # type: ignore AnyChainBlock, BlockRef, ) + BlockType = TypeVar("BlockType", covariant=True) PointType = TypeVar("PointType") +TxOutputPatternType = TypeVar("TxOutputPatternType") +TxOutputType = TypeVar("TxOutputType", covariant=True) +TxoRefType = TypeVar("TxoRefType", contravariant=True) -class Chain(Protocol[BlockType, PointType]): +class Chain( + Protocol[BlockType, PointType, TxOutputPatternType, TxOutputType, TxoRefType] +): @staticmethod def any_chain_to_block(message: AnyChainBlock) -> Optional[BlockType]: ... @@ -18,3 +29,19 @@ def point_to_block_ref(point: PointType) -> BlockRef: ... @staticmethod def block_ref_to_point(block_ref: BlockRef) -> PointType: ... + + @staticmethod + def tx_output_pattern_to_any_utxo_pattern( + tx_output_pattern: TxOutputPatternType, + ) -> AnyUtxoPattern: ... + + @staticmethod + def any_utxo_pattern_to_tx_output_pattern( + any_utxo_pattern: AnyUtxoPattern, + ) -> TxOutputPatternType: ... + + @staticmethod + def any_utxo_data_to_tx_output(any_utxo_data: AnyUtxoData) -> TxOutputType: ... + + @staticmethod + def chain_txo_ref_to_txo_ref(txo_ref: TxoRefType) -> TxoRef: ... diff --git a/utxorpc/generics/clients/__init__.py b/utxorpc/generics/clients/__init__.py index a7ec478..f7e5001 100644 --- a/utxorpc/generics/clients/__init__.py +++ b/utxorpc/generics/clients/__init__.py @@ -4,7 +4,6 @@ Any, Dict, Generic, - Iterable, Optional, Protocol, Sequence, @@ -33,7 +32,7 @@ class Client(Generic[Stub]): ssl_context: Optional[grpc.ChannelCredentials] channel: Optional[grpc.Channel] async_channel: Optional[grpc.aio.Channel] - options: Optional[Iterable[Tuple[str, str]]] + options: Optional[Sequence[Tuple[str, str]]] compression: Optional[grpc.Compression] chain: Type[Chain] @@ -125,8 +124,7 @@ async def async_connect(self): get_channel = partial( grpc.aio.insecure_channel, self.uri, - # Typing bug on grpc lib (https://github.com/grpc/grpc/issues/37025) - options=self.options, # type: ignore + options=self.options, compression=self.compression, ) if self.secure: @@ -134,8 +132,7 @@ async def async_connect(self): grpc.aio.secure_channel, self.uri, self.ssl_context or grpc.ssl_channel_credentials(), - # Typing bug on grpc lib (https://github.com/grpc/grpc/issues/37025) - options=self.options, # type: ignore + options=self.options, compression=self.compression, ) async with get_channel() as async_channel: diff --git a/utxorpc/generics/clients/query_client.py b/utxorpc/generics/clients/query_client.py new file mode 100644 index 0000000..a4e1d64 --- /dev/null +++ b/utxorpc/generics/clients/query_client.py @@ -0,0 +1,67 @@ +from typing import Generic, List, Optional + +from utxorpc_spec.utxorpc.v1alpha.query.query_pb2 import ( # type: ignore + ReadUtxosRequest, + SearchUtxosRequest, + UtxoPredicate, +) +from utxorpc_spec.utxorpc.v1alpha.query.query_pb2_grpc import QueryServiceStub # type: ignore + +from utxorpc.generics import TxOutputPatternType, TxOutputType, TxoRefType +from utxorpc.generics.clients import Client + + +class QueryClient( + Client[QueryServiceStub], Generic[TxOutputPatternType, TxOutputType, TxoRefType] +): + stub = QueryServiceStub + + async def async_search_utxos( + self, match: TxOutputPatternType + ) -> List[TxOutputType]: + stub = self.get_async_stub() + response = await stub.SearchUtxos( + SearchUtxosRequest( + predicate=UtxoPredicate( + match=self.chain.tx_output_pattern_to_any_utxo_pattern(match) + ) + ), + metadata=[(k, v) for k, v in self.metadata.items()], + ) + + return [self.chain.any_utxo_data_to_tx_output(item) for item in response.items] + + def search_utxos(self, match: TxOutputPatternType) -> List[TxOutputType]: + stub = self.get_stub() + response = stub.SearchUtxos( + SearchUtxosRequest( + predicate=UtxoPredicate( + match=self.chain.tx_output_pattern_to_any_utxo_pattern(match) + ) + ), + metadata=[(k, v) for k, v in self.metadata.items()], + ) + + return [self.chain.any_utxo_data_to_tx_output(item) for item in response.items] + + def read_utxos(self, keys: List[TxoRefType]) -> List[Optional[TxOutputType]]: + stub = self.get_stub() + response = stub.ReadUtxos( + ReadUtxosRequest( + keys=[self.chain.chain_txo_ref_to_txo_ref(key) for key in keys] + ), + metadata=[(k, v) for k, v in self.metadata.items()], + ) + return [self.chain.any_utxo_data_to_tx_output(item) for item in response.items] + + async def async_read_utxos( + self, keys: List[TxoRefType] + ) -> List[Optional[TxOutputType]]: + stub = self.get_async_stub() + response = await stub.ReadUtxos( + ReadUtxosRequest( + keys=[self.chain.chain_txo_ref_to_txo_ref(key) for key in keys] + ), + metadata=[(k, v) for k, v in self.metadata.items()], + ) + return [self.chain.any_utxo_data_to_tx_output(item) for item in response.items] diff --git a/utxorpc/generics/clients/sync_client.py b/utxorpc/generics/clients/sync_client.py index 1cecd63..e5c8834 100644 --- a/utxorpc/generics/clients/sync_client.py +++ b/utxorpc/generics/clients/sync_client.py @@ -7,7 +7,7 @@ FetchBlockRequest, FollowTipRequest, ) -from utxorpc_spec.utxorpc.v1alpha.sync.sync_pb2_grpc import ChainSyncServiceStub # type: ignore +from utxorpc_spec.utxorpc.v1alpha.sync.sync_pb2_grpc import SyncServiceStub # type: ignore from utxorpc.generics import BlockType, PointType from utxorpc.generics.clients import Client @@ -41,8 +41,8 @@ def __init__( self.point = point -class SyncClient(Client[ChainSyncServiceStub], Generic[BlockType, PointType]): - stub = ChainSyncServiceStub +class SyncClient(Client[SyncServiceStub], Generic[BlockType, PointType]): + stub = SyncServiceStub async def async_fetch_block(self, ref: Iterable[PointType]) -> Optional[BlockType]: stub = self.get_async_stub() From 9629d7bdac9ac58aeb220794bbccd86136ec8eee Mon Sep 17 00:00:00 2001 From: gonzalezzfelipe Date: Mon, 19 Aug 2024 18:00:30 -0300 Subject: [PATCH 2/2] Working examples --- examples/async.py | 6 +++--- examples/sync.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/async.py b/examples/async.py index 86e512a..4bb918a 100644 --- a/examples/async.py +++ b/examples/async.py @@ -22,7 +22,7 @@ async def main() -> None: - HOST = "api.utxorpc.cloud" + HOST = "cardano-preprod.utxorpc.cloud" API_KEY = os.getenv("DMTR_API_KEY") assert API_KEY is not None, "DMTR_API_KEY must be defined" @@ -32,8 +32,8 @@ async def main() -> None: slot=68149593, hash="403986182453766f3843fc6843fdf8f17587cd2ec10cece313b28c2ac88d39e5", ) - TXO_REF = CardanoTxoRef.from_hex( - index=3, hash="314ad4b3008d8bff0913f97b761ce2d4045514bed79977d88983623acd968e2c" + TXO_REF = CardanoTxoRef.from_base64( + index=2, hash="87M9mQb5CDSzemAcO3XyDxYupGVdTeVCuaL/qPF3C/c=" ) sync_client: CardanoSyncClient = CardanoSyncClient( diff --git a/examples/sync.py b/examples/sync.py index 0a4c137..a2b334b 100644 --- a/examples/sync.py +++ b/examples/sync.py @@ -20,7 +20,7 @@ def main() -> None: - HOST = "api.utxorpc.cloud" + HOST = "cardano-preprod.utxorpc.cloud" API_KEY = os.getenv("DMTR_API_KEY") assert API_KEY is not None, "DMTR_API_KEY must be defined" @@ -30,8 +30,8 @@ def main() -> None: slot=68149593, hash="403986182453766f3843fc6843fdf8f17587cd2ec10cece313b28c2ac88d39e5", ) - TXO_REF = CardanoTxoRef.from_hex( - index=3, hash="314ad4b3008d8bff0913f97b761ce2d4045514bed79977d88983623acd968e2c" + TXO_REF = CardanoTxoRef.from_base64( + index=2, hash="87M9mQb5CDSzemAcO3XyDxYupGVdTeVCuaL/qPF3C/c=" ) sync_client: CardanoSyncClient = CardanoSyncClient(