Skip to content

refactor(encoding): replace standalone functions with Reader/Writer classes#67

Merged
themantre merged 5 commits into
mainfrom
refactor/reader-writer-encoding
Jul 3, 2026
Merged

refactor(encoding): replace standalone functions with Reader/Writer classes#67
themantre merged 5 commits into
mainfrom
refactor/reader-writer-encoding

Conversation

@b00f

@b00f b00f commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replace standalone encode_*/decode_* functions with Reader/Writer classes, plus fixes and test improvements on top.

Main refactor (8a3e442)

  • 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

Fixes & improvements (ca0d636)

  • address: Simplify is_account_address() to not is_validator_address()
  • encoding: Raise ValueError on negative varint values in write_var_int()
  • amount: Add to_string() method, __str__ delegates to it
  • tests: Add comprehensive test_address.py (encode/decode round-trip, treasury, invalid cases)
  • tests: Refactor test_amount.py with centralized test cases and explicit expected bytes

b00f added 5 commits July 3, 2026 00:00
…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
@b00f b00f requested a review from themantre July 3, 2026 05:55
@themantre themantre merged commit 8f7b893 into main Jul 3, 2026
3 checks passed
@themantre themantre deleted the refactor/reader-writer-encoding branch July 3, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants