mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-27 01:48:17 +00:00
Slightly refactored mixin structure, added debugging output
This commit is contained in:
parent
9b8462f71e
commit
a117057dea
@ -32,5 +32,4 @@ class TrezorTest(unittest.TestCase):
|
|||||||
print "--------------"
|
print "--------------"
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.debug_transport.close()
|
self.client.close()
|
||||||
self.transport.close()
|
|
||||||
|
@ -14,6 +14,10 @@ def get_buttonrequest_value(code):
|
|||||||
# Converts integer code to its string representation of ButtonRequestType
|
# Converts integer code to its string representation of ButtonRequestType
|
||||||
return [ k for k, v in types.ButtonRequestType.items() if v == code][0]
|
return [ k for k, v in types.ButtonRequestType.items() if v == code][0]
|
||||||
|
|
||||||
|
def pprint(msg):
|
||||||
|
ser = msg.SerializeToString()
|
||||||
|
return "<%s> (%d bytes):\n%s" % (msg.__class__.__name__, len(ser), msg)
|
||||||
|
|
||||||
class CallException(Exception):
|
class CallException(Exception):
|
||||||
def __init__(self, code, message):
|
def __init__(self, code, message):
|
||||||
super(CallException, self).__init__()
|
super(CallException, self).__init__()
|
||||||
@ -54,9 +58,9 @@ class expect(object):
|
|||||||
class BaseClient(object):
|
class BaseClient(object):
|
||||||
# Implements very basic layer of sending raw protobuf
|
# Implements very basic layer of sending raw protobuf
|
||||||
# messages to device and getting its response back.
|
# messages to device and getting its response back.
|
||||||
def __init__(self, transport, *args, **kwargs):
|
def __init__(self, transport, **kwargs):
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
super(BaseClient, self).__init__(*args, **kwargs)
|
super(BaseClient, self).__init__() # *args, **kwargs)
|
||||||
|
|
||||||
def call(self, msg):
|
def call(self, msg):
|
||||||
try:
|
try:
|
||||||
@ -97,6 +101,9 @@ class TextUIMixin(object):
|
|||||||
# by implementing your own GuiMixin with
|
# by implementing your own GuiMixin with
|
||||||
# graphical widgets for every type of these callbacks.
|
# graphical widgets for every type of these callbacks.
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(TextUIMixin, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def callback_ButtonRequest(self, msg):
|
def callback_ButtonRequest(self, msg):
|
||||||
print "Sending ButtonAck for %s " % get_buttonrequest_value(msg.code)
|
print "Sending ButtonAck for %s " % get_buttonrequest_value(msg.code)
|
||||||
return proto.ButtonAck()
|
return proto.ButtonAck()
|
||||||
@ -149,6 +156,12 @@ class DebugLinkMixin(object):
|
|||||||
self.button = button # True -> YES button, False -> NO button
|
self.button = button # True -> YES button, False -> NO button
|
||||||
self.pin_correct = pin_correct
|
self.pin_correct = pin_correct
|
||||||
|
|
||||||
|
def call(self, msg):
|
||||||
|
print "SENDING", pprint(msg)
|
||||||
|
ret = super(DebugLinkMixin, self).call(msg)
|
||||||
|
print "RECEIVED", pprint(ret)
|
||||||
|
return ret
|
||||||
|
|
||||||
def callback_ButtonRequest(self, msg):
|
def callback_ButtonRequest(self, msg):
|
||||||
if self.expected_buttonrequests != None:
|
if self.expected_buttonrequests != None:
|
||||||
try:
|
try:
|
||||||
@ -177,16 +190,16 @@ class DebugLinkMixin(object):
|
|||||||
return proto.PinMatrixAck(pin=pin)
|
return proto.PinMatrixAck(pin=pin)
|
||||||
|
|
||||||
def callback_PassphraseRequest(self, msg):
|
def callback_PassphraseRequest(self, msg):
|
||||||
pass
|
raise Exception("Not implemented yet")
|
||||||
|
|
||||||
def callback_WordRequest(self, msg):
|
def callback_WordRequest(self, msg):
|
||||||
pass
|
raise Exception("Not implemented yet")
|
||||||
|
|
||||||
class ProtocolMixin(object):
|
class ProtocolMixin(object):
|
||||||
PRIME_DERIVATION_FLAG = 0x80000000
|
PRIME_DERIVATION_FLAG = 0x80000000
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(ProtocolMixin, self).__init__() # *args, **kwargs)
|
super(ProtocolMixin, self).__init__(*args, **kwargs)
|
||||||
self.init_device()
|
self.init_device()
|
||||||
|
|
||||||
def get_tx_func_placeholder(txhash):
|
def get_tx_func_placeholder(txhash):
|
||||||
@ -453,10 +466,10 @@ class ProtocolMixin(object):
|
|||||||
|
|
||||||
raise Exception("Unexpected result " % resp)
|
raise Exception("Unexpected result " % resp)
|
||||||
|
|
||||||
class TrezorClient(BaseClient, ProtocolMixin, TextUIMixin):
|
class TrezorClient(ProtocolMixin, TextUIMixin, BaseClient):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class TrezorDebugClient(BaseClient, ProtocolMixin, DebugLinkMixin):
|
class TrezorDebugClient(ProtocolMixin, DebugLinkMixin, BaseClient):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -478,6 +491,8 @@ class TrezorClient(object):
|
|||||||
resp = self.transport.read_blocking()
|
resp = self.transport.read_blocking()
|
||||||
|
|
||||||
if isinstance(resp, proto.ButtonRequest):
|
if isinstance(resp, proto.ButtonRequest):
|
||||||
|
_pprint(self, msg):
|
||||||
|
ser = msg.SerializeToString()
|
||||||
if expected_buttonrequests != None:
|
if expected_buttonrequests != None:
|
||||||
try:
|
try:
|
||||||
exp = expected_buttonrequests.pop(0)
|
exp = expected_buttonrequests.pop(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user