From bfbc6d5ab9de413cb81316d9dea574bedc1a6f8c Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 3 Aug 2018 18:52:20 +0200 Subject: [PATCH] src: cleanup "utf8" madness --- src/apps/cardano/get_public_key.py | 6 +++--- src/apps/lisk/sign_tx.py | 8 ++++---- src/apps/nem/transfer/layout.py | 4 ++-- src/protobuf.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/apps/cardano/get_public_key.py b/src/apps/cardano/get_public_key.py index 2b7b35a1a..bf1fddcef 100644 --- a/src/apps/cardano/get_public_key.py +++ b/src/apps/cardano/get_public_key.py @@ -39,10 +39,10 @@ async def cardano_get_public_key(ctx, msg): def _get_public_key(root_node, derivation_path: list): _, node = derive_address_and_node(root_node, derivation_path) - public_key = hexlify(seed.remove_ed25519_prefix(node.public_key())).decode("utf8") - chain_code = hexlify(node.chain_code()).decode("utf8") + public_key = hexlify(seed.remove_ed25519_prefix(node.public_key())).decode() + chain_code = hexlify(node.chain_code()).decode() xpub_key = public_key + chain_code - root_hd_passphrase = hexlify(_derive_hd_passphrase(root_node)).decode("utf8") + root_hd_passphrase = hexlify(_derive_hd_passphrase(root_node)).decode() node_type = HDNodeType( depth=node.depth(), diff --git a/src/apps/lisk/sign_tx.py b/src/apps/lisk/sign_tx.py index 4176aac4d..80a3f8196 100644 --- a/src/apps/lisk/sign_tx.py +++ b/src/apps/lisk/sign_tx.py @@ -121,15 +121,15 @@ def _get_asset_data_bytes(msg): if msg.type == LiskTransactionType.Transfer: # Transfer transaction have optional data field if msg.asset.data is not None: - return bytes(msg.asset.data, "utf8") + return msg.asset.data.encode() else: return b"" if msg.type == LiskTransactionType.RegisterDelegate: - return bytes(msg.asset.delegate.username, "utf8") + return msg.asset.delegate.username.encode() if msg.type == LiskTransactionType.CastVotes: - return bytes("".join(msg.asset.votes), "utf8") + return ("".join(msg.asset.votes)).encode() if msg.type == LiskTransactionType.RegisterSecondPassphrase: return msg.asset.signature.public_key @@ -138,7 +138,7 @@ def _get_asset_data_bytes(msg): data = b"" data += ustruct.pack(" 48: payload = payload[:48] + ".." diff --git a/src/protobuf.py b/src/protobuf.py index 92fc118bd..9fd417354 100644 --- a/src/protobuf.py +++ b/src/protobuf.py @@ -191,7 +191,7 @@ async def load_message(reader, msg_type): elif ftype is UnicodeType: fvalue = bytearray(ivalue) await reader.areadinto(fvalue) - fvalue = str(fvalue, "utf8") + fvalue = bytes(fvalue).decode() elif issubclass(ftype, MessageType): fvalue = await load_message(LimitedReader(reader, ivalue), ftype) else: @@ -247,7 +247,7 @@ async def dump_message(writer, msg): await writer.awrite(svalue) elif ftype is UnicodeType: - bvalue = bytes(svalue, "utf8") + bvalue = svalue.encode() await dump_uvarint(writer, len(bvalue)) await writer.awrite(bvalue)