Пример #1
0
        def _submit():
            req = tx_pb_v3.SubmitTransactionRequest(
                envelope_xdr=tx_bytes,
                invoice_list=invoice_list.to_proto() if invoice_list else None,
            )
            try:
                resp = self._transaction_stub_v3.SubmitTransaction(
                    req,
                    metadata=self._metadata,
                    timeout=_GRPC_TIMEOUT_SECONDS)
            except grpc.RpcError as e:
                raise BlockchainVersionError() if self._is_migration_error(
                    e) else e

            result = SubmitTransactionResult(tx_id=resp.hash.value)
            if resp.result == tx_pb_v3.SubmitTransactionResponse.Result.REJECTED:
                raise TransactionRejectedError()
            elif resp.result == tx_pb_v3.SubmitTransactionResponse.Result.INVOICE_ERROR:
                result.invoice_errors = resp.invoice_errors
            elif resp.result == tx_pb_v3.SubmitTransactionResponse.Result.FAILED:
                result.tx_error = TransactionErrors.from_result(
                    resp.result_xdr)
            elif resp.result != tx_pb_v3.SubmitTransactionResponse.Result.OK:
                raise Error(f'unexpected result from agora: {resp.result}')

            return result
Пример #2
0
    def test_error_from_result_other_op(self):
        op_result = gen_merge_op_result(xdr_const.ACCOUNT_MERGE_MALFORMED)
        result_xdr = gen_result_xdr(xdr_const.txFAILED, [op_result])

        te = TransactionErrors.from_result(result_xdr)
        assert isinstance(te.tx_error, Error)
        assert isinstance(te.op_errors[0], Error)
Пример #3
0
    def from_proto(cls, item: tx_pb.HistoryItem) -> 'TransactionData':
        data = cls(
            item.hash.value,
            error=TransactionErrors.from_result(item.result_xdr),
        )
        if item.envelope_xdr:
            env = te.TransactionEnvelope.from_xdr(
                base64.b64encode(item.envelope_xdr))
            data.payments = ReadOnlyPayment.payments_from_envelope(
                env, item.invoice_list)

        return data
Пример #4
0
    def test_error_from_result_multi_op(self):
        op_results = [
            gen_create_op_result(xdr_const.CREATE_ACCOUNT_SUCCESS),
            gen_create_op_result(xdr_const.CREATE_ACCOUNT_MALFORMED),
            gen_payment_op_result(xdr_const.PAYMENT_UNDERFUNDED),
        ]

        result_xdr = gen_result_xdr(xdr_const.txFAILED, op_results)

        te = TransactionErrors.from_result(result_xdr)
        assert isinstance(te.tx_error, Error)
        assert not te.op_errors[0]
        assert isinstance(te.op_errors[1], TransactionMalformedError)
        assert isinstance(te.op_errors[2], InsufficientBalanceError)
Пример #5
0
    def test_from_result_tx_failed(self, tx_result_code: int, op_type: int,
                                   op_result_code: int, op_error_type: type):
        """ Tests conversion of error types with transaction results containing only one operation result.
        """
        if op_type == xdr_const.CREATE_ACCOUNT:
            op_result = gen_create_op_result(op_result_code)
        elif op_type == xdr_const.PAYMENT:
            op_result = gen_payment_op_result(op_result_code)
        else:
            raise ValueError('invalid op_type')

        result_xdr = gen_result_xdr(tx_result_code,
                                    [op_result] if op_result else [])

        te = TransactionErrors.from_result(result_xdr)
        assert isinstance(te.tx_error, Error)
        assert isinstance(te.op_errors[0], op_error_type)
Пример #6
0
        def _submit():
            req = tx_pb.SubmitTransactionRequest(
                envelope_xdr=tx_bytes,
                invoice_list=invoice_list.to_proto() if invoice_list else None,
            )
            resp = self.transaction_stub.SubmitTransaction(
                req, timeout=_GRPC_TIMEOUT_SECONDS)

            result = SubmitStellarTransactionResult(tx_hash=resp.hash.value)
            if resp.result == tx_pb.SubmitTransactionResponse.Result.REJECTED:
                raise TransactionRejectedError()
            elif resp.result == tx_pb.SubmitTransactionResponse.Result.INVOICE_ERROR:
                result.invoice_errors = resp.invoice_errors
            elif resp.result == tx_pb.SubmitTransactionResponse.Result.FAILED:
                result.tx_error = TransactionErrors.from_result(
                    resp.result_xdr)
            elif resp.result != tx_pb.SubmitTransactionResponse.Result.OK:
                raise Error("unexpected result from agora: {}".format(
                    resp.result))

            return result
Пример #7
0
 def test_error_from_result_no_op(self, tx_result_code: int,
                                  exception_type: type):
     result_xdr = gen_result_xdr(tx_result_code, [])
     assert isinstance(
         TransactionErrors.from_result(result_xdr).tx_error, exception_type)
Пример #8
0
 def test_from_result_success(self):
     op_result = gen_create_op_result(xdr_const.CREATE_ACCOUNT_SUCCESS)
     result_xdr = gen_result_xdr(xdr_const.txSUCCESS,
                                 [op_result] if op_result else [])
     assert not TransactionErrors.from_result(result_xdr)