Skip to content

Commit 5295d0f

Browse files
committed
python: Add Connection.get_ledger_end.
1 parent 56e0478 commit 5295d0f

File tree

9 files changed

+161
-210
lines changed

9 files changed

+161
-210
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.8.1
1+
7.8.2

poetry.lock

Lines changed: 127 additions & 207 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[tool.poetry]
55
name = "dazl"
6-
version = "7.8.1"
6+
version = "7.8.2"
77
description = "high-level Ledger API client for Daml ledgers"
88
license = "Apache-2.0"
99
authors = ["Davin K. Tanabe <davin.tanabe@digitalasset.com>"]
@@ -23,7 +23,7 @@ googleapis_common_protos = "^1"
2323
grpcio = ">=1.32.0"
2424
oauthlib = { version = "*", optional = true }
2525
prometheus_client = { version = "*", optional = true }
26-
protobuf = ">=3.19.0, <=3.20"
26+
protobuf = ">=3.19.0, <4"
2727
pygments = { version = "*", optional = true }
2828
pyOpenSSL = { version = "*", optional = true }
2929
requests = "*"

python/dazl/ledger/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ class Connection(PackageService, Protocol):
304304
read_as: Union[None, Party, Collection[Party]] = None,
305305
act_as: Union[None, Party, Collection[Party]] = None,
306306
) -> Union[None, Awaitable[None]]: ...
307+
def get_ledger_end(self) -> Union[str, Awaitable[str]]: ...
307308
def archive(
308309
self,
309310
__contract_id: ContractId,

python/dazl/ledger/aio/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class Connection(_Connection, PackageService, Protocol):
169169
read_as: Union[None, Party, Collection[Party]] = None,
170170
act_as: Union[None, Party, Collection[Party]] = None,
171171
) -> ArchiveEvent: ...
172+
async def get_ledger_end(self) -> str: ...
172173
def query(
173174
self,
174175
__template_id: Union[str, TypeConName] = "*",

python/dazl/ledger/blocking/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class Connection(_Connection, PackageService, Protocol):
118118
read_as: Union[None, Party, Collection[Party]] = None,
119119
act_as: Union[None, Party, Collection[Party]] = None,
120120
) -> ArchiveEvent: ...
121+
def get_ledger_end(self) -> str: ...
121122
def query(
122123
self,
123124
__template_id: Union[str, TypeConName] = "*",

python/dazl/ledger/blocking/_aiowrapper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def archive_by_key(self, *args, **kwargs):
8282
fut = run_coroutine_threadsafe(self._conn.archive_by_key(*args, **kwargs), self._loop)
8383
return fut.result()
8484

85+
def get_ledger_end(self, *args, **kwargs):
86+
fut = run_coroutine_threadsafe(self._conn.get_ledger_end(*args, **kwargs), self._loop)
87+
return fut.result()
88+
8589
def query(self, *args, **kwargs):
8690
return QueryStreamThunk(self._conn.query(*args, **kwargs), self._loop)
8791

python/dazl/ledger/grpc/conn_aio.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,16 @@ def _command_meta(
552552

553553
# region Read API
554554

555+
async def get_ledger_end(self) -> "str":
556+
"""
557+
Return the offset at the end of the ledger.
558+
"""
559+
stub = lapipb.TransactionServiceStub(self.channel)
560+
561+
request = lapipb.GetLedgerEndRequest(ledger_id=self._config.access.ledger_id)
562+
response = await stub.GetLedgerEnd(request)
563+
return response.offset.absolute
564+
555565
def query(
556566
self,
557567
__template_id: Union[str, TypeConName] = "*",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2017-2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import dazl
5+
import pytest
6+
7+
8+
@pytest.mark.asyncio
9+
async def test_ledger_end(sandbox) -> None:
10+
async with dazl.connect(url=sandbox, admin=True) as conn:
11+
actual = await conn.get_ledger_end()
12+
13+
# the actual offset is unpredictable, but it will always be defined and non-empty
14+
assert actual

0 commit comments

Comments
 (0)