diff --git a/trezorlib/client.py b/trezorlib/client.py index a7e5cd7a6..e11f09a67 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -1092,10 +1092,8 @@ class ProtocolMixin(object): @expect(proto.RippleSignedTx) def ripple_sign_tx(self, n, transaction): - ripple.validate(transaction) - n = self._convert_prime(n) msg = ripple.create_sign_tx(transaction) - msg.address_n = n + msg.address_n = tools.parse_path(n) return self.call(msg) @field('public_key') diff --git a/trezorlib/ripple.py b/trezorlib/ripple.py index 998ad7175..908b117a2 100644 --- a/trezorlib/ripple.py +++ b/trezorlib/ripple.py @@ -16,33 +16,27 @@ import base64 import struct -import xdrlib -from . import messages as proto +from . import messages -def validate(transaction): - if False in (k in transaction for k in ("Fee", "Sequence", "TransactionType", "Amount", "Destination")): +def create_sign_tx(transaction) -> messages.RippleSignTx: + if not all(transaction.get(k) for k in ("Fee", "Sequence", "TransactionType", "Amount", "Destination")): raise ValueError("Some of the required fields missing (Fee, Sequence, TransactionType, Amount, Destination") if transaction["TransactionType"] != "Payment": raise ValueError("Only Payment transaction type is supported") + return messages.RippleSignTx( + fee=transaction.get("Fee"), + sequence=transaction.get("Sequence"), + flags=transaction.get("Flags"), + last_ledger_sequence=transaction.get("LastLedgerSequence"), + payment=create_payment(transaction), + ) -def create_sign_tx(transaction) -> proto.RippleSignTx: - msg = proto.RippleSignTx() - msg.fee = transaction["Fee"] - msg.sequence = transaction["Sequence"] - if "Flags" in transaction: - msg.flags = transaction["Flags"] - if "LastLedgerSequence" in transaction: - msg.last_ledger_sequence = transaction["LastLedgerSequence"] - msg.payment = create_payment(transaction) - return msg - - -def create_payment(transaction) -> proto.RipplePayment: - msg = proto.RipplePayment() - msg.amount = transaction["Amount"] - msg.destination = transaction["Destination"] - return msg +def create_payment(transaction) -> messages.RipplePayment: + return messages.RipplePayment( + amount=transaction.get("Amount"), + destination=transaction.get("Destination") + ) diff --git a/trezorlib/tests/device_tests/test_msg_ripple_get_address.py b/trezorlib/tests/device_tests/test_msg_ripple_get_address.py index bed741ebc..3c2d2a4a7 100644 --- a/trezorlib/tests/device_tests/test_msg_ripple_get_address.py +++ b/trezorlib/tests/device_tests/test_msg_ripple_get_address.py @@ -19,7 +19,6 @@ import pytest from .common import TrezorTest from .conftest import TREZOR_VERSION from binascii import hexlify -from trezorlib import messages as proto from trezorlib.client import CallException from trezorlib.tools import parse_path diff --git a/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py b/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py index 4a531b59e..1442d9795 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py @@ -20,7 +20,7 @@ from .common import TrezorTest from .conftest import TREZOR_VERSION from binascii import hexlify from trezorlib import stellar -from trezorlib import messages as proto +from trezorlib import messages from trezorlib.client import CallException from trezorlib.tools import parse_path @@ -43,8 +43,8 @@ class TestMsgStellarGetPublicKey(TrezorTest): self.client.stellar_get_public_key(parse_path('m/0/1')) if TREZOR_VERSION == 1: - assert exc.value.args[0] == proto.FailureType.ProcessError + assert exc.value.args[0] == messages.FailureType.ProcessError assert exc.value.args[1].endswith('Failed to derive private key') else: - assert exc.value.args[0] == proto.FailureType.FirmwareError + assert exc.value.args[0] == messages.FailureType.FirmwareError assert exc.value.args[1].endswith('Firmware error')