HomePhabricator

[electrum] consolidate compact_size code

Description

[electrum] consolidate compact_size code

Summary:
As of D14509, var_int and write_compact_size are doing exactly the same thing. BCDataStream.write_compact_size is also almost doing the same thing. De-triplicate this code.

Use serialize_blob as a shortcut when serializing a push of bytes. Use serialize_sequence as a shortcut when serializing a list of objects that have a serialize method returning bytes. Note that it cannot be done for txinputs because of the extra sign_schnorr argument.

Consolidate also the tests, add tests for the two functions mentioned above, and move compact_size_nbytes to serialize.py

Test Plan:
python test_runner.py

grep -r var_int .

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D14525

Details

Provenance
PiRKAuthored on Sep 22 2023, 14:15
PiRKPushed on Sep 25 2023, 12:16
Reviewer
Restricted Project
Differential Revision
D14525: [electrum] consolidate compact_size code
Parents
rABC692e0c46d453: [electrum] fix error dialogs in main_window
Branches
Unknown
Tags
Unknown