Skip to content

Commit

Permalink
Move txn_submit from interface to concrete registry
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Jan 24, 2024
1 parent 4e8c4ea commit 057f425
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 57 deletions.
4 changes: 0 additions & 4 deletions aries_cloudagent/anoncreds/default/did_indy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,3 @@ async def update_revocation_list(
) -> RevListResult:
"""Update a revocation list on the registry."""
raise NotImplementedError()

async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str:
"""Submit a transaction to the ledger."""
raise NotImplementedError()
4 changes: 0 additions & 4 deletions aries_cloudagent/anoncreds/default/did_web/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,3 @@ async def update_revocation_list(
) -> RevListResult:
"""Update a revocation list on the registry."""
raise NotImplementedError()

async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str:
"""Submit a transaction to the ledger."""
raise NotImplementedError()
39 changes: 28 additions & 11 deletions aries_cloudagent/anoncreds/default/legacy_indy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@

from base58 import alphabet

from aries_cloudagent.anoncreds.default.legacy_indy.author import get_endorser_info
from aries_cloudagent.protocols.endorse_transaction.v1_0.manager import (
TransactionManager,
TransactionManagerError,
)
from aries_cloudagent.protocols.endorse_transaction.v1_0.util import is_author_role
from aries_cloudagent.storage.error import StorageError

