Skip to content

feat: implement getLedgerEntries#35

Open
RaoulSchaffranek wants to merge 4 commits into
mainfrom
feat/get-ledger-entries
Open

feat: implement getLedgerEntries#35
RaoulSchaffranek wants to merge 4 commits into
mainfrom
feat/get-ledger-entries

Conversation

@RaoulSchaffranek

@RaoulSchaffranek RaoulSchaffranek commented Jul 3, 2026

Copy link
Copy Markdown
Member

Implements the getLedgerEntries RPC method per the Stellar RPC spec, covering the entry types the K world state tracks: ACCOUNT, CONTRACT_DATA (contract-instance entries and persistent/temporary storage), and CONTRACT_CODE.

What changed:

  • kdist/node.md: new #ledgerEntries dispatch rules resolve key descriptors against the world-state cells (<accounts>, <contractCodes>, <contracts>, <contractData>) and answer with intermediate JSON entries plus latestLedger as a JSON number. #scVal2JSON serialises stored ScVals back to the #decodeArg JSON shape, extended with the value-only types (void, string, u256, vec, map). Keys that resolve to nothing are skipped, not errors, per the spec.
  • ledger_entries.py (new): the two steps K cannot do — decoding the base64 LedgerKey params into key descriptors (validating keys, the 200-key cap, and xdrFormat, all -32602 on failure; json format politely rejected as unsupported) and re-encoding found entries as base64 LedgerEntryData. A re-encode round-trip check rejects keys with trailing garbage, matching Go's xdr.SafeUnmarshal.
  • server.py / transaction.py: the K configuration stores uploaded wasm parsed, so the raw module bytes are persisted under wasms/<hash>.wasm at upload time and reattached to CONTRACT_CODE entries.
  • scval.py: scval_from_json, the inverse decoder for values coming back out of the semantics.

Documented limitations (docs/notes.md): lastModifiedLedgerSeq is approximated by the current ledger (the semantics track no per-entry modification ledgers), ACCOUNT entries synthesise the required fields beyond the balance, and untracked key types (trustlines, offers, TTL, ...) are reported as not found.

Testing: 12 new integration tests pin the spec serialization (result keys, numeric ledger fields, optional liveUntilLedgerSeq, base64 key/xdr round-trips through stellar_sdk, silent drop of unknown keys, and the parameter validation errors) using a new storage.wat fixture that writes a persistent storage entry via put_contract_data. Full test_server.py passes (38/38); make check (flake8, mypy, isort, black) clean.

Cover the official spec surface: ACCOUNT, CONTRACT_CODE, and CONTRACT_DATA
(instance and persistent storage) lookups, base64 key/xdr round-trips,
numeric latestLedger/lastModifiedLedgerSeq, silent drop of unknown keys,
the 200-key cap, key and xdrFormat validation errors, and rejection of the
unsupported json xdrFormat. Adds a storage.wat fixture whose store()
function writes a persistent contract-data entry via put_contract_data.
Dispatch and state lookup live in the K semantics: new #ledgerEntries rules
resolve key descriptors against the world-state cells (accounts, contracts,
contractData, contractCodes) and answer with intermediate JSON entries plus
the numeric latestLedger. #scVal2JSON serialises stored ScVals back to the
JSON shape #decodeArg consumes, extended with the value-only types (void,
string, u256, vec, map).

Python handles only the XDR ends (ledger_entries.py): decoding the base64
LedgerKey params into key descriptors — with validation of keys, the 200-key
cap, and xdrFormat (base64 only) — and re-encoding found entries as base64
LedgerEntryData. Unknown or untracked keys are skipped, not errors, per the
spec. Because the K configuration stores uploaded wasm parsed, the server now
persists the raw module bytes under wasms/<hash>.wasm at upload time and
reattaches them to CONTRACT_CODE entries.

lastModifiedLedgerSeq is approximated by the current ledger (the semantics
do not track per-entry modification ledgers) and ACCOUNT entries synthesise
the AccountEntry fields the semantics do not model beyond the balance.
@RaoulSchaffranek RaoulSchaffranek changed the title Implement getLedgerEntries feat: implement getLedgerEntries Jul 3, 2026
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