diff --git a/aries_cloudagent/ledger/routes.py b/aries_cloudagent/ledger/routes.py index 46aa2612fe..1949f2c579 100644 --- a/aries_cloudagent/ledger/routes.py +++ b/aries_cloudagent/ledger/routes.py @@ -407,10 +407,8 @@ async def register_ledger_nym(request: web.BaseRequest): if endorser_write_txn else None ), - endorser_write_txn=endorser_write_txn, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) txn = transaction.serialize() except (StorageError, TransactionManagerError) as err: diff --git a/aries_cloudagent/messaging/credential_definitions/routes.py b/aries_cloudagent/messaging/credential_definitions/routes.py index 186141bf38..d0068d916a 100644 --- a/aries_cloudagent/messaging/credential_definitions/routes.py +++ b/aries_cloudagent/messaging/credential_definitions/routes.py @@ -349,7 +349,6 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq transaction=transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err diff --git a/aries_cloudagent/messaging/schemas/routes.py b/aries_cloudagent/messaging/schemas/routes.py index 53366c56c7..c5a9952601 100644 --- a/aries_cloudagent/messaging/schemas/routes.py +++ b/aries_cloudagent/messaging/schemas/routes.py @@ -316,7 +316,6 @@ async def schemas_send_schema(request: web.BaseRequest): transaction=transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/endorsed_transaction_response_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/endorsed_transaction_response_handler.py index 88dff4f6e8..0ce3a060c4 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/endorsed_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/endorsed_transaction_response_handler.py @@ -35,8 +35,9 @@ async def handle(self, context: RequestContext, responder: BaseResponder): mgr = TransactionManager(context.profile) try: transaction = await mgr.receive_endorse_response(context.message) - except TransactionManagerError: + except TransactionManagerError as err: self._logger.exception("Error receiving endorsed transaction response") + raise HandlerException(str(err)) # Automatically write transaction if flag is set if context.settings.get("endorser.auto_write"): @@ -52,3 +53,4 @@ async def handle(self, context: RequestContext, responder: BaseResponder): ) except (StorageError, TransactionManagerError) as err: self._logger.exception(err) + raise HandlerException(str(err)) diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py index 5a33ffdb02..64cc194d10 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py @@ -63,9 +63,7 @@ async def test_called_x(self): request_context.connection_ready = True handler = test_module.EndorsedTransactionResponseHandler() responder = MockResponder() - await handler.handle(request_context, responder) + with self.assertRaises(test_module.HandlerException): + await handler.handle(request_context, responder) - mock_tran_mgr.return_value.receive_endorse_response.assert_called_once_with( - request_context.message - ) assert not responder.messages diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py index 8952808c4d..18f5664010 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py @@ -114,7 +114,7 @@ async def create_request( signature: str = None, signed_request: dict = None, expires_time: str = None, - endorser_write_txn: bool = None, + endorser_write_txn: bool = False, author_goal_code: str = None, signer_goal_code: str = None, ): @@ -207,8 +207,6 @@ async def receive_request(self, request: TransactionRequest, connection_id: str) return transaction - # todo - implementing changes for writing final transaction to the ledger - # (For Sign Transaction Protocol) async def create_endorse_response( self, transaction: TransactionRecord, @@ -331,19 +329,12 @@ async def create_endorse_response( transaction.endorser_write_txn and txn_goal_code == TransactionRecord.ENDORSE_TRANSACTION ): - # running as the endorser, we've been asked to write the transaction - ledger_response = await self.complete_transaction(transaction, True) - endorsed_transaction_response = EndorsedTransactionResponse( - transaction_id=transaction.thread_id, - thread_id=transaction._id, - signature_response=signature_response, - state=TransactionRecord.STATE_TRANSACTION_ACKED, - endorser_did=endorser_did, - ledger_response=ledger_response, + # no longer supported - if the author asks the endorser to write + # the transaction, raise an error + raise TransactionManagerError( + "Operation not supported, endorser cannot write the ledger transaction" ) - return transaction, endorsed_transaction_response - endorsed_transaction_response = EndorsedTransactionResponse( transaction_id=transaction.thread_id, thread_id=transaction._id, @@ -385,14 +376,10 @@ async def receive_endorse_response(self, response: EndorsedTransactionResponse): await transaction.save(session, reason="Received an endorsed response") # this scenario is where the author has asked the endorser to write the ledger + # we are not supporting endorser ledger writes ... if transaction.endorser_write_txn: - connection_id = transaction.connection_id - async with self._profile.session() as session: - connection_record = await ConnRecord.retrieve_by_id( - session, connection_id - ) - await self.endorsed_txn_post_processing( - transaction, response.ledger_response, connection_record + raise TransactionManagerError( + "Endorser ledger writes are no longer supported" ) return transaction @@ -415,9 +402,18 @@ async def complete_transaction( ledger_transaction = transaction.messages_attach[0]["data"]["json"] - # check if we (author) have requested the endorser to write the transaction - if (endorser and transaction.endorser_write_txn) or ( - (not endorser) and (not transaction.endorser_write_txn) + # check our goal code! + txn_goal_code = ( + transaction.signature_request[0]["signer_goal_code"] + if transaction.signature_request + and "signer_goal_code" in transaction.signature_request[0] + else TransactionRecord.ENDORSE_TRANSACTION + ) + + # if we are the author, we need to write the endorsed ledger transaction ... + # ... EXCEPT for DID transactions, which the endorser will write + if (not endorser) and ( + txn_goal_code != TransactionRecord.WRITE_DID_TRANSACTION ): ledger = self._profile.inject(BaseLedger) if not ledger: @@ -447,9 +443,11 @@ async def complete_transaction( await transaction.save(session, reason="Completed transaction") # this scenario is where the endorser is writing the transaction - # (called from self.create_endorse_response()) + # shouldn't get to this point, but check and raise an error just in case if endorser and transaction.endorser_write_txn: - return ledger_response + raise TransactionManagerError( + "Operation not supported, endorser cannot write the ledger transaction" + ) connection_id = transaction.connection_id async with self._profile.session() as session: diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/transaction_request.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/transaction_request.py index 48864805de..4bd8154663 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/transaction_request.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/transaction_request.py @@ -117,8 +117,9 @@ class Meta: required=False, metadata={ "description": ( - "If True, Endorser will write the transaction after endorsing it" + "Request Endorser to write the ledger transaction, " + "this parameter is deprecated and no longer supported." ), - "example": True, + "example": False, }, ) diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/models/transaction_record.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/models/transaction_record.py index e41863b3e1..17cb287ecb 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/models/transaction_record.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/models/transaction_record.py @@ -244,8 +244,9 @@ class Meta: required=False, metadata={ "description": ( - "If True, Endorser will write the transaction after endorsing it" + "Request Endorser to write the ledger transaction, " + "this parameter is deprecated and no longer supported." ), - "example": True, + "example": False, }, ) diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py index 57c0b054e4..1013320117 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py @@ -1,6 +1,5 @@ """Endorse Transaction handling admin routes.""" -import json import logging from aiohttp import web @@ -116,17 +115,6 @@ class DateSchema(OpenAPISchema): ) -class EndorserWriteLedgerTransactionSchema(OpenAPISchema): - """Sets endorser_write_txn. Option for the endorser to write the transaction.""" - - endorser_write_txn = fields.Boolean( - required=False, - metadata={ - "description": "Endorser will write the transaction after endorsing it" - }, - ) - - class EndorserInfoSchema(OpenAPISchema): """Class for user to input the DID associated with the requested endorser.""" @@ -203,7 +191,6 @@ async def transactions_retrieve(request: web.BaseRequest): summary="For author to send a transaction request", ) @querystring_schema(TranIdMatchInfoSchema()) -@querystring_schema(EndorserWriteLedgerTransactionSchema()) @request_schema(DateSchema()) @response_schema(TransactionRecordSchema(), 200) async def transaction_create_request(request: web.BaseRequest): @@ -218,7 +205,7 @@ async def transaction_create_request(request: web.BaseRequest): context: AdminRequestContext = request["context"] outbound_handler = request["outbound_message_router"] transaction_id = request.query.get("tran_id") - endorser_write_txn = json.loads(request.query.get("endorser_write_txn", "false")) + endorser_write_txn = False body = await request.json() expires_time = body.get("expires_time") diff --git a/aries_cloudagent/revocation/routes.py b/aries_cloudagent/revocation/routes.py index 228aeb1cd5..8a4dd0b007 100644 --- a/aries_cloudagent/revocation/routes.py +++ b/aries_cloudagent/revocation/routes.py @@ -1270,7 +1270,6 @@ async def send_rev_reg_def(request: web.BaseRequest): transaction=transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err @@ -1388,7 +1387,6 @@ async def send_rev_reg_entry(request: web.BaseRequest): transaction=transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err @@ -1543,7 +1541,6 @@ async def generate(rr_record: IssuerRevRegRecord) -> dict: transaction=revo_transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise TransactionManagerError(reason=err.roll_up) from err @@ -1625,7 +1622,6 @@ async def on_revocation_entry_event(profile: Profile, event: Event): transaction=revo_transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise RevocationError(err.roll_up) from err diff --git a/aries_cloudagent/wallet/routes.py b/aries_cloudagent/wallet/routes.py index d9baa3770e..e394df1b2a 100644 --- a/aries_cloudagent/wallet/routes.py +++ b/aries_cloudagent/wallet/routes.py @@ -717,7 +717,6 @@ async def wallet_set_public_did(request: web.BaseRequest): transaction=transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err @@ -975,7 +974,6 @@ async def wallet_set_did_endpoint(request: web.BaseRequest): transaction=transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err @@ -1233,7 +1231,6 @@ async def on_register_nym_event(profile: Profile, event: Event): transaction=transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, - # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: # log the error, but continue diff --git a/demo/features/0586-sign-transaction.feature b/demo/features/0586-sign-transaction.feature index b7427d9c20..6b50f24867 100644 --- a/demo/features/0586-sign-transaction.feature +++ b/demo/features/0586-sign-transaction.feature @@ -194,3 +194,4 @@ Feature: RFC 0586 Aries sign (endorse) transactions functions Examples: | Acme_capabilities | Bob_capabilities | Schema_name | Credential_data | | --endorser-role endorser --revocation --public-did | --endorser-role author --revocation | driverslicense | Data_DL_NormalizedValues | + | --endorser-role endorser --revocation --public-did | --endorser-role author --revocation --multitenant | driverslicense | Data_DL_NormalizedValues |