mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-19 12:58:13 +00:00
refactor(python/stellar): avoid warning when constructing StellarSignTx
[no changelog], covered in Stellar refactor changelog entries
This commit is contained in:
parent
91e8413c7e
commit
399ee51be6
@ -32,6 +32,7 @@ try:
|
|||||||
IdMemo,
|
IdMemo,
|
||||||
ManageData,
|
ManageData,
|
||||||
ManageSellOffer,
|
ManageSellOffer,
|
||||||
|
NoneMemo,
|
||||||
Operation,
|
Operation,
|
||||||
PathPaymentStrictReceive,
|
PathPaymentStrictReceive,
|
||||||
Payment,
|
Payment,
|
||||||
@ -53,7 +54,6 @@ except ImportError:
|
|||||||
DEFAULT_NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015"
|
DEFAULT_NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015"
|
||||||
|
|
||||||
DEFAULT_BIP32_PATH = "m/44h/148h/0h"
|
DEFAULT_BIP32_PATH = "m/44h/148h/0h"
|
||||||
# Stellar's BIP32 differs to Bitcoin's see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md
|
|
||||||
|
|
||||||
|
|
||||||
def from_envelope(envelope: "TransactionEnvelope"):
|
def from_envelope(envelope: "TransactionEnvelope"):
|
||||||
@ -63,35 +63,47 @@ def from_envelope(envelope: "TransactionEnvelope"):
|
|||||||
"""
|
"""
|
||||||
if not HAVE_STELLAR_SDK:
|
if not HAVE_STELLAR_SDK:
|
||||||
raise RuntimeError("Stellar SDK not available")
|
raise RuntimeError("Stellar SDK not available")
|
||||||
tx = messages.StellarSignTx()
|
|
||||||
parsed_tx = envelope.transaction
|
parsed_tx = envelope.transaction
|
||||||
tx.source_account = parsed_tx.source.account_id
|
if parsed_tx.time_bounds is None:
|
||||||
tx.fee = parsed_tx.fee
|
raise ValueError("Timebounds are mandatory")
|
||||||
tx.sequence_number = parsed_tx.sequence
|
|
||||||
|
|
||||||
# Timebounds is an optional field
|
memo_type = messages.StellarMemoType.NONE
|
||||||
if parsed_tx.time_bounds:
|
memo_text = None
|
||||||
tx.timebounds_start = parsed_tx.time_bounds.min_time
|
memo_id = None
|
||||||
tx.timebounds_end = parsed_tx.time_bounds.max_time
|
memo_hash = None
|
||||||
|
if isinstance(parsed_tx.memo, NoneMemo):
|
||||||
memo = parsed_tx.memo
|
pass
|
||||||
if isinstance(memo, TextMemo):
|
elif isinstance(parsed_tx.memo, TextMemo):
|
||||||
# memo_text is specified as UTF-8 string, but returned as bytes from the XDR parser
|
# memo_text is specified as UTF-8 string, but returned as bytes from the XDR parser
|
||||||
tx.memo_type = messages.StellarMemoType.TEXT
|
memo_type = messages.StellarMemoType.TEXT
|
||||||
tx.memo_text = memo.memo_text.decode("utf-8")
|
memo_text = parsed_tx.memo.memo_text.decode("utf-8")
|
||||||
elif isinstance(memo, IdMemo):
|
elif isinstance(parsed_tx.memo, IdMemo):
|
||||||
tx.memo_type = messages.StellarMemoType.ID
|
memo_type = messages.StellarMemoType.ID
|
||||||
tx.memo_id = memo.memo_id
|
memo_id = parsed_tx.memo.memo_id
|
||||||
elif isinstance(memo, HashMemo):
|
elif isinstance(parsed_tx.memo, HashMemo):
|
||||||
tx.memo_type = messages.StellarMemoType.HASH
|
memo_type = messages.StellarMemoType.HASH
|
||||||
tx.memo_hash = memo.memo_hash
|
memo_hash = parsed_tx.memo.memo_hash
|
||||||
elif isinstance(memo, ReturnHashMemo):
|
elif isinstance(parsed_tx.memo, ReturnHashMemo):
|
||||||
tx.memo_type = messages.StellarMemoType.RETURN
|
memo_type = messages.StellarMemoType.RETURN
|
||||||
tx.memo_hash = memo.memo_return
|
memo_hash = parsed_tx.memo.memo_return
|
||||||
else:
|
else:
|
||||||
tx.memo_type = messages.StellarMemoType.NONE
|
raise ValueError("Unsupported memo type")
|
||||||
|
|
||||||
|
tx = messages.StellarSignTx(
|
||||||
|
source_account=parsed_tx.source.account_id,
|
||||||
|
fee=parsed_tx.fee,
|
||||||
|
sequence_number=parsed_tx.sequence,
|
||||||
|
timebounds_start=parsed_tx.time_bounds.min_time,
|
||||||
|
timebounds_end=parsed_tx.time_bounds.max_time,
|
||||||
|
memo_type=memo_type,
|
||||||
|
memo_text=memo_text,
|
||||||
|
memo_id=memo_id,
|
||||||
|
memo_hash=memo_hash,
|
||||||
|
num_operations=len(parsed_tx.operations),
|
||||||
|
network_passphrase=envelope.network_passphrase,
|
||||||
|
)
|
||||||
|
|
||||||
tx.num_operations = len(parsed_tx.operations)
|
|
||||||
operations = [_read_operation(op) for op in parsed_tx.operations]
|
operations = [_read_operation(op) for op in parsed_tx.operations]
|
||||||
return tx, operations
|
return tx, operations
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user