add protobuf example to playground

Use with python-trezor:

./cmdtr.py -t udp get_public_node -n 0
This commit is contained in:
Jan Pochyla 2016-05-19 16:54:58 +02:00 committed by Pavol Rusnak
parent b41c94dee4
commit 53ab1b8a7d
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
1 changed files with 52 additions and 23 deletions

View File

@ -1,9 +1,11 @@
from trezor import loop from trezor import loop
from trezor import ui from trezor import ui
from trezor import msg
from trezor.ui.pin import PinDialog, PIN_CONFIRMED, PIN_CANCELLED from trezor.ui.pin import PinDialog, PIN_CONFIRMED, PIN_CANCELLED
from trezor.utils import unimport_func from trezor.utils import unimport_func
@unimport_func
def layout_tap_to_confirm(address, amount, currency): def layout_tap_to_confirm(address, amount, currency):
# ui.display.bar(0, 0, 240, 40, ui.GREEN) # ui.display.bar(0, 0, 240, 40, ui.GREEN)
@ -26,34 +28,63 @@ def layout_tap_to_confirm(address, amount, currency):
# animation = ui.animate_pulse(func, ui.BLACK, ui.GREY, speed=200000) # animation = ui.animate_pulse(func, ui.BLACK, ui.GREY, speed=200000)
pin_dialog = PinDialog() # pin_dialog = PinDialog()
pin_result = yield from pin_dialog.wait_for_result() # pin_result = yield from pin_dialog.wait_for_result()
if pin_result is PIN_CONFIRMED: # if pin_result is PIN_CONFIRMED:
print('PIN confirmed:', pin_dialog.pin) # print('PIN confirmed:', pin_dialog.pin)
elif pin_result is PIN_CANCELLED: # elif pin_result is PIN_CANCELLED:
print('PIN CANCELLED, go home') # print('PIN CANCELLED, go home')
from trezor.messages.Initialize import Initialize
from trezor.messages.Features import Features
from trezor.messages.GetPublicKey import GetPublicKey
from trezor.messages.PinMatrixRequest import PinMatrixRequest
from trezor.messages.PinMatrixRequestType import Current
from trezor.messages.PinMatrixAck import PinMatrixAck
from trezor.messages.PublicKey import PublicKey
from trezor.messages.HDNodeType import HDNodeType
@unimport_func m = yield from msg.read_msg(Initialize)
def zprava(): print('Initialize')
from uio import BytesIO
from trezor.messages.GetAddress import GetAddress m = Features()
m.revision = 'deadbeef'
m.bootloader_hash = 'deadbeef'
m.device_id = 'DEADBEEF'
m.coins = []
m.imported = False
m.initialized = True
m.label = 'My TREZOR'
m.major_version = 2
m.minor_version = 0
m.patch_version = 0
m.pin_cached = False
m.pin_protection = True
m.passphrase_cached = False
m.passphrase_protection = False
m.vendor = 'bitcointrezor.com'
m = GetAddress() m = yield from msg.call(m, GetPublicKey)
m.address_n = [1, 2, 3] print('GetPublicKey', m.address_n)
m.show_display = True
print(m.__dict__) m = PinMatrixRequest()
f = BytesIO() m.type = Current
m.dump(f)
data = f.getvalue() m = yield from msg.call(m, PinMatrixAck)
f.close() print('PinMatrixAck', m.pin)
print(data)
# m2 = GetAddress.load(BytesIO(data)) m = PublicKey()
# print(m2.__dict__) m.node = HDNodeType()
m.node.depth = 0
m.node.child_num = 0
m.node.fingerprint = 0
m.node.chain_code = 'deadbeef'
m.node.public_key = 'deadbeef'
m = yield from msg.call(m, Initialize)
print('Initialize')
def dispatch(): def dispatch():
@ -65,5 +96,3 @@ def boot():
# Initilize app on boot time. # Initilize app on boot time.
# This should hookup HID message types dispatcher() wants to receive. # This should hookup HID message types dispatcher() wants to receive.
print("Boot playground") print("Boot playground")
zprava()