Skip to content

refactor: drop dead code, dedupe xdrFormat validation and response builders#43

Merged
RaoulSchaffranek merged 2 commits into
mainfrom
refactor/implementation-dedup-dead-code
Jul 23, 2026
Merged

refactor: drop dead code, dedupe xdrFormat validation and response builders#43
RaoulSchaffranek merged 2 commits into
mainfrom
refactor/implementation-dedup-dead-code

Conversation

@RaoulSchaffranek

Copy link
Copy Markdown
Member

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_xdr and sc_address_from_xdr (the XDR SCVal → Komet SCValue path) were referenced only by each other — nothing in the server, encoder, or tests consumed them. Removed both, along with their now-orphaned 16-symbol from komet.scval import (…) block and two TYPE_CHECKING imports.

Unified xdrFormat validation (server.py)
Three near-identical validators (_check_xdr_format, _history_envelope, _get_events_envelope) now defer to a single _unsupported_xdr_format helper. 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 "default base64".

Consolidated ledger reads (server.py)
_latest_ledger() is now the only reader of metadata.json's latest_ledger; four methods that re-inlined the read now call it.

_result_str helper (server.py)
Added alongside _error_str. The four response builders return the JSON string directly instead of a dict that each call site separately json.dumps-ed (removed four inline {'jsonrpc': '2.0', …} literals and five json.dumps(self._…) calls).

Untangled handle_rpc (server.py)
Extracted the ~50-line inline sendTransaction block 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.md no longer advertises the deleted scvalue_from_xdr.

Not done

The fourth xdrFormat copy in ledger_entries.py was left in place — it uses a different error mechanism (InvalidParamsError vs. pre-formatted string) and lives in a module server.py imports 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.

…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.
@RaoulSchaffranek
RaoulSchaffranek merged commit 386f483 into main Jul 23, 2026
1 check passed
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.

1 participant