Skip to content

Commit 386f483

Browse files
Merge pull request #43 from runtimeverification/refactor/implementation-dedup-dead-code
refactor: drop dead code, dedupe xdrFormat validation and response builders
2 parents 15b224e + 37985fa commit 386f483

3 files changed

Lines changed: 118 additions & 223 deletions

File tree

docs/notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
| [`server.py`](server.md)`StellarRpcServer` | Long-running HTTP/JSON-RPC server wrapping the one-shot K interpreter; `handle_rpc` dispatch; owns the io-dir files. Holds no ledger or receipt state. |
1414
| [`transaction.py`](transaction.md)`TransactionEncoder` | XDR → request envelope + (for wasm uploads) kasmer steps; address/contract-id helpers. |
1515
| [`interpreter.py`](interpreter.md)`NodeInterpreter` | Runs request envelopes through `llvm_interpret`; persists `state.kore`. No `kast``kore` whole-config conversions. |
16-
| `scval.py` | XDR `SCVal`Komet `SCValue` (`scvalue_from_xdr`), XDR `SCVal`request/response JSON (`scval_to_json`, `scval_from_json`). |
16+
| `scval.py` | XDR `SCVal` ↔ request/response JSON (`scval_to_json`, `scval_from_json`). |
1717
| `ledger_entries.py` | `getLedgerEntries` XDR translation: base64 `LedgerKey` → key descriptors for the semantics, intermediate entries → base64 `LedgerEntryData`. |
1818
| [`kdist/node.md`](node-semantics.md) | The K RPC layer: reads `request.json`, dispatches, updates `metadata.json` and the per-transaction `receipts/` files, writes `response.json`. |
1919

src/komet_node/scval.py

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,13 @@
22

33
from typing import TYPE_CHECKING
44

5-
from komet.scval import (
6-
SCI32,
7-
SCI64,
8-
SCI128,
9-
SCI256,
10-
SCU32,
11-
SCU64,
12-
SCU128,
13-
SCU256,
14-
AccountId,
15-
ContractId,
16-
SCAddress,
17-
SCBool,
18-
SCBytes,
19-
SCMap,
20-
SCSymbol,
21-
SCVec,
22-
)
235
from stellar_sdk import xdr as stellar_xdr
246
from stellar_sdk.xdr.sc_address_type import SCAddressType
257
from stellar_sdk.xdr.sc_val_type import SCValType
268

279
_UINT64_MASK = (1 << 64) - 1
2810

2911
if TYPE_CHECKING:
30-
from komet.scval import SCValue
31-
from stellar_sdk.xdr.sc_address import SCAddress as XDRSCAddress
3212
from stellar_sdk.xdr.sc_val import SCVal
3313

3414

