From a36ccd7e6f2711d2ef5b1d4fe162fc4de37e7ed8 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 8 Oct 2020 12:03:29 +0200 Subject: [PATCH] feat!(python): drop Mapping protocol support from MessageType --- python/src/trezorlib/btc.py | 3 ++- python/src/trezorlib/protobuf.py | 12 +----------- tests/bip32.py | 3 ++- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/python/src/trezorlib/btc.py b/python/src/trezorlib/btc.py index 923d02a5b..32401d312 100644 --- a/python/src/trezorlib/btc.py +++ b/python/src/trezorlib/btc.py @@ -15,6 +15,7 @@ # If not, see . import warnings +from copy import copy from decimal import Decimal from typing import TYPE_CHECKING, Any, Dict, Sequence, Tuple @@ -235,7 +236,7 @@ def sign_tx( serialized_tx = b"" def copy_tx_meta(tx: messages.TransactionType) -> messages.TransactionType: - tx_copy = messages.TransactionType(**tx) + tx_copy = copy(tx) # clear fields tx_copy.inputs_cnt = len(tx.inputs) tx_copy.inputs = [] diff --git a/python/src/trezorlib/protobuf.py b/python/src/trezorlib/protobuf.py index 048620ee9..836d991f6 100644 --- a/python/src/trezorlib/protobuf.py +++ b/python/src/trezorlib/protobuf.py @@ -23,6 +23,7 @@ For serializing (dumping) protobuf types, object with `Writer` interface is requ """ import logging +import warnings from io import BytesIO from itertools import zip_longest from typing import ( @@ -30,7 +31,6 @@ from typing import ( Callable, Dict, Iterable, - Iterator, List, Optional, Tuple, @@ -38,7 +38,6 @@ from typing import ( TypeVar, Union, ) -import warnings from typing_extensions import Protocol @@ -280,15 +279,6 @@ class MessageType(metaclass=_MessageTypeMeta): d[key] = value return "<%s: %s>" % (self.__class__.__name__, d) - def __iter__(self) -> Iterator[str]: - return iter(self.keys()) - - def keys(self) -> Iterator[str]: - return (name for name, _, _ in self.get_fields().values()) - - def __getitem__(self, key: str) -> Any: - return getattr(self, key) - def ByteSize(self) -> int: data = BytesIO() dump_message(data, self) diff --git a/tests/bip32.py b/tests/bip32.py index a705a7df8..cfa833c6a 100644 --- a/tests/bip32.py +++ b/tests/bip32.py @@ -17,6 +17,7 @@ import hashlib import hmac import struct +from copy import copy import ecdsa from ecdsa.curves import SECP256k1 @@ -67,7 +68,7 @@ def public_ckd(public_node, n): if not isinstance(n, list): raise ValueError("Parameter must be a list") - node = messages.HDNodeType(**public_node) + node = copy(public_node) for i in n: node = get_subnode(node, i)