from ....anoncreds.default.legacy_indy.author import get_endorser_info
from ....cache.base import BaseCache
from ....config.injection_context import InjectionContext
from ....core.profile import Profile
Expand All @@ -30,8 +23,18 @@
IndyLedgerRequestsExecutor,
)
from ....multitenant.base import BaseMultitenantManager
from ....revocation_anoncreds.models.issuer_cred_rev_record import IssuerCredRevRecord
from ....protocols.endorse_transaction.v1_0.manager import (
TransactionManager,
TransactionManagerError,
)
from ....protocols.endorse_transaction.v1_0.util import is_author_role
from ....revocation_anoncreds.models.issuer_cred_rev_record import (
IssuerCredRevRecord,
)
from ....revocation_anoncreds.recover import generate_ledger_rrrecovery_txn
from ....storage.error import StorageError
from ....utils import sentinel
from ....wallet.did_info import DIDInfo
from ...base import (
AnonCredsObjectAlreadyExists,
AnonCredsObjectNotFound,
Expand Down Expand Up @@ -823,7 +826,15 @@ async def fix_ledger_entry(

return (rev_reg_delta, recovery_txn, applied_txn)

async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str:
async def txn_submit(
self,
profile: Profile,
ledger_transaction: str,
sign: bool = None,
taa_accept: bool = None,
sign_did: DIDInfo = sentinel,
write_ledger: bool = True,
) -> str:
"""Submit a transaction to the ledger."""
ledger = profile.inject(BaseLedger)

Expand All @@ -832,7 +843,13 @@ async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str:

try:
return await shield(
ledger.txn_submit(ledger_transaction, sign=False, taa_accept=False)
ledger.txn_submit(
ledger_transaction,
sign=sign,
taa_accept=taa_accept,
sign_did=sign_did,
write_ledger=write_ledger,
)
)
except LedgerError as err:
raise AnonCredsRegistrationError(err.roll_up) from err
8 changes: 0 additions & 8 deletions aries_cloudagent/anoncreds/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""AnonCreds Registry."""
import json
import logging
from typing import List, Optional, Sequence

Expand Down Expand Up @@ -185,10 +184,3 @@ async def update_revocation_list(
return await registrar.update_revocation_list(
profile, rev_reg_def, prev_list, curr_list, revoked, options
)

async def txn_submit(self, profile: Profile, ledger_transaction: str) -> str:
"""Submit a transaction to the ledger."""
registrar = await self._registrar_for_identifier(
json.loads(ledger_transaction)["endorser"]
)
return await registrar.txn_submit(profile, ledger_transaction)
7 changes: 6 additions & 1 deletion aries_cloudagent/ledger/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ async def send_schema_anoncreds(
attribute_names: A list of schema attributes
"""
from aries_cloudagent.anoncreds.default.legacy_indy.registry import (
LegacyIndyRegistry,
)

public_info = await self.get_wallet_public_did()
if not public_info:
Expand Down Expand Up @@ -628,7 +631,9 @@ async def send_schema_anoncreds(
)

try:
resp = await self.txn_submit(
legacy_indy_registry = LegacyIndyRegistry()
resp = await legacy_indy_registry.txn_submit(
self.profile,
schema_req,
sign=True,
sign_did=public_info,
Expand Down
14 changes: 8 additions & 6 deletions aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import uuid
from asyncio import shield

from aries_cloudagent.anoncreds.events import notify_anoncreds_schema_event
from aries_cloudagent.anoncreds.registry import AnonCredsRegistry

from ....anoncreds.events import notify_anoncreds_schema_event
from ....connections.models.conn_record import ConnRecord
from ....core.error import BaseError
from ....core.profile import Profile
Expand Down Expand Up @@ -420,9 +418,13 @@ async def complete_transaction(
self._profile.context.settings.get_value("wallet.type")
== "askar-anoncreds"
):
anoncreds_registry = self._profile.inject(AnonCredsRegistry)
ledger_response_json = await anoncreds_registry.txn_submit(
self._profile, ledger_transaction
from aries_cloudagent.anoncreds.default.legacy_indy.registry import (
LegacyIndyRegistry,
)

legacy_indy_registry = LegacyIndyRegistry()
ledger_response_json = await legacy_indy_registry.txn_submit(
self._profile, ledger_transaction, sign=False, taa_accept=False
)
else:
ledger = self._profile.inject(BaseLedger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import uuid
from unittest import IsolatedAsyncioTestCase

from aries_cloudagent.anoncreds.registry import AnonCredsRegistry
from aries_cloudagent.tests import mock

from .....admin.request_context import AdminRequestContext
from .....anoncreds.default.legacy_indy.registry import LegacyIndyRegistry
from .....cache.base import BaseCache
from .....cache.in_memory import InMemoryCache
from .....connections.models.conn_record import ConnRecord
from .....ledger.base import BaseLedger
from .....storage.error import StorageNotFoundError
from .....tests import mock
from .....wallet.base import BaseWallet
from .....wallet.did_method import SOV, DIDMethods
from .....wallet.key_type import ED25519
Expand Down Expand Up @@ -498,23 +497,21 @@ async def test_complete_transaction(self):

assert transaction_record.state == TransactionRecord.STATE_TRANSACTION_ACKED

async def test_complete_transaction_anoncreds(self):
@mock.patch.object(
LegacyIndyRegistry,
"txn_submit",
return_value=json.dumps(
{
"result": {
"txn": {"type": "101", "metadata": {"from": TEST_DID}},
"txnMetadata": {"txnId": SCHEMA_ID},
}
}
),
)
async def test_complete_transaction_anoncreds(self, mock_txn_submit):
self.profile.settings.set_value("wallet.type", "askar-anoncreds")
self.profile.context.injector.bind_instance(
AnonCredsRegistry,
mock.MagicMock(
txn_submit=mock.CoroutineMock(
return_value=json.dumps(
{
"result": {
"txn": {"type": "101", "metadata": {"from": TEST_DID}},
"txnMetadata": {"txnId": SCHEMA_ID},
}
}
)
)
),
)

transaction_record = await self.manager.create_record(
messages_attach=self.test_messages_attach,
connection_id=self.test_connection_id,
Expand Down Expand Up @@ -548,10 +545,7 @@ async def test_complete_transaction_anoncreds(self):
save_record.assert_called_once()

assert transaction_record.state == TransactionRecord.STATE_TRANSACTION_ACKED
# txn submit called from anoncreds registry
assert self.profile.context._injector.get_provider(
AnonCredsRegistry
)._instance.txn_submit.called
assert mock_txn_submit.called

async def test_create_refuse_response_bad_state(self):
transaction_record = await self.manager.create_record(
Expand Down

0 comments on commit 057f425

Please sign in to comment.