Skip to content

Commit c193d00

Browse files
Proper usb response (#267)
support bool from process_host_command
1 parent 20ff492 commit c193d00

File tree

11 files changed

+32
-26
lines changed

11 files changed

+32
-26
lines changed

src/apps/backup.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
bip39: <recovery phrase>
44
"""
55
from app import BaseApp, AppError
6-
from io import BytesIO
7-
from binascii import hexlify
8-
from rng import get_random_bytes
96
from embit import bip39
107
from gui.screens import Prompt
118
from gui.components.mnemonic import MnemonicTable
@@ -30,6 +27,7 @@ async def process_host_command(self, stream, show_fn):
3027
table = MnemonicTable(scr)
3128
table.align(scr.message, lv.ALIGN.OUT_BOTTOM_MID, 0, 30)
3229
table.set_mnemonic(mnemonic)
33-
if await show_fn(scr):
30+
confirm = await show_fn(scr)
31+
if confirm:
3432
self.keystore.set_mnemonic(mnemonic)
35-
return None
33+
return confirm

src/apps/blindingkeys/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def process_host_command(self, stream, show_screen):
4545
"Send master blinding private key\nto the host?\n\n"
4646
"Host is requesting your\nSLIP-77 blinding key.\n\n"
4747
"It will be able to watch your funds and unblind transactions.")):
48-
return
48+
return False
4949
return BytesIO(self.keystore.slip77_key.wif(NETWORKS[self.network])), {}
5050
raise AppError("Unknown command")
5151

src/apps/signmessage/signmessage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def process_host_command(self, stream, show_screen):
7272
)
7373
res = await show_screen(scr)
7474
if res is False:
75-
return None
75+
return False
7676
sig = self.sign_message(derivation_path, message)
7777
# for GUI we can also return an object with helpful data
7878
pub = self.keystore.get_xpub(derivation_path).get_public_key()

src/apps/wallets/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from .manager import WalletManager
44
from .liquid.manager import LWalletManager
55
from helpers import is_liquid
6-
import gc
76

87
class WalletsApp(BaseApp):
98
# This is a dummy app that can switch between Bitcoin and Liquid wallet managers

src/apps/wallets/liquid/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async def process_host_command(self, stream, show_screen):
136136
asset = bytes(reversed(unhexlify(hexasset)))
137137
self.assets[asset] = assetlbl
138138
self.save_assets()
139-
return BytesIO(b"success"), {}
139+
return True
140140
elif cmd == DUMP_ASSETS:
141141
return BytesIO(self.assets_json()), {}
142142
else:

src/apps/wallets/manager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async def process_host_command(self, stream, show_screen):
208208
"message": "Scan it with your wallet",
209209
}
210210
return res, obj
211-
return
211+
return False
212212
if cmd == SIGN_BCUR:
213213
# move to the end of UR:BYTES/
214214
stream.seek(9, 1)
@@ -231,18 +231,18 @@ async def process_host_command(self, stream, show_screen):
231231
"message": "Scan it with your wallet",
232232
}
233233
return res, obj
234-
return
234+
return False
235235
elif cmd == LIST_WALLETS:
236236
wnames = json.dumps([w.name for w in self.wallets])
237237
return BytesIO(wnames.encode()), {}
238238
elif cmd == ADD_WALLET:
239239
# read content, it's small
240240
desc = stream.read().decode().strip()
241241
w = self.parse_wallet(desc)
242-
res = await self.confirm_new_wallet(w, show_screen)
243-
if res:
242+
confirm = await self.confirm_new_wallet(w, show_screen)
243+
if confirm:
244244
self.add_wallet(w)
245-
return
245+
return bool(confirm)
246246
elif cmd == VERIFY_ADDRESS:
247247
data = stream.read().decode().replace("bitcoin:", "")
248248
# should be of the form addr?index=N or similar
@@ -257,7 +257,7 @@ async def process_host_command(self, stream, show_screen):
257257
break
258258
w, _ = self.find_wallet_from_address(addr, index=idx)
259259
await show_screen(WalletScreen(w, self.network, idx))
260-
return
260+
return True
261261
elif cmd == DERIVE_ADDRESS:
262262
arr = stream.read().split(b" ")
263263
redeem_script = None

src/hosts/qr.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import time
44
import asyncio
55
from platform import simulator, config, delete_recursively
6-
from io import BytesIO
76
import gc
87
from gui.screens.settings import HostSettings
98
from gui.screens import Alert

src/hosts/sd.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from .core import Host, HostError
22
from platform import fpath
3-
from io import BytesIO
43
import os
54
import platform
6-
from binascii import b2a_base64, a2b_base64, hexlify
5+
from binascii import hexlify
76
from helpers import a2b_base64_stream
87

98
class SDHost(Host):
@@ -70,7 +69,13 @@ def truncate(self, fname):
7069
return fname[:18]+"..."+fname[-12:]
7170

7271
async def select_file(self, extensions):
73-
files = sum([[f[0] for f in os.ilistdir(self.sdpath) if f[0].lower().endswith(ext) and f[1] == 0x8000] for ext in extensions], [])
72+
files = sum([
73+
[
74+
f[0] for f in os.ilistdir(self.sdpath)
75+
if f[0].lower().endswith(ext)
76+
and f[1] == 0x8000
77+
] for ext in extensions
78+
], [])
7479

7580
if len(files) == 0:
7681
raise HostError("\n\nNo matching files found on the SD card\nAllowed: %s" % ", ".join(extensions))
@@ -81,7 +86,11 @@ async def select_file(self, extensions):
8186
buttons = []
8287
for ext in extensions:
8388
title = [(None, ext+" files")]
84-
barr = [(self.sdpath+"/"+f, self.truncate(f)) for f in files if f.lower().endswith(ext)]
89+
barr = [
90+
(self.sdpath+"/"+f, self.truncate(f))
91+
for f in files
92+
if f.lower().endswith(ext)
93+
]
8594
if len(barr) == 0:
8695
buttons += [(None, "%s files - No files" % ext)]
8796
else:

src/hosts/usb.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from io import BytesIO
21
from errors import BaseError
32
from .core import Host, HostError
43
import sys
@@ -65,7 +64,7 @@ def cleanup(self):
6564
platform.delete_recursively(self.path)
6665

6766
async def process_command(self, stream):
68-
if self.manager == None:
67+
if self.manager is None:
6968
raise HostError("Device is busy")
7069
# all commands are pretty short
7170
b = stream.read(20)
@@ -76,8 +75,10 @@ async def process_command(self, stream):
7675
stream.seek(0)
7776
# res should be a stream as well
7877
res = await self.manager.process_host_request(stream)
79-
if res is None:
78+
if res is None or res is False:
8079
self.respond(b"error: User cancelled")
80+
elif res is True:
81+
self.respond(b"success")
8182
else:
8283
stream, meta = res
8384
# if it's str - it's a filename
@@ -148,7 +149,7 @@ def read_to_file(self):
148149
return self.path + "/data"
149150

150151
async def update(self):
151-
if self.manager == None:
152+
if self.manager is None:
152153
return await asyncio.sleep_ms(100)
153154
if self.usb is None:
154155
return await asyncio.sleep_ms(100)

src/specter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ async def mainmenu(self):
324324
if stream is not None:
325325
# check against all apps
326326
res = await self.process_host_request(stream, popup=False)
327-
if res is not None:
327+
if res not in [True, False, None]:
328328
await host.send_data(*res)
329329
else:
330330
print(menuitem)

0 commit comments

Comments
 (0)