Skip to main content

Module rust_client

Module rust_client 

Source
Expand description

Rust client generator.

Produces a self-contained off-chain Rust client from a ProgramManifest. Consumers are integration tests, CLI tools, other on-chain programs that CPI into this one, and server-side services that build transactions.

The generator’s output uses the canonical solana-sdk shape (Pubkey, Instruction, AccountMeta) so it drops into any existing Rust program or test harness without a custom runtime.

Closes the “winning architecture” design’s Category 5 item (“generate TS + Rust clients”) and is the Rust counterpart to TsClientGen and KtClientGen.

§Shape

Every generated client file has four sections:

  • Constants: LAYOUT_ID hex bytes per account layout, per-field offsets + sizes, instruction discriminators.
  • Accounts: a typed struct per layout plus a decode_{name}(&[u8]) -> Result<{Name}> that reads fields out of raw bytes at their declared offsets, preceded by assert_{name}_layout(&[u8]) which compares the header’s LAYOUT_ID against the embedded constant.
  • Instructions: create_{ix}_ix(accounts, args) -> Instruction builders with the discriminator byte + LE-encoded args.
  • Events: decode_{event}_data(&[u8]) -> Result<{Event}>.

Client-side layout verification is mandatory. the audit’s closing directive is that clients must refuse to decode accounts whose headers disagree with the compiled ABI. The generated assert_{name}_layout is the enforcement point.

Structs§

RsClientGen
Full Rust client emitter.