refactor(encoding): replace standalone functions with Reader/Writer classes#67
Merged
Conversation
…lasses - Introduce Writer class with write_uint8/write_uint16/write_uint32/write_var_int/write_str/write_fixed_bytes methods - Introduce Reader class with read_uint8/read_uint16/read_uint32/read_var_int/read_str/read_fixed_bytes methods - Rename append_* to write_* for symmetry with read_* - Update all domain types (Block, Header, Certificate, Transaction, Hash, Address, Amount, etc.) to accept Writer/Reader instead of raw io types - Update ABCs (Signature, PublicKey, Payload) encode/decode signatures - Update all tests and examples - Remove dead TYPE_CHECKING/io imports
- Simplify is_account_address() to not is_validator_address() - Raise ValueError on negative varint in Writer.write_var_int() - Add Amount.to_string() method, make __str__ delegate to it - Add comprehensive test_address.py test suite (encode/decode round-trip, treasury) - Refactor test_amount.py with centralized test cases and explicit expected bytes
themantre
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace standalone
encode_*/decode_*functions withReader/Writerclasses, plus fixes and test improvements on top.Main refactor (8a3e442)
Writerclass withwrite_uint8/write_uint16/write_uint32/write_var_int/write_str/write_fixed_bytesmethodsReaderclass withread_uint8/read_uint16/read_uint32/read_var_int/read_str/read_fixed_bytesmethodsappend_*towrite_*for symmetry withread_*Block,Header,Certificate,Transaction,Hash,Address,Amount, etc.) to acceptWriter/Readerinstead of rawiotypesSignature,PublicKey,Payload) encode/decode signaturesTYPE_CHECKING/ioimportsFixes & improvements (ca0d636)
is_account_address()tonot is_validator_address()ValueErroron negative varint values inwrite_var_int()to_string()method,__str__delegates to ittest_address.py(encode/decode round-trip, treasury, invalid cases)test_amount.pywith centralized test cases and explicit expected bytes