diff --git a/src/_zkapauthorizer/model.py b/src/_zkapauthorizer/model.py index 726be23690610c5681067e6f857f0c2a345bf30b..8b289f4448aa1b4eff009045d9bb556213cb490a 100644 --- a/src/_zkapauthorizer/model.py +++ b/src/_zkapauthorizer/model.py @@ -362,19 +362,6 @@ class VoucherStore(object): list((token, group_id) for token in unblinded_tokens), ) - @with_cursor - def insert_unblinded_tokens(self, cursor, unblinded_tokens, group_id): - """ - Store some unblinded tokens, for example as part of a backup-restore - process. - - :param list[str] unblinded_tokens: The unblinded tokens to store. - - :param int group_id: The unique identifier of the redemption group to - which these tokens belong. - """ - self._insert_unblinded_tokens(cursor, unblinded_tokens, group_id) - @with_cursor def insert_unblinded_tokens_for_voucher( self, cursor, voucher, public_key, unblinded_tokens, completed, spendable @@ -658,22 +645,6 @@ class VoucherStore(object): """, ) - @with_cursor - def backup(self, cursor): - """ - Read out all state necessary to recreate this database in the event it is - lost. - """ - cursor.execute( - """ - SELECT [token] FROM [unblinded-tokens] ORDER BY [rowid] - """, - ) - tokens = cursor.fetchall() - return { - "unblinded-tokens": list(token for (token,) in tokens), - } - def start_lease_maintenance(self): """ Get an object which can track a newly started round of lease maintenance diff --git a/src/_zkapauthorizer/resource.py b/src/_zkapauthorizer/resource.py index 2a37249287e27d0f1f1dd7ab4d1abd32d8ad6a16..fcea68b9d50b4c08fe71229a7032dc30a40cc17f 100644 --- a/src/_zkapauthorizer/resource.py +++ b/src/_zkapauthorizer/resource.py @@ -21,9 +21,7 @@ vouchers for fresh tokens. In the future it should also allow users to read statistics about token usage. """ -from itertools import islice -from json import load, loads -from sys import maxsize +from json import loads from twisted.logger import Logger from twisted.web.http import BAD_REQUEST @@ -178,8 +176,8 @@ def authorizationless_resource_tree( ), ) root.putChild( - b"unblinded-token", - _UnblindedTokenCollection( + b"lease-maintenance", + _LeaseMaintenanceResource( store, controller, ), @@ -321,10 +319,10 @@ class _ProjectVersion(Resource): ) -class _UnblindedTokenCollection(Resource): +class _LeaseMaintenanceResource(Resource): """ - This class implements inspection of unblinded tokens. Users **GET** this - resource to find out about unblinded tokens in the system. + This class implements inspection of lease maintenance activity. Users + **GET** this resource to learn about lease maintenance spending. """ _log = Logger() @@ -336,40 +334,16 @@ class _UnblindedTokenCollection(Resource): def render_GET(self, request): """ - Retrieve some unblinded tokens and associated information. + Retrieve the spending information. """ application_json(request) - state = self._store.backup() - unblinded_tokens = state["unblinded-tokens"] - - limit = request.args.get(b"limit", [None])[0] - if limit is not None: - limit = min(maxsize, int(limit)) - - position = request.args.get(b"position", [b""])[0].decode("utf-8") - return dumps_utf8( { - "total": len(unblinded_tokens), - "spendable": self._store.count_unblinded_tokens(), - "unblinded-tokens": list( - islice( - (token for token in unblinded_tokens if token > position), limit - ) - ), + "total": self._store.count_unblinded_tokens(), "lease-maintenance-spending": self._lease_maintenance_activity(), } ) - def render_POST(self, request): - """ - Store some unblinded tokens. - """ - application_json(request) - unblinded_tokens = load(request.content)["unblinded-tokens"] - self._store.insert_unblinded_tokens(unblinded_tokens, group_id=0) - return dumps_utf8({}) - def _lease_maintenance_activity(self): activity = self._store.get_latest_lease_maintenance_activity() if activity is None: