diff --git a/sovtoken/sovtoken/request_handlers/write_request_handler/xfer_handler.py b/sovtoken/sovtoken/request_handlers/write_request_handler/xfer_handler.py index 853e3c21..e4f3e21c 100644 --- a/sovtoken/sovtoken/request_handlers/write_request_handler/xfer_handler.py +++ b/sovtoken/sovtoken/request_handlers/write_request_handler/xfer_handler.py @@ -2,15 +2,16 @@ from sovtoken.exceptions import UTXOError from indy_common.authorize.auth_actions import AuthActionAdd -from sovtoken.constants import INPUTS, OUTPUTS, XFER_PUBLIC, TOKEN_LEDGER_ID, UTXO_CACHE_LABEL +from sovtoken.constants import INPUTS, OUTPUTS, XFER_PUBLIC, TOKEN_LEDGER_ID, UTXO_CACHE_LABEL, SIGS from sovtoken.messages.txn_validator import txn_xfer_public_validate from sovtoken.request_handlers.token_utils import spend_input, add_new_output, sum_inputs, sum_outputs, \ validate_given_inputs_outputs from sovtoken.types import Output +from plenum.common.constants import ED25519 from plenum.common.exceptions import InvalidClientMessageException, InvalidClientRequest, OperationError from plenum.common.request import Request -from plenum.common.txn_util import get_payload_data, get_seq_no +from plenum.common.txn_util import get_payload_data, get_seq_no, add_sigs_to_txn from plenum.server.database_manager import DatabaseManager from plenum.server.request_handlers.handler_interfaces.write_request_handler import WriteRequestHandler @@ -63,6 +64,14 @@ def update_state(self, txn, prev_result, request, is_committed=False): error = 'Exception {} while updating state'.format(ex) raise OperationError(error) + def _req_to_txn(self, req: Request): + sigs = req.operation.pop(SIGS) + txn = super()._req_to_txn(req) + req.operation[SIGS] = sigs + sigs = [(i["address"], s) for i, s in zip(req.operation[INPUTS], sigs)] + add_sigs_to_txn(txn, sigs, sig_type=ED25519) + return txn + def _do_validate_inputs_ouputs(self, request): try: sum_in = sum_inputs(self.utxo_cache, diff --git a/sovtoken/sovtoken/test/test_public_xfer_1.py b/sovtoken/sovtoken/test/test_public_xfer_1.py index fc0887a8..0bf54bc5 100644 --- a/sovtoken/sovtoken/test/test_public_xfer_1.py +++ b/sovtoken/sovtoken/test/test_public_xfer_1.py @@ -3,7 +3,7 @@ from plenum.common.txn_util import get_seq_no from plenum.common.exceptions import RequestNackedException from plenum.common.types import OPERATION -from sovtoken.constants import SIGS, ADDRESS, SEQNO, AMOUNT, OUTPUTS, PAYMENT_ADDRESS +from sovtoken.constants import SIGS, ADDRESS, SEQNO, AMOUNT, OUTPUTS, PAYMENT_ADDRESS, INPUTS from sovtoken.test.helper import user1_token_wallet @@ -287,3 +287,30 @@ def test_multiple_inputs_outputs_with_change( assert address5_utxos[1][PAYMENT_ADDRESS] == address5 assert address5_utxos[0][AMOUNT] == 100 assert address5_utxos[1][AMOUNT] == 10 + + +def test_xfer_signatures_included_in_txn( + helpers, + addresses, + initial_mint +): + [address1, address2, address3, address4, address5] = addresses + + inputs = helpers.general.get_utxo_addresses([address1, address2, address3]) + inputs = [utxo for utxos in inputs for utxo in utxos] + + outputs = [ + {"address": address4, "amount": 200}, + {"address": address5, "amount": 100}, + ] + + request = helpers.request.transfer(inputs, outputs) + response = helpers.sdk.send_and_check_request_objects([request]) + + sigs = [(i["address"], s) for i, s in zip(request.operation[INPUTS], request.operation[SIGS])] + request = response[0][0] + sigs.append((request["identifier"], request["signature"])) + + rep_sigs = [(v['from'], v['value']) for v in response[0][1]["result"]["reqSignature"]["values"]] + + assert sorted(rep_sigs) == sorted(sigs)