mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-25 16:08:32 +00:00
ripple: code review fixes
This commit is contained in:
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(
|
||||||
def create_sign_tx(transaction) -> proto.RippleSignTx:
|
fee=transaction.get("Fee"),
|
||||||
msg = proto.RippleSignTx()
|
sequence=transaction.get("Sequence"),
|
||||||
msg.fee = transaction["Fee"]
|
flags=transaction.get("Flags"),
|
||||||
msg.sequence = transaction["Sequence"]
|
last_ledger_sequence=transaction.get("LastLedgerSequence"),
|
||||||
if "Flags" in transaction:
|
payment=create_payment(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:
|
def create_payment(transaction) -> messages.RipplePayment:
|
||||||
msg = proto.RipplePayment()
|
return messages.RipplePayment(
|
||||||
msg.amount = transaction["Amount"]
|
amount=transaction.get("Amount"),
|
||||||
msg.destination = transaction["Destination"]
|
destination=transaction.get("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…
Reference in New Issue
Block a user