diff --git a/python/src/trezorlib/btc.py b/python/src/trezorlib/btc.py index 1dff24880..82765ec1e 100644 --- a/python/src/trezorlib/btc.py +++ b/python/src/trezorlib/btc.py @@ -17,10 +17,10 @@ import warnings from copy import copy from decimal import Decimal -from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, Optional, Sequence, Tuple +from typing import TYPE_CHECKING, Any, AnyStr, List, Optional, Sequence, Tuple # TypedDict is not available in typing for python < 3.8 -from typing_extensions import TypedDict +from typing_extensions import Protocol, TypedDict from . import exceptions, messages from .tools import expect, normalize_nfc, session @@ -65,6 +65,13 @@ if TYPE_CHECKING: vin: List[Vin] vout: List[Vout] + class TxCacheType(Protocol): + def __getitem__(self, __key: bytes) -> messages.TransactionType: + ... + + def __contains__(self, __key: bytes) -> bool: + ... + def from_json(json_dict: "Transaction") -> messages.TransactionType: def make_input(vin: "Vin") -> messages.TxInputType: @@ -242,7 +249,7 @@ def sign_tx( inputs: Sequence[messages.TxInputType], outputs: Sequence[messages.TxOutputType], details: Optional[messages.SignTx] = None, - prev_txes: Optional[Dict[bytes, messages.TransactionType]] = None, + prev_txes: Optional["TxCacheType"] = None, preauthorized: bool = False, **kwargs: Any, ) -> Tuple[Sequence[Optional[bytes]], bytes]: