Skip to content

Commit

Permalink
[Proof editor] fix rich text proof
Browse files Browse the repository at this point in the history
In the serialization, I forgot to encode the number of stakes and the pubkey length. Fix this and add an assertion to avoid regressions.
  • Loading branch information
PiRK committed Aug 24, 2022
1 parent 625c026 commit f26560a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions electroncash_gui/qt/avalanche_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
SignedStake,
Stake,
)
from electroncash.avalanche.serialize import DeserializationError
from electroncash.avalanche.serialize import (
DeserializationError,
serialize_blob,
write_compact_size,
)
from electroncash.bitcoin import is_private_key
from electroncash.constants import PROOF_DUST_THRESHOLD, STAKE_UTXO_CONFIRMATIONS
from electroncash.i18n import _
Expand Down Expand Up @@ -63,6 +67,7 @@ def proof_to_rich_text(proof: Proof) -> str:
"""
p = struct.pack("<Qq", proof.sequence, proof.expiration_time)
p += proof.master_pub.serialize()
p += write_compact_size(len(proof.signed_stakes))
rich_text = colored_text(p.hex(), TextColor.NEUTRAL)

for ss in proof.signed_stakes:
Expand All @@ -72,7 +77,9 @@ def proof_to_rich_text(proof: Proof) -> str:
else:
rich_text += colored_text(ss.sig.hex(), TextColor.BAD_STAKE_SIG)

rich_text += colored_text(proof.payout_script_pubkey.hex(), TextColor.NEUTRAL)
rich_text += colored_text(
serialize_blob(proof.payout_script_pubkey).hex(), TextColor.NEUTRAL
)
if proof.verify_master_signature():
return rich_text + colored_text(proof.signature.hex(), TextColor.GOOD_SIG)
return rich_text + colored_text(proof.signature.hex(), TextColor.BAD_SIG)
Expand Down Expand Up @@ -495,6 +502,9 @@ def on_merge_stakes_clicked(self):

def displayProof(self, proof: Proof):
self.proof_display.setText(proof_to_rich_text(proof))
assert proof.to_hex() == self.proof_display.toPlainText()

# Update status bar below actual proof display
if proof.verify_master_signature():
self.master_sig_status_label.setText(
colored_text("✅ Valid", TextColor.GOOD_SIG)
Expand Down

0 comments on commit f26560a

Please sign in to comment.