From bcdc07a54d520d0ac8ca94586cb0989ab08c6ade Mon Sep 17 00:00:00 2001 From: Nick Klockenga Date: Fri, 9 Dec 2022 11:13:33 -0500 Subject: [PATCH] minor cleanup and comment additions --- src/seedsigner/hardware/microsd.py | 10 +++------- src/seedsigner/views/psbt_views.py | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/seedsigner/hardware/microsd.py b/src/seedsigner/hardware/microsd.py index 4f5982ba..fc373a27 100644 --- a/src/seedsigner/hardware/microsd.py +++ b/src/seedsigner/hardware/microsd.py @@ -1,5 +1,5 @@ import time -import base64, binascii, os, glob +import base64, os, glob from seedsigner.models.singleton import Singleton from seedsigner.models.threads import BaseThread @@ -94,10 +94,6 @@ def find_psbt_files(self): "filepath": filepath, "type": "base64" }) - + + # sort the list by name of file without extension self.psbt_files = sorted(self.psbt_files, key=lambda d: d['name']) - - if len(self.psbt_files) > 0: - print("PSBT Files Found:") - for psbt in self.psbt_files: - print('{filename}:{type}'.format(**psbt)) diff --git a/src/seedsigner/views/psbt_views.py b/src/seedsigner/views/psbt_views.py index a4de058e..28c3da97 100644 --- a/src/seedsigner/views/psbt_views.py +++ b/src/seedsigner/views/psbt_views.py @@ -1,5 +1,6 @@ import logging, os from typing import List +from binascii import a2b_base64 from embit.psbt import PSBT from embit import script @@ -22,14 +23,17 @@ class PSBTFileSelectionView(View): def run(self): + + # edge case when file selection menu is selected, but no psbt files are available, re-route to home menu if len(self.controller.microsd.psbt_files) == 0: return Destination(MainMenuView) + # add button to button list for each psbt file button_data = [] for psbt_file in self.controller.microsd.psbt_files: - if len(psbt_file["filename"]) > 18: - button_data.append(psbt_file["filename"][:13] + "..." + psbt_file["filename"][-7:]) + if len(psbt_file["filename"]) > 21: + button_data.append(psbt_file["filename"][:12] + "..." + psbt_file["filename"][-7:]) else: button_data.append(psbt_file["filename"]) @@ -43,11 +47,8 @@ def run(self): return Destination(BackStackView) # Read PSBT file select if it exists - from embit import psbt - from binascii import a2b_base64 - psbt_file = self.controller.microsd.psbt_files[selected_menu_num] - tx = psbt.PSBT + tx = PSBT.PSBT if os.path.exists(psbt_file["filepath"]): with open(psbt_file["filepath"], 'rb') as f: @@ -522,7 +523,7 @@ def run(self): psbt.sign_with(psbt_parser.root) trimmed_psbt = psbt - if self.controller.psbt_file == None: # skip trim when using files on microsd + if self.controller.psbt_file == None: # skip trim when using psbt files from microsd trimmed_psbt = PSBTParser.trim(psbt) if sig_cnt == PSBTParser.sig_count(trimmed_psbt): @@ -533,6 +534,7 @@ def run(self): else: self.controller.psbt = trimmed_psbt + # when psbt file is used from microsd, write signed psbt to microsd if self.controller.psbt_file == None: return Destination(PSBTSignedQRDisplayView) else: @@ -563,14 +565,15 @@ def run(self): class PSBTSignedFileDisplayView(View): def run(self): - # extract psbt (embit) bytes to write to file + # extract psbt from memory to write to file. The file name of a signed PSBT is appended with "signed" to the original file name. + # So "Test 123.psbt" unsigned PSBT will be written to the microsd card as "Test 123 signed.psbt". raw = self.controller.psbt.serialize() filename, extension = os.path.splitext(self.controller.psbt_file["filename"]) signed_filename = filename + " signed" + extension signed_filepath = MicroSD.MOUNT_LOCATION + signed_filename increment = 0 - # if file already exists, add increment to file name (to avoid writing over existing psbt) + # if signed filename already exists on disk, add incremented number to the end of the file name while os.path.exists(signed_filepath): increment += 1 signed_filename = filename + " signed" + str(increment) + extension