2021-12-08 09:10:58 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
from trezor import wire
|
|
|
|
|
2019-05-10 14:23:18 +00:00
|
|
|
from apps.common.writers import (
|
2021-01-14 15:15:55 +00:00
|
|
|
write_bytes_fixed,
|
2020-03-16 10:31:11 +00:00
|
|
|
write_bytes_unchecked,
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint8,
|
|
|
|
write_uint16_le,
|
|
|
|
write_uint32_le,
|
|
|
|
write_uint64_le,
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint,
|
2019-05-10 14:23:18 +00:00
|
|
|
)
|
|
|
|
|
2021-12-08 09:10:58 +00:00
|
|
|
if TYPE_CHECKING:
|
2021-03-23 12:35:27 +00:00
|
|
|
from trezor.messages import (
|
|
|
|
EosActionBuyRam,
|
|
|
|
EosActionBuyRamBytes,
|
|
|
|
EosActionCommon,
|
|
|
|
EosActionDelegate,
|
|
|
|
EosActionDeleteAuth,
|
|
|
|
EosActionLinkAuth,
|
2021-12-08 09:10:58 +00:00
|
|
|
EosActionUnlinkAuth,
|
2021-03-23 12:35:27 +00:00
|
|
|
EosActionNewAccount,
|
|
|
|
EosActionRefund,
|
|
|
|
EosActionSellRam,
|
|
|
|
EosActionTransfer,
|
|
|
|
EosActionUndelegate,
|
|
|
|
EosActionUpdateAuth,
|
|
|
|
EosActionVoteProducer,
|
|
|
|
EosAsset,
|
|
|
|
EosAuthorization,
|
|
|
|
EosTxHeader,
|
|
|
|
)
|
2019-07-03 13:07:04 +00:00
|
|
|
from trezor.utils import Writer
|
|
|
|
|
|
|
|
|
|
|
|
def write_auth(w: Writer, auth: EosAuthorization) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint32_le(w, auth.threshold)
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(w, len(auth.keys))
|
2019-05-10 14:23:18 +00:00
|
|
|
for key in auth.keys:
|
2021-12-08 09:10:58 +00:00
|
|
|
if key.key is None:
|
|
|
|
raise wire.DataError("Key must be provided explicitly.")
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(w, key.type)
|
2021-01-14 15:15:55 +00:00
|
|
|
write_bytes_fixed(w, key.key, 33)
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint16_le(w, key.weight)
|
|
|
|
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(w, len(auth.accounts))
|
2019-05-10 14:23:18 +00:00
|
|
|
for account in auth.accounts:
|
|
|
|
write_uint64_le(w, account.account.actor)
|
|
|
|
write_uint64_le(w, account.account.permission)
|
|
|
|
write_uint16_le(w, account.weight)
|
|
|
|
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(w, len(auth.waits))
|
2019-05-10 14:23:18 +00:00
|
|
|
for wait in auth.waits:
|
|
|
|
write_uint32_le(w, wait.wait_sec)
|
|
|
|
write_uint16_le(w, wait.weight)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_header(hasher: Writer, header: EosTxHeader) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint32_le(hasher, header.expiration)
|
|
|
|
write_uint16_le(hasher, header.ref_block_num)
|
|
|
|
write_uint32_le(hasher, header.ref_block_prefix)
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(hasher, header.max_net_usage_words)
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint8(hasher, header.max_cpu_usage_ms)
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(hasher, header.delay_sec)
|
2019-05-10 14:23:18 +00:00
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_transfer(w: Writer, msg: EosActionTransfer) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.sender)
|
|
|
|
write_uint64_le(w, msg.receiver)
|
|
|
|
write_asset(w, msg.quantity)
|
2021-12-08 09:10:58 +00:00
|
|
|
write_bytes_prefixed(w, msg.memo.encode())
|
2019-05-10 14:23:18 +00:00
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_buyram(w: Writer, msg: EosActionBuyRam) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.payer)
|
|
|
|
write_uint64_le(w, msg.receiver)
|
|
|
|
write_asset(w, msg.quantity)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_buyrambytes(w: Writer, msg: EosActionBuyRamBytes) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.payer)
|
|
|
|
write_uint64_le(w, msg.receiver)
|
|
|
|
write_uint32_le(w, msg.bytes)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_sellram(w: Writer, msg: EosActionSellRam) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.account)
|
|
|
|
write_uint64_le(w, msg.bytes)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_delegate(w: Writer, msg: EosActionDelegate) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.sender)
|
|
|
|
write_uint64_le(w, msg.receiver)
|
|
|
|
write_asset(w, msg.net_quantity)
|
|
|
|
write_asset(w, msg.cpu_quantity)
|
|
|
|
write_uint8(w, 1 if msg.transfer else 0)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_undelegate(w: Writer, msg: EosActionUndelegate) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.sender)
|
|
|
|
write_uint64_le(w, msg.receiver)
|
|
|
|
write_asset(w, msg.net_quantity)
|
|
|
|
write_asset(w, msg.cpu_quantity)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_refund(w: Writer, msg: EosActionRefund) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.owner)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_voteproducer(w: Writer, msg: EosActionVoteProducer) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.voter)
|
|
|
|
write_uint64_le(w, msg.proxy)
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(w, len(msg.producers))
|
2019-05-10 14:23:18 +00:00
|
|
|
for producer in msg.producers:
|
|
|
|
write_uint64_le(w, producer)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_updateauth(w: Writer, msg: EosActionUpdateAuth) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.account)
|
|
|
|
write_uint64_le(w, msg.permission)
|
|
|
|
write_uint64_le(w, msg.parent)
|
|
|
|
write_auth(w, msg.auth)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_deleteauth(w: Writer, msg: EosActionDeleteAuth) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.account)
|
|
|
|
write_uint64_le(w, msg.permission)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_linkauth(w: Writer, msg: EosActionLinkAuth) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.account)
|
|
|
|
write_uint64_le(w, msg.code)
|
|
|
|
write_uint64_le(w, msg.type)
|
|
|
|
write_uint64_le(w, msg.requirement)
|
|
|
|
|
|
|
|
|
2021-12-08 09:10:58 +00:00
|
|
|
def write_action_unlinkauth(w: Writer, msg: EosActionUnlinkAuth) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.account)
|
|
|
|
write_uint64_le(w, msg.code)
|
|
|
|
write_uint64_le(w, msg.type)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_newaccount(w: Writer, msg: EosActionNewAccount) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, msg.creator)
|
|
|
|
write_uint64_le(w, msg.name)
|
|
|
|
write_auth(w, msg.owner)
|
|
|
|
write_auth(w, msg.active)
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_action_common(w: Writer, msg: EosActionCommon) -> None:
|
|
|
|
write_uint64_le(w, msg.account)
|
|
|
|
write_uint64_le(w, msg.name)
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(w, len(msg.authorization))
|
2019-05-10 14:23:18 +00:00
|
|
|
for authorization in msg.authorization:
|
2019-07-03 13:07:04 +00:00
|
|
|
write_uint64_le(w, authorization.actor)
|
|
|
|
write_uint64_le(w, authorization.permission)
|
2019-05-10 14:23:18 +00:00
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def write_asset(w: Writer, asset: EosAsset) -> None:
|
2019-05-10 14:23:18 +00:00
|
|
|
write_uint64_le(w, asset.amount)
|
|
|
|
write_uint64_le(w, asset.symbol)
|
|
|
|
|
|
|
|
|
2021-01-14 15:15:55 +00:00
|
|
|
def write_bytes_prefixed(w: Writer, data: bytes) -> None:
|
2021-05-27 11:48:16 +00:00
|
|
|
write_uvarint(w, len(data))
|
2021-01-14 15:15:55 +00:00
|
|
|
write_bytes_unchecked(w, data)
|