refactor: drop dead code, dedupe xdrFormat validation and response builders#43
Merged
Merged
Conversation
…e builders Post-merge cleanup of the implementation (test suite was already deduped). - scval.py: remove scvalue_from_xdr / sc_address_from_xdr (the XDR -> Komet SCValue path had no consumer) and their now-orphaned komet.scval imports. - server.py: unify the three divergent xdrFormat validators behind one _unsupported_xdr_format helper, fixing their disagreement on empty/null/absent. - server.py: make _latest_ledger the sole reader of metadata.json's latest_ledger. - server.py: add _result_str alongside _error_str; response builders now return the JSON string directly instead of a dict re-serialised at each call site. - server.py: extract the inline sendTransaction block into _handle_send_transaction so handle_rpc is a uniform dispatcher. - docs: drop the reference to the deleted scvalue_from_xdr. No behaviour change; all 90 tests pass.
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.
Post-merge cleanup of the implementation. The test suite was deduped in #42; this does the same for the implementation. No behaviour change — all 90 tests pass, and flake8/mypy/autoflake/black are clean.
What changed
Dead code (
scval.py, −123 lines)scvalue_from_xdrandsc_address_from_xdr(the XDRSCVal→ KometSCValuepath) were referenced only by each other — nothing in the server, encoder, or tests consumed them. Removed both, along with their now-orphaned 16-symbolfrom komet.scval import (…)block and twoTYPE_CHECKINGimports.Unified
xdrFormatvalidation (server.py)Three near-identical validators (
_check_xdr_format,_history_envelope,_get_events_envelope) now defer to a single_unsupported_xdr_formathelper. This also removes their disagreement on edge cases: empty string /null/ absent were previously rejected by one method and accepted by another; they now uniformly mean "defaultbase64".Consolidated ledger reads (
server.py)_latest_ledger()is now the only reader ofmetadata.json'slatest_ledger; four methods that re-inlined the read now call it._result_strhelper (server.py)Added alongside
_error_str. The four response builders return the JSON string directly instead of a dict that each call site separatelyjson.dumps-ed (removed four inline{'jsonrpc': '2.0', …}literals and fivejson.dumps(self._…)calls).Untangled
handle_rpc(server.py)Extracted the ~50-line inline
sendTransactionblock into_handle_send_transaction, so the dispatcher is a uniform sequence of one-line delegations matching its siblings (_handle_simulate,_get_ledger_entries).Docs
docs/notes.mdno longer advertises the deletedscvalue_from_xdr.Not done
The fourth
xdrFormatcopy inledger_entries.pywas left in place — it uses a different error mechanism (InvalidParamsErrorvs. pre-formatted string) and lives in a moduleserver.pyimports from, so sharing the helper would require a third module to avoid a circular import. Left out as not worth the coupling; easy to revisit.