@@ -176,106 +156,3 @@ def _map_entry(pair: object) -> tuple[dict, dict]:
176156
if isinstance(pair, (list, tuple)) and len(pair) == 2:
177157
return pair[0], pair[1]
178158
raise NotImplementedError(f'Unsupported SCMap entry in JSON encoding: {pair!r}')
179-
180-
181-
def sc_address_from_xdr(xdr: XDRSCAddress) -> SCAddress:
182-
"""Convert an XDR SCAddress to a Komet SCAddress."""
183-
match xdr.type:
184-
case SCAddressType.SC_ADDRESS_TYPE_ACCOUNT:
185-
assert xdr.account_id is not None
186-
# The account_id is a PublicKey XDR — extract the raw 32-byte ed25519 key
187-
assert xdr.account_id.account_id.ed25519 is not None
188-
raw_bytes = xdr.account_id.account_id.ed25519.uint256
189-
return SCAddress(AccountId(raw_bytes))
190-
case SCAddressType.SC_ADDRESS_TYPE_CONTRACT:
191-
assert xdr.contract_id is not None
192-
return SCAddress(ContractId(xdr.contract_id.contract_id.hash))
193-
case _:
194-
raise NotImplementedError(f'Unsupported SCAddress type: {xdr.type}')
195-
196-
197-
def scvalue_from_xdr(xdr: SCVal) -> SCValue:
198-
"""
199-
Convert a Stellar XDR SCVal to a Komet SCValue.
200-
201-
The XDR SCVal is a large union type — each case maps directly to one of
202-
the Komet SCValue dataclasses. Unsupported types (void, error, timepoint,
203-
duration, contract instance, ledger keys) raise NotImplementedError.
204-
"""
205-
match xdr.type:
206-
207-
case SCValType.SCV_BOOL:
208-
assert xdr.b is not None
209-
return SCBool(xdr.b)
210-
211-
case SCValType.SCV_I32:
212-
assert xdr.i32 is not None
213-
return SCI32(xdr.i32.int32)
214-
215-
case SCValType.SCV_I64:
216-
assert xdr.i64 is not None
217-
return SCI64(xdr.i64.int64)
218-
219-
case SCValType.SCV_I128:
220-
assert xdr.i128 is not None
221-
# i128 is stored as (hi: int64, lo: uint64) parts
222-
val = (xdr.i128.hi.int64 << 64) | xdr.i128.lo.uint64
223-
return SCI128(val)
224-
225-
case SCValType.SCV_I256:
226-
assert xdr.i256 is not None
227-
# i256 is stored as (hi_hi, hi_lo, lo_hi, lo_lo) parts
228-
val = (
229-
(xdr.i256.hi_hi.int64 << 192)
230-
| (xdr.i256.hi_lo.uint64 << 128)
231-
| (xdr.i256.lo_hi.uint64 << 64)
232-
| xdr.i256.lo_lo.uint64
233-
)
234-
return SCI256(val)
235-
236-
case SCValType.SCV_U32:
237-
assert xdr.u32 is not None
238-
return SCU32(xdr.u32.uint32)
239-
240-
case SCValType.SCV_U64:
241-
assert xdr.u64 is not None
242-
return SCU64(xdr.u64.uint64)
243-
244-
case SCValType.SCV_U128:
245-
assert xdr.u128 is not None
246-
val = (xdr.u128.hi.uint64 << 64) | xdr.u128.lo.uint64
247-
return SCU128(val)
248-
249-
case SCValType.SCV_U256:
250-
assert xdr.u256 is not None
251-
val = (
252-
(xdr.u256.hi_hi.uint64 << 192)
253-
| (xdr.u256.hi_lo.uint64 << 128)
254-
| (xdr.u256.lo_hi.uint64 << 64)
255-
| xdr.u256.lo_lo.uint64
256-
)
257-
return SCU256(val)
258-
259-
case SCValType.SCV_SYMBOL:
260-
assert xdr.sym is not None
261-
return SCSymbol(xdr.sym.sc_symbol.decode())
262-
263-
case SCValType.SCV_BYTES:
264-
assert xdr.bytes is not None
265-
return SCBytes(xdr.bytes.sc_bytes)
266-
267-
case SCValType.SCV_ADDRESS:
268-
assert xdr.address is not None
269-
return sc_address_from_xdr(xdr.address)
270-
271-
case SCValType.SCV_VEC:
272-
assert xdr.vec is not None
273-
# komet annotates SCVec.val as tuple[SCValue] instead of tuple[SCValue, ...]
274-
return SCVec(tuple(scvalue_from_xdr(v) for v in xdr.vec.sc_vec)) # type: ignore[arg-type]
275-
276-
case SCValType.SCV_MAP:
277-
assert xdr.map is not None
278-
return SCMap({scvalue_from_xdr(entry.key): scvalue_from_xdr(entry.val) for entry in xdr.map.sc_map})
279-
280-
case _:
281-
raise NotImplementedError(f'Unsupported SCVal type: {xdr.type}')

0 commit comments

Comments
 (0)