diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/models/credential_exchange.py b/aries_cloudagent/protocols/issue_credential/v1_0/models/credential_exchange.py index 6ef3a3af61..96b3bf50a6 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/models/credential_exchange.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/models/credential_exchange.py @@ -12,6 +12,7 @@ from .....indy.models.cred_precis import IndyCredInfo, IndyCredInfoSchema from .....indy.models.cred_request import IndyCredRequest, IndyCredRequestSchema from .....messaging.models.base_record import BaseExchangeRecord, BaseExchangeSchema +from .....messaging.models.light_webhook import LightWeightWebhook from .....messaging.valid import INDY_CRED_DEF_ID, INDY_SCHEMA_ID, UUIDFour from .....storage.base import StorageError @@ -221,6 +222,33 @@ async def save_error_state( except StorageError: LOGGER.exception("Error saving credential exchange error state") + # Override + async def emit_event(self, session: ProfileSession, payload: Any = None): + """ + Emit an event. + + Args: + session: The profile session to use + payload: The event payload + """ + + if not self.RECORD_TOPIC: + return + + if self.state: + topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}::{self.state}" + else: + topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}" + + if not payload: + payload = self.serialize() + + if session.profile.settings.get("transport.light_weight_webhook"): + payload = LightWeightWebhook(1, **self.__dict__) + payload = payload.__dict__ + + await session.profile.notify(topic, payload) + @property def record_value(self) -> dict: """Accessor for the JSON record value generated for this invitation.""" diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/cred_ex_record.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/cred_ex_record.py index fbbc0adaf5..7979c95a04 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/cred_ex_record.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/cred_ex_record.py @@ -8,6 +8,7 @@ from .....core.profile import ProfileSession from .....messaging.models.base_record import BaseExchangeRecord, BaseExchangeSchema +from .....messaging.models.light_webhook import LightWeightWebhook from .....messaging.valid import UUIDFour from .....storage.base import StorageError @@ -181,6 +182,33 @@ async def save_error_state( except StorageError as err: LOGGER.exception(err) + # Override + async def emit_event(self, session: ProfileSession, payload: Any = None): + """ + Emit an event. + + Args: + session: The profile session to use + payload: The event payload + """ + + if not self.RECORD_TOPIC: + return + + if self.state: + topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}::{self.state}" + else: + topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}" + + if not payload: + payload = self.serialize() + + if session.profile.settings.get("transport.light_weight_webhook"): + payload = LightWeightWebhook(2, **self.__dict__) + payload = payload.__dict__ + + await session.profile.notify(topic, payload) + @property def record_value(self) -> Mapping: """Accessor for the JSON record value generated for this credential exchange."""