Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.ruff_cache
.mypy_cache
.venv
dist
3 changes: 3 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 37 additions & 7 deletions examples/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "cardano-preprod.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_base64(
index=2, hash="87M9mQb5CDSzemAcO3XyDxYupGVdTeVCuaL/qPF3C/c="
)

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)
Expand All @@ -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())
42 changes: 36 additions & 6 deletions examples/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "cardano-preprod.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_base64(
index=2, hash="87M9mQb5CDSzemAcO3XyDxYupGVdTeVCuaL/qPF3C/c="
)

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()
Loading