1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-13 18:18:08 +00:00
trezor-firmware/core/src/apps/stellar/writers.py
2019-10-01 15:12:37 +02:00

37 lines
908 B
Python

from .helpers import public_key_from_address
from apps.common.writers import write_bytes, write_uint32_be, write_uint64_be
write_uint32 = write_uint32_be
write_uint64 = write_uint64_be
if False:
from typing import AnyStr
def write_string(w, s: AnyStr) -> None:
"""Write XDR string padded to a multiple of 4 bytes."""
if isinstance(s, str):
buf = s.encode()
else:
buf = s
write_uint32(w, len(buf))
write_bytes(w, buf)
# if len isn't a multiple of 4, add padding bytes
reminder = len(buf) % 4
if reminder:
write_bytes(w, bytes([0] * (4 - reminder)))
def write_bool(w, val: bool):
if val:
write_uint32(w, 1)
else:
write_uint32(w, 0)
def write_pubkey(w, address: str):
# first 4 bytes of an address are the type, there's only one type (0)
write_uint32(w, 0)
write_bytes(w, public_key_from_address(address))