diff --git a/aries_cloudagent/ledger/routes.py b/aries_cloudagent/ledger/routes.py index ed05253c42..db3b1ddd19 100644 --- a/aries_cloudagent/ledger/routes.py +++ b/aries_cloudagent/ledger/routes.py @@ -232,16 +232,20 @@ async def ledger_get_taa(request: web.BaseRequest): reason += ": missing wallet-type?" raise web.HTTPForbidden(reason=reason) - taa_info = await ledger.get_txn_author_agreement() - accepted = None - if taa_info["taa_required"]: - accept_record = await ledger.get_latest_txn_author_acceptance() - if accept_record: - accepted = { - "mechanism": accept_record["mechanism"], - "time": accept_record["time"], - } - taa_info["taa_accepted"] = accepted + async with ledger: + try: + taa_info = await ledger.get_txn_author_agreement() + accepted = None + if taa_info["taa_required"]: + accept_record = await ledger.get_latest_txn_author_acceptance() + if accept_record: + accepted = { + "mechanism": accept_record["mechanism"], + "time": accept_record["time"], + } + taa_info["taa_accepted"] = accepted + except LedgerError as err: + raise web.HTTPBadRequest(reason=err.roll_up) from err return web.json_response({"result": taa_info}) @@ -268,18 +272,25 @@ async def ledger_accept_taa(request: web.BaseRequest): raise web.HTTPForbidden(reason=reason) accept_input = await request.json() - taa_info = await ledger.get_txn_author_agreement() - if not taa_info["taa_required"]: - raise web.HTTPBadRequest(reason=f"Ledger {ledger.pool_name} TAA not available") - taa_record = { - "version": accept_input["version"], - "text": accept_input["text"], - "digest": ledger.taa_digest(accept_input["version"], accept_input["text"]), - } - try: - await ledger.accept_txn_author_agreement(taa_record, accept_input["mechanism"]) - except StorageError as err: - raise web.HTTPBadRequest(reason=err.roll_up) from err + async with ledger: + try: + taa_info = await ledger.get_txn_author_agreement() + if not taa_info["taa_required"]: + raise web.HTTPBadRequest( + reason=f"Ledger {ledger.pool_name} TAA not available" + ) + taa_record = { + "version": accept_input["version"], + "text": accept_input["text"], + "digest": ledger.taa_digest( + accept_input["version"], accept_input["text"] + ), + } + await ledger.accept_txn_author_agreement( + taa_record, accept_input["mechanism"] + ) + except (LedgerError, StorageError) as err: + raise web.HTTPBadRequest(reason=err.roll_up) from err return web.json_response({}) diff --git a/aries_cloudagent/verifier/indy.py b/aries_cloudagent/verifier/indy.py index 7018d9be57..57ee327022 100644 --- a/aries_cloudagent/verifier/indy.py +++ b/aries_cloudagent/verifier/indy.py @@ -65,18 +65,19 @@ async def pre_verify(self, pres_req: dict, pres: dict) -> (PreVerifyResult, str) if "proof" not in pres: return (PreVerifyResult.INCOMPLETE, "Missing 'proof'") - for (index, ident) in enumerate(pres["identifiers"]): - if not ident.get("timestamp"): - cred_def_id = ident["cred_def_id"] - cred_def = await self.ledger.get_credential_definition(cred_def_id) - if cred_def["value"].get("revocation"): - return ( - PreVerifyResult.INCOMPLETE, - ( - f"Missing timestamp in presentation identifier #{index} " - f"for cred def id {cred_def_id}" - ), - ) + async with self.ledger: + for (index, ident) in enumerate(pres["identifiers"]): + if not ident.get("timestamp"): + cred_def_id = ident["cred_def_id"] + cred_def = await self.ledger.get_credential_definition(cred_def_id) + if cred_def["value"].get("revocation"): + return ( + PreVerifyResult.INCOMPLETE, + ( + f"Missing timestamp in presentation identifier " + f"#{index} for cred def id {cred_def_id}" + ), + ) for (uuid, req_pred) in pres_req["requested_predicates"].items(): try: