Skip to content

Commit

Permalink
use compressed psbt to reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
stepansnigirev committed Apr 8, 2021
1 parent 26d5702 commit 3f0c21c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/apps/wallets/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,17 @@ async def sign_psbt(self, stream, show_screen, encoding=BASE64_STREAM):
# read in chunks, write to ram file
a2b_base64_stream(stream, f)
with open(self.tempdir+"/raw", "rb") as f:
psbt = PSBT.read_from(f)
psbt = PSBT.read_from(f, compress=True)
# cleanup
platform.delete_recursively(self.tempdir)
else:
psbt = PSBT.read_from(stream)
psbt = PSBT.read_from(stream, compress=True)
# check if all utxos are there and if there are custom sighashes
sighash = SIGHASH.ALL
custom_sighashes = []
for i, inp in enumerate(psbt.inputs):
if inp.witness_utxo is None:
if inp.non_witness_utxo is None:
raise WalletError("Invalid PSBT - missing previous transaction")
if (not inp.is_verified) and inp.witness_utxo is None and inp.non_witness_utxo is None:
raise WalletError("Invalid PSBT - missing previous transaction")
if inp.sighash_type and inp.sighash_type != SIGHASH.ALL:
custom_sighashes.append((i, inp.sighash_type))

Expand Down Expand Up @@ -539,14 +538,15 @@ def parse_psbt(self, psbt):
for i, inp in enumerate(psbt.inputs):
found = False
utxo = psbt.utxo(i)
meta["inputs"][i] = {
"label": "Unknown wallet",
"value": utxo.value,
"sighash": SIGHASH_NAMES[inp.sighash_type or SIGHASH.ALL]
}
for w in self.wallets:
if w.owns(psbt.utxo(i), inp.bip32_derivations, inp.witness_script or inp.redeem_script):
branch_idx, idx = w.get_derivation(inp.bip32_derivations)
meta["inputs"][i] = {
"label": w.name,
"value": utxo.value,
"sighash": SIGHASH_NAMES[inp.sighash_type or SIGHASH.ALL]
}
meta["inputs"][i]["label"] = w.name
if branch_idx == 1:
meta["inputs"][i]["label"] += " change %d" % idx
elif branch_idx == 0:
Expand Down
2 changes: 1 addition & 1 deletion src/gui/screens/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, title, meta):

obj = self.message # for alignments

enable_inputs = len([k for k in meta["inputs"] if k["sighash"] != "ALL"]) > 0
enable_inputs = len([k for k in meta["inputs"] if k.get("sighash", "ALL") != "ALL"]) > 0

lbl = add_label("Show detailed information ", scr=self)
lbl.align(obj, lv.ALIGN.CENTER, 0, 0)
Expand Down

0 comments on commit 3f0c21c

Please sign in to comment.