Skip to content

Commit

Permalink
Merge branch 'main' into feature/didx-reject
Browse files Browse the repository at this point in the history
  • Loading branch information
swcurran authored Aug 4, 2023
2 parents c3239bb + dcb858c commit 433e536
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 72 deletions.
5 changes: 3 additions & 2 deletions aries_cloudagent/core/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import hashlib
import json
import logging
from typing import Optional

from packaging import version as package_version
from qrcode import QRCode
Expand Down Expand Up @@ -677,7 +678,7 @@ async def queue_outbound(
self,
profile: Profile,
outbound: OutboundMessage,
inbound: InboundMessage = None,
inbound: Optional[InboundMessage] = None,
) -> OutboundSendStatus:
"""
Queue an outbound message for transport.
Expand All @@ -700,7 +701,7 @@ async def queue_outbound(
)
except ConnectionManagerError:
LOGGER.exception("Error preparing outbound message for transmission")
return
return OutboundSendStatus.UNDELIVERABLE
except (LedgerConfigError, LedgerTransactionError) as e:
LOGGER.error("Shutdown on ledger error %s", str(e))
if self.admin_server:
Expand Down
36 changes: 32 additions & 4 deletions aries_cloudagent/ledger/multiple_ledger/base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ...core.profile import Profile
from ...ledger.base import BaseLedger
from ...messaging.valid import IndyDID
from ...multitenant.manager import BaseMultitenantManager


class MultipleLedgerManagerError(BaseError):
Expand All @@ -31,10 +32,6 @@ async def get_write_ledgers(self) -> List[str]:
async def get_ledger_id_by_ledger_pool_name(self, pool_name: str) -> str:
"""Return ledger_id by ledger pool name."""

@abstractmethod
async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> str:
"""Set the write ledger for the profile."""

@abstractmethod
async def get_prod_ledgers(self) -> Mapping:
"""Return configured production ledgers."""
Expand Down Expand Up @@ -65,3 +62,34 @@ def extract_did_from_identifier(self, identifier: str) -> str:
return identifier.split(":")[-1]
else:
return identifier.split(":")[0]

async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> str:
"""Set the write ledger for the profile."""
if ledger_id not in self.writable_ledgers:
raise MultipleLedgerManagerError(
f"Provided Ledger identifier {ledger_id} is not write configurable."
)
extra_settings = {}
multi_tenant_mgr = self.profile.inject_or(BaseMultitenantManager)
multi_ledgers = self.production_ledgers | self.non_production_ledgers
if ledger_id in multi_ledgers:
profile.context.injector.bind_instance(
BaseLedger, multi_ledgers.get(ledger_id)
)
self._update_settings(profile.context.settings, ledger_id)
self._update_settings(extra_settings, ledger_id)
if multi_tenant_mgr:
await multi_tenant_mgr.update_wallet(
profile.context.settings["wallet.id"],
extra_settings,
)
return ledger_id
raise MultipleLedgerManagerError(f"No ledger info found for {ledger_id}.")

def _update_settings(self, settings, ledger_id: str):
endorser_info = self.get_endorser_info_for_ledger(ledger_id)
if endorser_info:
endorser_alias, endorser_did = endorser_info
settings["endorser.endorser_alias"] = endorser_alias
settings["endorser.endorser_public_did"] = endorser_did
settings["ledger.write_ledger"] = ledger_id
33 changes: 0 additions & 33 deletions aries_cloudagent/ledger/multiple_ledger/indy_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from ...core.profile import Profile
from ...ledger.base import BaseLedger
from ...ledger.error import LedgerError
from ...multitenant.manager import BaseMultitenantManager
from ...wallet.crypto import did_is_self_certified

from ..indy import IndySdkLedger
Expand Down Expand Up @@ -91,38 +90,6 @@ async def get_ledger_id_by_ledger_pool_name(self, pool_name: str) -> str:
"in either production_ledgers or non_production_ledgers"
)

async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> str:
"""Set the write ledger for the profile."""
if ledger_id not in self.writable_ledgers:
raise MultipleLedgerManagerError(
f"Provided Ledger identifier {ledger_id} is not write configurable."
)
extra_settings = {}
multi_tenant_mgr = self.profile.inject_or(BaseMultitenantManager)
multi_ledgers = self.production_ledgers | self.non_production_ledgers
if ledger_id in multi_ledgers:
profile.context.injector.bind_instance(
BaseLedger, multi_ledgers.get(ledger_id)
)
endorser_info = self.get_endorser_info_for_ledger(ledger_id)
if endorser_info:
endorser_alias, endorser_did = endorser_info
profile.context.settings["endorser.endorser_alias"] = endorser_alias
profile.context.settings["endorser.endorser_public_did"] = endorser_did
profile.context.settings["ledger.write_ledger"] = ledger_id
if multi_tenant_mgr:
extra_settings = {
"endorser.endorser_alias": endorser_alias,
"endorser.endorser_public_did": endorser_did,
"ledger.write_ledger": ledger_id,
}
await multi_tenant_mgr.update_wallet(
profile.context.settings["wallet.id"],
extra_settings,
)
return ledger_id
raise MultipleLedgerManagerError(f"No ledger info found for {ledger_id}.")

async def _get_ledger_by_did(
self,
ledger_id: str,
Expand Down
33 changes: 0 additions & 33 deletions aries_cloudagent/ledger/multiple_ledger/indy_vdr_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from ...core.profile import Profile
from ...ledger.base import BaseLedger
from ...ledger.error import LedgerError
from ...multitenant.manager import BaseMultitenantManager
from ...wallet.crypto import did_is_self_certified

from ..indy_vdr import IndyVdrLedger
Expand Down Expand Up @@ -74,38 +73,6 @@ async def get_nonprod_ledgers(self) -> Mapping:
"""Return non_production ledgers mapping."""
return self.non_production_ledgers

async def set_profile_write_ledger(self, ledger_id: str, profile: Profile) -> str:
"""Set the write ledger for the profile."""
if ledger_id not in self.writable_ledgers:
raise MultipleLedgerManagerError(
f"Provided Ledger identifier {ledger_id} is not write configurable."
)
extra_settings = {}
multi_tenant_mgr = self.profile.inject_or(BaseMultitenantManager)
multi_ledgers = self.production_ledgers | self.non_production_ledgers
if ledger_id in multi_ledgers:
profile.context.injector.bind_instance(
BaseLedger, multi_ledgers.get(ledger_id)
)
endorser_info = self.get_endorser_info_for_ledger(ledger_id)
if endorser_info:
endorser_alias, endorser_did = endorser_info
profile.context.settings["endorser.endorser_alias"] = endorser_alias
profile.context.settings["endorser.endorser_public_did"] = endorser_did
profile.context.settings["ledger.write_ledger"] = ledger_id
if multi_tenant_mgr:
extra_settings = {
"endorser.endorser_alias": endorser_alias,
"endorser.endorser_public_did": endorser_did,
"ledger.write_ledger": ledger_id,
}
await multi_tenant_mgr.update_wallet(
profile.context.settings["wallet.id"],
extra_settings,
)
return ledger_id
raise MultipleLedgerManagerError(f"No ledger info found for {ledger_id}.")

async def get_ledger_inst_by_id(self, ledger_id: str) -> Optional[BaseLedger]:
"""Return BaseLedger instance."""
return self.production_ledgers.get(
Expand Down

0 comments on commit 433e536

Please sign in to comment.