1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-13 00:40:58 +00:00
trezor-firmware/src/apps/nem/writers.py
2018-06-06 17:24:06 +02:00

47 lines
1.1 KiB
Python

def write_uint32(w, n: int):
w.append(n & 0xFF)
w.append((n >> 8) & 0xFF)
w.append((n >> 16) & 0xFF)
w.append((n >> 24) & 0xFF)
def write_uint64(w, n: int):
w.append(n & 0xFF)
w.append((n >> 8) & 0xFF)
w.append((n >> 16) & 0xFF)
w.append((n >> 24) & 0xFF)
w.append((n >> 32) & 0xFF)
w.append((n >> 40) & 0xFF)
w.append((n >> 48) & 0xFF)
w.append((n >> 56) & 0xFF)
def write_bytes(w, buf: bytearray):
w.extend(buf)
def write_bytes_with_length(w, buf: bytearray):
write_uint32(w, len(buf))
write_bytes(w, buf)
def nem_transaction_write_common(tx_type: int, version: int, timestamp: int, signer: bytes, fee: int, deadline: int)\
-> bytearray:
ret = bytearray()
write_uint32(ret, tx_type)
write_uint32(ret, version)
write_uint32(ret, timestamp)
write_bytes_with_length(ret, bytearray(signer))
write_uint64(ret, fee)
write_uint32(ret, deadline)
return ret
def nem_get_version(network, mosaics=None) -> int:
if mosaics:
return network << 24 | 2
return network << 24 | 1