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