@@ -312,6 +312,7 @@ async def _submit(
312
312
taa_accept : Optional [bool ] = None ,
313
313
sign_did : DIDInfo = sentinel ,
314
314
write_ledger : bool = True ,
315
+ profile : Optional [Profile ] = None , # <-- ADD profile parameter
315
316
) -> dict :
316
317
"""Sign and submit request to ledger.
317
318
@@ -321,9 +322,10 @@ async def _submit(
321
322
taa_accept: whether to apply TAA acceptance to the (signed, write) request
322
323
sign_did: override the signing DID
323
324
write_ledger: whether to write the request to the ledger
324
-
325
+ profile: The profile context used for the request
325
326
"""
326
327
328
+ current_profile = profile or self .profile
327
329
if not self .pool_handle :
328
330
raise ClosedPoolError (
329
331
f"Cannot sign and submit request to closed pool '{ self .pool_name } '"
@@ -336,7 +338,7 @@ async def _submit(
336
338
337
339
if sign is None or sign :
338
340
if sign_did is sentinel :
339
- sign_did = await self .get_wallet_public_did ()
341
+ sign_did = await self .get_wallet_public_did (profile = current_profile )
340
342
if sign is None :
341
343
sign = bool (sign_did )
342
344
@@ -345,7 +347,9 @@ async def _submit(
345
347
raise BadLedgerRequestError ("Cannot sign request without a public DID" )
346
348
347
349
if taa_accept or taa_accept is None :
348
- acceptance = await self .get_latest_txn_author_acceptance ()
350
+ acceptance = await self .get_latest_txn_author_acceptance (
351
+ profile = current_profile
352
+ )
349
353
if acceptance :
350
354
acceptance = {
351
355
"taaDigest" : acceptance ["digest" ],
@@ -354,12 +358,16 @@ async def _submit(
354
358
}
355
359
request .set_txn_author_agreement_acceptance (acceptance )
356
360
357
- async with self . profile .session () as session :
361
+ async with current_profile .session () as session :
358
362
wallet = session .inject (BaseWallet )
359
- request .set_signature (
360
- await wallet .sign_message (request .signature_input , sign_did .verkey )
361
- )
362
- del wallet
363
+ try :
364
+ signature = await wallet .sign_message (
365
+ message = request .signature_input ,
366
+ from_verkey = sign_did .verkey ,
367
+ )
368
+ request .set_signature (signature )
369
+ except WalletNotFoundError as e :
370
+ raise WalletNotFoundError ("Missing key for sign operation" ) from e
363
371
364
372
if not write_ledger :
365
373
return json .loads (request .body )
@@ -368,6 +376,10 @@ async def _submit(
368
376
request_result = await self .pool .handle .submit_request (request )
369
377
except VdrError as err :
370
378
raise LedgerTransactionError ("Ledger request error" ) from err
379
+ except Exception as e :
380
+ raise LedgerTransactionError (
381
+ "Unexpected error during ledger submission"
382
+ ) from e
371
383
372
384
return request_result
373
385
@@ -1003,15 +1015,18 @@ async def accept_txn_author_agreement(
1003
1015
cache_key = TAA_ACCEPTED_RECORD_TYPE + "::" + self .profile .name
1004
1016
await cache .set (cache_key , acceptance , self .pool .cache_duration )
1005
1017
1006
- async def get_latest_txn_author_acceptance (self ) -> dict :
1018
+ async def get_latest_txn_author_acceptance (
1019
+ self , profile : Optional [Profile ] = None
1020
+ ) -> dict :
1007
1021
"""Look up the latest TAA acceptance."""
1008
- cache_key = TAA_ACCEPTED_RECORD_TYPE + "::" + self .profile .name
1022
+ current_profile = profile or self .profile
1023
+ cache_key = TAA_ACCEPTED_RECORD_TYPE + "::" + current_profile .name
1009
1024
acceptance = self .pool .cache and await self .pool .cache .get (cache_key )
1010
1025
if not acceptance :
1011
1026
tag_filter = {"pool_name" : self .pool_name }
1012
- async with self . profile .session () as session :
1027
+ async with current_profile .session () as session :
1013
1028
storage = session .inject (BaseStorage )
1014
- cache = self . profile .inject_or (BaseCache )
1029
+ cache = current_profile .inject_or (BaseCache )
1015
1030
found = await storage .find_all_records (
1016
1031
TAA_ACCEPTED_RECORD_TYPE , tag_filter
1017
1032
)
@@ -1226,24 +1241,34 @@ async def send_revoc_reg_entry(
1226
1241
issuer_did : Optional [str ] = None ,
1227
1242
write_ledger : bool = True ,
1228
1243
endorser_did : Optional [str ] = None ,
1244
+ profile : Optional [Profile ] = None ,
1229
1245
) -> dict :
1230
1246
"""Publish a revocation registry entry to the ledger."""
1231
- async with self .profile .session () as session :
1247
+
1248
+ current_profile = profile or self .profile
1249
+ async with current_profile .session () as session :
1232
1250
wallet = session .inject (BaseWallet )
1233
- if issuer_did :
1234
- did_info = await wallet .get_local_did (issuer_did )
1235
- else :
1251
+ try :
1236
1252
did_info = await wallet .get_public_did ()
1237
- del wallet
1253
+ except Exception :
1254
+ raise
1255
+ finally :
1256
+ del wallet
1257
+
1238
1258
if not did_info :
1239
1259
raise LedgerTransactionError (
1240
1260
"No issuer DID found for revocation registry entry"
1241
1261
)
1242
1262
1243
- if self .profile .context .settings .get ("wallet.type" ) == "askar-anoncreds" :
1244
- from acapy_agent .anoncreds .default .legacy_indy .registry import (
1245
- LegacyIndyRegistry ,
1246
- )
1263
+ wallet_type = current_profile .context .settings .get ("wallet.type" )
1264
+ if wallet_type == "askar-anoncreds" :
1265
+ try :
1266
+ from acapy_agent .anoncreds .default .legacy_indy .registry import (
1267
+ LegacyIndyRegistry ,
1268
+ )
1269
+
1270
+ except ImportError :
1271
+ raise
1247
1272
1248
1273
revoc_reg_entry_req = await self ._create_revoc_reg_entry_request (
1249
1274
did_info ,
@@ -1253,17 +1278,23 @@ async def send_revoc_reg_entry(
1253
1278
write_ledger = write_ledger ,
1254
1279
endorser_did = endorser_did ,
1255
1280
)
1281
+
1256
1282
if endorser_did and not write_ledger :
1283
+ LOGGER .debug ("Adding endorser to request" )
1257
1284
revoc_reg_entry_req .set_endorser (endorser_did )
1258
1285
1259
1286
legacy_indy_registry = LegacyIndyRegistry ()
1260
- resp = await legacy_indy_registry .txn_submit (
1261
- self ,
1262
- revoc_reg_entry_req ,
1263
- sign = True ,
1264
- sign_did = did_info ,
1265
- write_ledger = write_ledger ,
1266
- )
1287
+ try :
1288
+ resp = await legacy_indy_registry .txn_submit (
1289
+ self ,
1290
+ revoc_reg_entry_req ,
1291
+ sign = True ,
1292
+ sign_did = did_info ,
1293
+ write_ledger = write_ledger ,
1294
+ profile = current_profile ,
1295
+ )
1296
+ except Exception :
1297
+ raise
1267
1298
1268
1299
if not write_ledger :
1269
1300
return revoc_reg_id , {"signed_txn" : resp }
@@ -1284,22 +1315,36 @@ async def send_revoc_reg_entry(
1284
1315
revoc_def_type ,
1285
1316
json .dumps (revoc_reg_entry ),
1286
1317
)
1318
+
1287
1319
if endorser_did and not write_ledger :
1288
1320
request .set_endorser (endorser_did )
1321
+
1289
1322
except VdrError as err :
1290
1323
raise LedgerError (
1291
1324
"Exception when sending revocation registry entry"
1292
1325
) from err
1293
- resp = await self ._submit (
1294
- request , True , sign_did = did_info , write_ledger = write_ledger
1295
- )
1296
- return {"result" : resp }
1297
1326
1298
- async def get_wallet_public_did (self ) -> DIDInfo :
1327
+ try :
1328
+ resp = await self ._submit (
1329
+ request ,
1330
+ True ,
1331
+ sign_did = did_info ,
1332
+ write_ledger = write_ledger ,
1333
+ profile = current_profile ,
1334
+ )
1335
+ return {"result" : resp }
1336
+ except Exception as err :
1337
+ raise LedgerError (
1338
+ "Exception when sending revocation registry entry"
1339
+ ) from err
1340
+
1341
+ async def get_wallet_public_did (self , profile : Optional [Profile ] = None ) -> DIDInfo :
1299
1342
"""Fetch the public DID from the wallet."""
1300
- async with self .profile .session () as session :
1343
+ current_profile = profile or self .profile
1344
+ async with current_profile .session () as session :
1301
1345
wallet = session .inject (BaseWallet )
1302
- return await wallet .get_public_did ()
1346
+ public_did = await wallet .get_public_did ()
1347
+ return public_did
1303
1348
1304
1349
async def txn_endorse (
1305
1350
self ,
@@ -1334,15 +1379,21 @@ async def txn_submit(
1334
1379
taa_accept : Optional [bool ] = None ,
1335
1380
sign_did : DIDInfo = sentinel ,
1336
1381
write_ledger : bool = True ,
1382
+ profile : Optional [Profile ] = None ,
1337
1383
) -> str :
1338
1384
"""Write the provided (signed and possibly endorsed) transaction to the ledger."""
1339
- resp = await self ._submit (
1340
- request_json ,
1341
- sign = sign ,
1342
- taa_accept = taa_accept ,
1343
- sign_did = sign_did ,
1344
- write_ledger = write_ledger ,
1345
- )
1385
+ kwargs = {
1386
+ "sign" : sign ,
1387
+ "taa_accept" : taa_accept ,
1388
+ "sign_did" : sign_did ,
1389
+ "write_ledger" : write_ledger ,
1390
+ }
1391
+
1392
+ if profile :
1393
+ kwargs ["profile" ] = profile
1394
+
1395
+ resp = await self ._submit (request_json , ** kwargs )
1396
+
1346
1397
if write_ledger :
1347
1398
# match the format returned by indy sdk
1348
1399
resp = {"op" : "REPLY" , "result" : resp }
0 commit comments