[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