# Path: keepkeylib/client.py
# class expect(object):
#     # Decorator checks if the method
#     # returned one of expected protobuf messages
#     # or raises an exception
#     def __init__(self, *expected):
#         self.expected = expected
# 
#     def __call__(self, f):
#         def wrapped_f(*args, **kwargs):
#             ret = f(*args, **kwargs)
#             if not isinstance(ret, self.expected):
#                 raise Exception("Got %s, expected %s" % (ret.__class__, self.expected))
#             return ret
#         return wrapped_f
# 
# def session(f):
#     # Decorator wraps a BaseClient method
#     # with session activation / deactivation
#     def wrapped_f(*args, **kwargs):
#         client = args[0]
#         try:
#             client.transport.session_begin()
#             return f(*args, **kwargs)
#         finally:
#             client.transport.session_end()
#     return wrapped_f
# 
# class field(object):
#     # Decorator extracts single value from
#     # protobuf object. If the field is not
#     # present, raises an exception.
#     def __init__(self, field):
#         self.field = field
# 
#     def __call__(self, f):
#         def wrapped_f(*args, **kwargs):
#             ret = f(*args, **kwargs)
#             ret.HasField(self.field)
#             return getattr(ret, self.field)
#         return wrapped_f


from . import messages_binance_pb2 as messages
from .client import expect, session, field
@field("address")
def get_address(client, address_n, show_display=False):
    return client.call(
        messages.BinanceGetAddress(address_n=address_n, show_display=show_display)
    )


@expect(messages.BinancePublicKey)
@field("public_key")
def get_public_key(client, address_n, show_display=False):
    return client.call(
        messages.BinanceGetPublicKey(address_n=address_n, show_display=show_display)
    )


@session
def sign_tx(client, address_n, tx_json):
    msg = tx_json["msgs"][0]
    envelope = messages.BinanceSignTx(
        account_number=int(tx_json['account_number']),
        chain_id=tx_json['chain_id'],
        sequence=int(tx_json['sequence']),
        source=int(tx_json['source']),
        memo=tx_json['memo'],
        msg_count=1,
        address_n=address_n,
    )

    response = client.call(envelope)


# Path: keepkeylib/client.py
# class expect(object):
#     # Decorator checks if the method
#     # returned one of expected protobuf messages
#     # or raises an exception
#     def __init__(self, *expected):
#         self.expected = expected
# 
#     def __call__(self, f):
#         def wrapped_f(*args, **kwargs):
#             ret = f(*args, **kwargs)
#             if not isinstance(ret, self.expected):
#                 raise Exception("Got %s, expected %s" % (ret.__class__, self.expected))
#             return ret
#         return wrapped_f
# 
# def session(f):
#     # Decorator wraps a BaseClient method
#     # with session activation / deactivation
#     def wrapped_f(*args, **kwargs):
#         client = args[0]
#         try:
#             client.transport.session_begin()
#             return f(*args, **kwargs)
#         finally:
#             client.transport.session_end()
#     return wrapped_f
# 
# class field(object):
#     # Decorator extracts single value from
#     # protobuf object. If the field is not
#     # present, raises an exception.
#     def __init__(self, field):
#         self.field = field
# 
#     def __call__(self, f):
#         def wrapped_f(*args, **kwargs):
#             ret = f(*args, **kwargs)
#             ret.HasField(self.field)
#             return getattr(ret, self.field)
#         return wrapped_f


# Path: keepkeylib/binance.py
from . import messages_binance_pb2 as messages
from .client import expect, session, field

@field("address")
def get_address(client, address_n, show_display=False):
    return client.call(
        messages.BinanceGetAddress(address_n=address_n, show_display=show_display)
    )


@expect(messages.BinancePublicKey)
@field("public_key")
def get_public_key(client, address_n, show_display=False):
    return client.call(
        messages.BinanceGetPublicKey(address_n=address_n, show_display=show_display)
    )


@session
def sign_tx(client, address_n, tx_json):
    msg = tx_json["msgs"][0]
    envelope = messages.BinanceSignTx(
        account_number=int(tx_json['account_number']),
        chain_id=tx_json['chain_id'],
        sequence=int(tx_json['sequence']),
        source=int(tx_json['source']),
        memo=tx_json['memo'],
        msg_count=1,
        address_n=address_n,
    )

    response = client.call(envelope)


    if not isinstance(response, messages.BinanceTxRequest):