Skip to content

Commit

Permalink
Merge pull request #354 from Foundation-Devices/SFT-2235-qr-code-fail…
Browse files Browse the repository at this point in the history
…s-to-display-multisig

SFT-2235: qr code fails to display multisig
  • Loading branch information
mjg-foundation committed Jul 13, 2023
2 parents e9626ad + 49acd96 commit 33c49a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def check_inputs(self):

if (not self.data and not self.write_fn) or (self.data and self.write_fn):
await ErrorPage("Either data or a write function is required to save a file.").show()
self.set_result(False)
self.set_result(None)
return

self.goto(self.save)
Expand Down Expand Up @@ -89,7 +89,7 @@ async def save(self):
await ErrorPage(text='Failed to write file: {}'.format(e),
right_micron=self.show_check) \
.show(auto_close_timeout=self.auto_timeout)
self.set_result(False)
self.set_result(None)
return

if written:
Expand All @@ -104,4 +104,4 @@ async def success(self):
await SuccessPage(text='Saved {} as {}'.format(self.success_text, self.out_full),
right_micron=self.show_check) \
.show(auto_close_timeout=self.auto_timeout)
self.set_result(True)
self.set_result(self.out_full)
63 changes: 18 additions & 45 deletions ports/stm32/boards/Passport/modules/flows/sign_psbt_qr_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def __init__(self):
self.psbt = None
self.txid = None
self.is_comp = None
self.out_fn = None
self.out2_fn = None
self.written = False
self.signed_bytes = None
self.max_frames = 35
self.filename = None

async def scan_transaction(self):
from foundation import ur
Expand Down Expand Up @@ -108,6 +109,7 @@ async def common_flow(self):
self.goto(self.get_signed_bytes)

async def get_signed_bytes(self):
import gc
from foundation import FixedBytesIO
from pages import ErrorPage
from passport import mem
Expand All @@ -127,6 +129,9 @@ async def get_signed_bytes(self):
self.set_result(False)
return

self.is_comp = self.psbt.is_complete()
self.psbt = None
gc.collect()
self.goto(self.show_signed_transaction)

async def show_signed_transaction(self):
Expand Down Expand Up @@ -159,64 +164,38 @@ async def show_signed_transaction(self):

self.set_result(True)

def write_final_fn(self, filename):
from utils import HexWriter

# write psbt to file as hex
with HexWriter(open(filename, 'w+t')) as fd:
self.txid = self.psbt.finalize(fd)
self.out2_fn = filename

def write_psbt_fn(self, filename):
# Attempt to write-out the transaction
with self.output_encoder(open(filename, 'wb')) as fd:
# save as updated PSBT
self.psbt.serialize(fd)
self.out_fn = filename

async def save_to_microsd(self):
from flows import SaveToMicroSDFlow
from pages import ErrorPage
from utils import get_folder_path
from public_constants import DIR_TRANSACTIONS
from ubinascii import hexlify as b2a_hex

# Check that the psbt has been written, and the transaction has been written if complete
if self.out_fn and (self.is_comp == bool(self.out2_fn)):
# Check that the psbt has been written
if self.written:
self.goto(self.show_success)
return

self.written = True
base = 'QR'

self.is_comp = self.psbt.is_complete()
if not self.is_comp:
# Keep the filename under control during multiple passes
target_fname = base + '-part.psbt'
else:
# Add -signed to end. We won't offer to sign again.
target_fname = base + '-signed.psbt'

result_1 = await SaveToMicroSDFlow(filename=target_fname,
write_fn=self.write_psbt_fn,
success_text="psbt",
path=get_folder_path(DIR_TRANSACTIONS),
automatic=False,
auto_prompt=True).run()
if not result_1:
self.filename = await SaveToMicroSDFlow(filename=target_fname,
data=b2a_hex(self.signed_bytes),
success_text="psbt",
path=get_folder_path(DIR_TRANSACTIONS),
automatic=False,
auto_prompt=True).run()
if self.filename is None:
self.back()
return

if self.is_comp:
target2_fname = base + '-final.txn'
result_2 = await SaveToMicroSDFlow(filename=target2_fname,
write_fn=self.write_final_fn,
success_text="transaction",
path=get_folder_path(DIR_TRANSACTIONS),
automatic=False,
auto_prompt=True).run()
if not result_2:
self.back()
return

self.goto(self.show_success)

async def show_success(self):
Expand All @@ -225,13 +204,7 @@ async def show_success(self):
from styles.colors import DEFAULT_LARGE_ICON_COLOR
from pages import LongTextPage

msg = "Updated PSBT is:\n\n%s" % self.out_fn
if self.out2_fn:
msg += '\n\nFinalized transaction (ready for broadcast):\n\n%s' % self.out2_fn

if self.txid:
msg += '\n\nFinal TXID:\n' + self.txid

msg = "Updated PSBT is:\n\n%s" % self.filename
result = await LongTextPage(text=msg,
centered=True,
left_micron=microns.ScanQR,
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/boards/Passport/modules/pages/show_qr_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self,

self.prev_card_descs = None
self.prev_card_idx = common.ui.active_card_idx
self.prev_top_level = False
self.qr_size_idx = common.settings.get('last_qr_size_idx', 0)
self.qr_card_descs = [
{'page_micron': microns.PageQRSmall},
Expand Down

0 comments on commit 33c49a6

Please sign in to comment.