-
-
Notifications
You must be signed in to change notification settings - Fork 194
Conversation
9f2ed75
to
0c39962
Compare
quick notes:
|
trezorlib/ripple.py
Outdated
|
||
|
||
def validate(transaction): | ||
if False in (k in transaction for k in ("Fee", "Sequence", "TransactionType", "Amount", "Destination")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not all(k in transaction for k in (...)):
also maybe:
if not all(transaction.get(k) for k in (...)):
to check truthiness of the actual values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, so your second option it is
trezorlib/ripple.py
Outdated
if "Flags" in transaction: | ||
msg.flags = transaction["Flags"] | ||
if "LastLedgerSequence" in transaction: | ||
msg.last_ledger_sequence = transaction["LastLedgerSequence"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead:
return messages.RippleSignTx(
fee=transaction["Fee"],
sequence=transaction["Sequence"],
flags=transaction.get("Flags"),
last_ledger_sequence=transaction.get("LastLedgerSequence"),
payment=create_payment(transaction),
)
(perhaps use get()
for the first two as well, for consistency)
the dict.get
method will return None
if key is missing, so you don't need the if
check.
also maybe validate(transaction)
within this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, fixed
trezorlib/ripple.py
Outdated
msg = proto.RipplePayment() | ||
msg.amount = transaction["Amount"] | ||
msg.destination = transaction["Destination"] | ||
return msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd also put the properties in constructor (same as above), if they are just items from the dict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
trezorlib/client.py
Outdated
@expect(proto.RippleSignedTx) | ||
def ripple_sign_tx(self, n, transaction): | ||
ripple.validate(transaction) | ||
n = self._convert_prime(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more _convert_prime
please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should use tools.parse_path(n)
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but not here. the n
should already be the output of parse_path
, that part is correct
trezorlib/ripple.py
Outdated
|
||
import base64 | ||
import struct | ||
import xdrlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't seem to use xdrlib?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
re API: where do you expect to get transaction data? I'm probably going to modify Lisk and NEM (which take dicts) to work similarly. |
Yeah, this is something I've wanted to discuss with you. I guess there are three options how the input data can be provided:
This has one serious disadvantage that when the other transaction types are introduced, we'll have to change this API. So maybe it's not a good idea.
|
Ok, I'll move the methods to ripple.py. How do I register it in the client? Should I do in the client.py something like
or ...? |
e55551b
to
7debbea
Compare
re "register in client" - don't do that at all .) users are expected to |
re API: why not "provide data as protobuf objects"? |
Discussed in person. We'll load the transaction data from a json file and then parse into protobuf. The sign_tx function will accept the protobuf messages |
@matejcik I think this is done from my side. Let me know if I forgot something. |
trezorlib/ripple.py
Outdated
|
||
@field('address') | ||
@expect(messages.RippleAddress) | ||
def ripple_get_address(client, address_n, show_display=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename to get_address
trezorlib/ripple.py
Outdated
|
||
|
||
@expect(messages.RippleSignedTx) | ||
def ripple_sign_tx(client, address_n, msg: messages.RippleSignTx): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename to sign_tx
last thing (function names), otherwise LGTM |
5ec537d
to
8111734
Compare
Good idea. Done. |
and done. |
This introduces support for Ripple, which is coming to trezor-core.
I wasn't sure about the API, so I've done it in the similar way as Stellar's. So the signing command takes a dict as an argument consisting of the fields. I'm not sure it is ideal though, so let me know what you think.