-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code to allow endorser to write the transaction to ledger, and code t…
…o save record in author's wallet. Signed-off-by: Harsh Multani <[email protected]>
- Loading branch information
1 parent
adf8256
commit d9d90a1
Showing
8 changed files
with
292 additions
and
31 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...dagent/protocols/endorse_transaction/v1_0/handlers/transaction_acknowledgement_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Transaction acknowledgement message handler.""" | ||
|
||
from .....messaging.base_handler import ( | ||
BaseHandler, | ||
BaseResponder, | ||
HandlerException, | ||
RequestContext, | ||
) | ||
|
||
from ..manager import TransactionManager, TransactionManagerError | ||
from ..messages.transaction_acknowledgement import TransactionAcknowledgement | ||
|
||
|
||
class TransactionAcknowledgementHandler(BaseHandler): | ||
"""Message handler class for Acknowledging transaction.""" | ||
|
||
async def handle(self, context: RequestContext, responder: BaseResponder): | ||
""" | ||
Handle transaction acknowledgement message. | ||
Args: | ||
context: Request context | ||
responder: Responder callback | ||
""" | ||
|
||
self._logger.debug( | ||
f"TransactionAcknowledgementHandler called with context {context}" | ||
) | ||
assert isinstance(context.message, TransactionAcknowledgement) | ||
|
||
if not context.connection_ready: | ||
raise HandlerException("No connection established") | ||
|
||
profile_session = await context.session() | ||
mgr = TransactionManager(profile_session) | ||
try: | ||
await mgr.receive_transaction_acknowledgement( | ||
context.message, context.connection_record.connection_id | ||
) | ||
except TransactionManagerError: | ||
self._logger.exception("Error receiving transaction acknowledgement") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
aries_cloudagent/protocols/endorse_transaction/v1_0/messages/transaction_acknowledgement.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Represents a transaction acknowledgement message.""" | ||
|
||
from marshmallow import EXCLUDE, fields | ||
|
||
from .....messaging.valid import UUIDFour | ||
from .....messaging.ack.message import Ack, AckSchema | ||
|
||
from ..message_types import TRANSACTION_ACKNOWLEDGEMENT, PROTOCOL_PACKAGE | ||
|
||
HANDLER_CLASS = ( | ||
f"{PROTOCOL_PACKAGE}.handlers" | ||
".transaction_acknowledgement_handler.TransactionAcknowledgementHandler" | ||
) | ||
|
||
|
||
class TransactionAcknowledgement(Ack): | ||
"""Class representing a transaction acknowledgement message.""" | ||
|
||
class Meta: | ||
"""Metadata for a transaction acknowledgement message.""" | ||
|
||
handler_class = HANDLER_CLASS | ||
message_type = TRANSACTION_ACKNOWLEDGEMENT | ||
schema_class = "TransactionAcknowledgementSchema" | ||
|
||
def __init__( | ||
self, | ||
*, | ||
thread_id: str = None, | ||
**kwargs, | ||
): | ||
""" | ||
Initialize a transaction acknowledgement object. | ||
Args: | ||
thread_id: Thread id of transaction record | ||
""" | ||
super().__init__(**kwargs) | ||
self.thread_id = thread_id | ||
|
||
|
||
class TransactionAcknowledgementSchema(AckSchema): | ||
"""Transaction Acknowledgement schema class.""" | ||
|
||
class Meta: | ||
"""Transaction Acknowledgement metadata.""" | ||
|
||
model_class = TransactionAcknowledgement | ||
unknown = EXCLUDE | ||
|
||
thread_id = fields.Str(required=True, example=UUIDFour.EXAMPLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.