feat: implement getLedgerEntries#35
Open
RaoulSchaffranek wants to merge 4 commits into
Open
Conversation
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.
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.
Implements the
getLedgerEntriesRPC 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), andCONTRACT_CODE.What changed:
kdist/node.md: new#ledgerEntriesdispatch rules resolve key descriptors against the world-state cells (<accounts>,<contractCodes>,<contracts>,<contractData>) and answer with intermediate JSON entries pluslatestLedgeras a JSON number.#scVal2JSONserialises stored ScVals back to the#decodeArgJSON 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 base64LedgerKeyparams into key descriptors (validatingkeys, the 200-key cap, andxdrFormat, all-32602on failure;jsonformat politely rejected as unsupported) and re-encoding found entries as base64LedgerEntryData. A re-encode round-trip check rejects keys with trailing garbage, matching Go'sxdr.SafeUnmarshal.server.py/transaction.py: the K configuration stores uploaded wasm parsed, so the raw module bytes are persisted underwasms/<hash>.wasmat upload time and reattached toCONTRACT_CODEentries.scval.py:scval_from_json, the inverse decoder for values coming back out of the semantics.Documented limitations (docs/notes.md):
lastModifiedLedgerSeqis approximated by the current ledger (the semantics track no per-entry modification ledgers),ACCOUNTentries 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 throughstellar_sdk, silent drop of unknown keys, and the parameter validation errors) using a newstorage.watfixture that writes a persistent storage entry viaput_contract_data. Fulltest_server.pypasses (38/38);make check(flake8, mypy, isort, black) clean.