Skip to content

Add typed (non-XDR-encoded) invoke_host_function API for Rust embedders #1657

@tomerweller

Description

@tomerweller

Summary

The current invoke_host_function() API accepts all inputs as XDR-encoded bytes and returns outputs as encoded bytes. This made sense for the C++ stellar-core FFI boundary, but imposes unnecessary overhead on pure-Rust embedders that already have typed XDR objects — they pay for two redundant XDR round-trips per transaction (serialize typed inputs to bytes, then deserialize byte outputs back to typed).

Proposal

Add a parallel invoke_host_function_typed() that accepts and returns native Rust XDR types directly (HostFunction, SorobanResources, AccountId, etc.), along with:

  • A typed result struct (InvokeHostFunctionTypedResult) returning Result<ScVal, HostError>, post-execution Storage, Events, initial TTL/storage state, and restored key information — everything a Rust embedder needs to compute rent and ledger changes without re-encoding.
  • A typed get_ledger_changes_typed() that mirrors the existing get_ledger_changes() but returns Rc<LedgerKey> / Rc<LedgerEntry> instead of encoded byte vectors.
  • Public type aliases (TtlEntryMap, RestoredKeySet) so downstream consumers can work with these types directly.

The existing bytes-based API remains unchanged — this is purely additive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions