Skip to content

Commit

Permalink
minor cleanup and comment additions
Browse files Browse the repository at this point in the history
  • Loading branch information
newtonick committed Dec 9, 2022
1 parent 656ea53 commit bcdc07a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
10 changes: 3 additions & 7 deletions src/seedsigner/hardware/microsd.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
21 changes: 12 additions & 9 deletions src/seedsigner/views/psbt_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"])

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bcdc07a

Please sign in to comment.