You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/src/apps/eos/writers.py

169 lines
4.7 KiB

add EOS support Squashed commit of the following: commit 060563458fbc3b4a17f4d77ba5cd62d0c265c806 Author: matejcik <ja@matejcik.cz> Date: Fri May 10 16:16:19 2019 +0200 skip t1 in eos test commit f759089fef29501467b62bf1540715132a72c4cf Author: matejcik <ja@matejcik.cz> Date: Fri May 10 15:55:20 2019 +0200 make style commit 3ecdd5f77b331d7a6e5a46a10c79d80f214f31bd Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Thu May 9 22:05:41 2019 +0300 Refinements in asset to to string conversion function according to code review and test cases for amounts less than 1 commit 72e44a35bada76abdd94ab866c2113a6d9d85191 Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Wed May 8 00:27:45 2019 +0300 Moved to input_flow rest of the tests, cleanup and styling commit 92f9acbabcbef44a6912b074a309393450f0c8de Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Tue May 7 21:47:12 2019 +0300 Fix for amounts less then 1 commit 8a0154f7432ab78e69a123202a97194d34c2a3cb Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Mon May 6 23:26:24 2019 +0300 removed unnecessary peace of code commit b25c15de3eb1df863760e81ca69f09094349c26e Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Mon May 6 23:16:57 2019 +0300 Fixed validate path parameters commit f0f6e7036a8b88d9c5c6b702a8d851e9a9bd3378 Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Mon May 6 23:04:58 2019 +0300 Fixes commit 0c64d3814300df86d452975b2bd46fea13f512d2 Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Mon May 6 22:19:51 2019 +0300 Fixed styling commit 41d1e77231e7da78fade9b2efa1b7d1980f0d3a8 Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Mon May 6 22:13:58 2019 +0300 Changes to core, added CURVE to path validation commit c045b4554ee8e058dbfe35f715b003d0d85ab1d4 Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Mon May 6 22:07:37 2019 +0300 Changes according to review commit 3f0e6cfd40e7d87dc3287bc3a0b2b9db5dea5377 Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Mon Apr 29 21:37:16 2019 +0300 Added change to make expiration date timezone agnostic commit efdf44c326cc3f3137c447e798db5439b57c91fa Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Thu Apr 18 00:14:30 2019 +0300 changes according to code review commit 3b3723da8f8f536c7c370a14236ea81aac25080a Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Tue Apr 16 23:44:50 2019 +0300 Merged python to monorepo commit da6b0c683c29388e15c889ecea6e7f7471961a19 Author: Andriy Tkachyshyn <atkachyshyn@gmail.com> Date: Tue Apr 16 23:13:42 2019 +0300 Merged core to monorepo
5 years ago
from trezor.messages import (
EosActionBuyRam,
EosActionBuyRamBytes,
EosActionCommon,
EosActionDelegate,
EosActionDeleteAuth,
EosActionLinkAuth,
EosActionNewAccount,
EosActionRefund,
EosActionSellRam,
EosActionTransfer,
EosActionUndelegate,
EosActionUpdateAuth,
EosActionVoteProducer,
EosAsset,
EosAuthorization,
EosTxHeader,
)
from trezor.utils import HashWriter
from apps.common.writers import (
write_bytes,
write_uint8,
write_uint16_le,
write_uint32_le,
write_uint64_le,
)
def write_auth(w: bytearray, auth: EosAuthorization) -> int:
write_uint32_le(w, auth.threshold)
write_variant32(w, len(auth.keys))
for key in auth.keys:
write_variant32(w, key.type)
write_bytes(w, key.key)
write_uint16_le(w, key.weight)
write_variant32(w, len(auth.accounts))
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)
write_variant32(w, len(auth.waits))
for wait in auth.waits:
write_uint32_le(w, wait.wait_sec)
write_uint16_le(w, wait.weight)
def write_header(hasher: HashWriter, header: EosTxHeader):
write_uint32_le(hasher, header.expiration)
write_uint16_le(hasher, header.ref_block_num)
write_uint32_le(hasher, header.ref_block_prefix)
write_variant32(hasher, header.max_net_usage_words)
write_uint8(hasher, header.max_cpu_usage_ms)
write_variant32(hasher, header.delay_sec)
def write_action_transfer(w: bytearray, msg: EosActionTransfer):
write_uint64_le(w, msg.sender)
write_uint64_le(w, msg.receiver)
write_asset(w, msg.quantity)
write_variant32(w, len(msg.memo))
write_bytes(w, msg.memo)
def write_action_buyram(w: bytearray, msg: EosActionBuyRam):
write_uint64_le(w, msg.payer)
write_uint64_le(w, msg.receiver)
write_asset(w, msg.quantity)
def write_action_buyrambytes(w: bytearray, msg: EosActionBuyRamBytes):
write_uint64_le(w, msg.payer)
write_uint64_le(w, msg.receiver)
write_uint32_le(w, msg.bytes)
def write_action_sellram(w: bytearray, msg: EosActionSellRam):
write_uint64_le(w, msg.account)
write_uint64_le(w, msg.bytes)
def write_action_delegate(w: bytearray, msg: EosActionDelegate):
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)
def write_action_undelegate(w: bytearray, msg: EosActionUndelegate):
write_uint64_le(w, msg.sender)
write_uint64_le(w, msg.receiver)
write_asset(w, msg.net_quantity)
write_asset(w, msg.cpu_quantity)
def write_action_refund(w: bytearray, msg: EosActionRefund):
write_uint64_le(w, msg.owner)
def write_action_voteproducer(w: bytearray, msg: EosActionVoteProducer):
write_uint64_le(w, msg.voter)
write_uint64_le(w, msg.proxy)
write_variant32(w, len(msg.producers))
for producer in msg.producers:
write_uint64_le(w, producer)
def write_action_updateauth(w: bytearray, msg: EosActionUpdateAuth):
write_uint64_le(w, msg.account)
write_uint64_le(w, msg.permission)
write_uint64_le(w, msg.parent)
write_auth(w, msg.auth)
def write_action_deleteauth(w: bytearray, msg: EosActionDeleteAuth):
write_uint64_le(w, msg.account)
write_uint64_le(w, msg.permission)
def write_action_linkauth(w: bytearray, msg: EosActionLinkAuth):
write_uint64_le(w, msg.account)
write_uint64_le(w, msg.code)
write_uint64_le(w, msg.type)
write_uint64_le(w, msg.requirement)
def write_action_unlinkauth(w: bytearray, msg: EosActionLinkAuth):
write_uint64_le(w, msg.account)
write_uint64_le(w, msg.code)
write_uint64_le(w, msg.type)
def write_action_newaccount(w: bytearray, msg: EosActionNewAccount):
write_uint64_le(w, msg.creator)
write_uint64_le(w, msg.name)
write_auth(w, msg.owner)
write_auth(w, msg.active)
def write_action_common(hasher: HashWriter, msg: EosActionCommon):
write_uint64_le(hasher, msg.account)
write_uint64_le(hasher, msg.name)
write_variant32(hasher, len(msg.authorization))
for authorization in msg.authorization:
write_uint64_le(hasher, authorization.actor)
write_uint64_le(hasher, authorization.permission)
def write_asset(w: bytearray, asset: EosAsset) -> int:
write_uint64_le(w, asset.amount)
write_uint64_le(w, asset.symbol)
def write_variant32(w: bytearray, value: int) -> int:
variant = bytearray()
while True:
b = value & 0x7F
value >>= 7
b |= (value > 0) << 7
variant.append(b)
if value == 0:
break
write_bytes(w, bytes(variant))