ripple: code review fixes

pull/25/head
Tomas Susanka 6 years ago committed by matejcik
parent 102028587b
commit 77414ad761

@ -1092,10 +1092,8 @@ class ProtocolMixin(object):
@expect(proto.RippleSignedTx) @expect(proto.RippleSignedTx)
def ripple_sign_tx(self, n, transaction): def ripple_sign_tx(self, n, transaction):
ripple.validate(transaction)
n = self._convert_prime(n)
msg = ripple.create_sign_tx(transaction) msg = ripple.create_sign_tx(transaction)
msg.address_n = n msg.address_n = tools.parse_path(n)
return self.call(msg) return self.call(msg)
@field('public_key') @field('public_key')

@ -16,33 +16,27 @@
import base64 import base64
import struct import struct
import xdrlib
from . import messages as proto from . import messages
def validate(transaction): def create_sign_tx(transaction) -> messages.RippleSignTx:
if False in (k in transaction for k in ("Fee", "Sequence", "TransactionType", "Amount", "Destination")): 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") raise ValueError("Some of the required fields missing (Fee, Sequence, TransactionType, Amount, Destination")
if transaction["TransactionType"] != "Payment": if transaction["TransactionType"] != "Payment":
raise ValueError("Only Payment transaction type is supported") 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) def create_payment(transaction) -> messages.RipplePayment:
return msg return messages.RipplePayment(
amount=transaction.get("Amount"),
destination=transaction.get("Destination")
def create_payment(transaction) -> proto.RipplePayment: )
msg = proto.RipplePayment()
msg.amount = transaction["Amount"]
msg.destination = transaction["Destination"]
return msg

@ -19,7 +19,6 @@ import pytest
from .common import TrezorTest from .common import TrezorTest
from .conftest import TREZOR_VERSION from .conftest import TREZOR_VERSION
from binascii import hexlify from binascii import hexlify
from trezorlib import messages as proto
from trezorlib.client import CallException from trezorlib.client import CallException
from trezorlib.tools import parse_path from trezorlib.tools import parse_path

@ -20,7 +20,7 @@ from .common import TrezorTest
from .conftest import TREZOR_VERSION from .conftest import TREZOR_VERSION
from binascii import hexlify from binascii import hexlify
from trezorlib import stellar from trezorlib import stellar
from trezorlib import messages as proto from trezorlib import messages
from trezorlib.client import CallException from trezorlib.client import CallException
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
@ -43,8 +43,8 @@ class TestMsgStellarGetPublicKey(TrezorTest):
self.client.stellar_get_public_key(parse_path('m/0/1')) self.client.stellar_get_public_key(parse_path('m/0/1'))
if TREZOR_VERSION == 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') assert exc.value.args[1].endswith('Failed to derive private key')
else: 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') assert exc.value.args[1].endswith('Firmware error')

Loading…
Cancel
Save