Capsule-local adapter dispatch¶
Every capsule carries a generated dispatch module. It is the entry point for every call into the block: it takes a method number and the call's arguments, checks them against the interface, and calls your method. It lives inside the capsule, so a call is checked by the block's own sealed code, with no routing table outside it.
The capsule's executable surface index points each method at it:
"charge": {"export_ordinal": 7, "adapter_entrypoint": "capsule.acme.billing.ledger_adapter_dispatch:dispatch"}
How a call reaches your method¶
At run time the Rust kernel consumes only the sealed compiled interface. It rebuilds its own interface model from it and verifies the hash, and works from that model; the XCI source and the generated code stay build inputs.
flowchart TB
X["XCI source"] --> C["Compiled interface<br/>sealed in the package"]
C -->|"build time"| G["Dispatch module<br/>generated from it"]
C -->|"run time"| K["Rust kernel<br/>consumes only the sealed compiled interface,<br/>rebuilds its interface model, verifies the hash"]
K --> M["Cell monitor"]
M --> P["Rust CPython provider<br/>runs Python in the cell"]
P -->|"CPython C API"| D["Dispatch module"]
D --> U["Your method<br/>Ledger.charge"]
What it does with a call¶
The ledger block's dispatch module, as the pipeline generates it:
def dispatch(target: object, method_ordinal: int, arguments: Mapping[int, object]) -> object:
if method_ordinal == 7:
expected = frozenset((1, 2,))
if frozenset(arguments) != expected:
raise InterfaceDispatchRefusal(f"argument ids do not match method {method_ordinal}")
operation = getattr(target, 'charge', None)
if operation is None or not callable(operation):
raise InterfaceDispatchRefusal(f"guest target does not implement method {method_ordinal}")
return operation(request=arguments[1], receipt=arguments[2])
elif method_ordinal == 9:
...
raise InterfaceDispatchRefusal(f"method ordinal {method_ordinal} is not declared by this interface")
For each call it:
- matches the method number against the interface's methods;
- checks that the arguments are exactly the method's parameter numbers;
- finds the method on your class;
- calls it with the arguments under their parameter names.
A call that fails a step is refused with the reason, and your code is not entered. The numbers and names come from the interface, so the dispatch module always matches the interface it was generated from; bake confirms it byte for byte.
Related: Export ordinals and Interface conformance.