mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-22 18:19:03 +00:00
ripple: code review fixes
This commit is contained in:
parent
102028587b
commit
77414ad761
trezorlib
@ -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')
|
||||
|
@ -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")
|
||||
|
||||
|
||||
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
|
||||
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_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")
|
||||
)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user