Expand description
State Receipts – structured mutation summaries.
A StateReceipt captures a complete record of what happened during
an instruction’s execution: which fields changed, what the before/after
fingerprints were, which invariants ran, which capabilities were active,
and how many CPI calls or journal appends occurred.
§Use Cases
- Audit trails: Emit receipts as events for off-chain indexing
- Test assertions: Verify exact mutation footprint in tests
- Post-mutation validation: Feed receipt to invariant checks
- Debugging: Log receipts during development
- CLI inspection: Decode receipt bytes with
hopper receipt
§Usage
ⓘ
// Before mutation
let mut receipt = StateReceipt::<8>::begin(
&layout_id,
account_data,
);
// ... mutations happen ...
// After mutation
receipt.commit(account_data);
receipt.set_invariants(true, 3);
receipt.set_policy_flags(DEPOSIT_CAPS.bits());
receipt.set_cpi_count(1);
receipt.set_journal_appends(2);
// Emit as event
emit_slices(&[&receipt.to_bytes()]);Structs§
- Decoded
Receipt - Decoded receipt from wire bytes. Useful for CLI and off-chain tooling.
- Receipt
Explain - Human-readable explanation of a decoded receipt.
- Receipt
Narrative - An auto-generated human-readable narrative describing a mutation.
- State
Receipt - A structured record of a state mutation.
Enums§
- Compat
Impact - Compatibility impact level encoded in a receipt.
- Failure
Stage - Stage of instruction execution at which a failure was recorded.
- Narrative
Risk - Risk level for a receipt narrative.
- Phase
- Instruction execution phase encoded in a receipt.
Constants§
- FAILED_
INVARIANT_ NONE - Sentinel value for
failed_invariant_idxmeaning “no invariant was associated with the failure”. - MAX_
RECEIPT_ FIELDS - Maximum fields tracked in a receipt’s changed-field bitmask.
- RECEIPT_
SIZE - Receipt summary size in bytes.
- RECEIPT_
SIZE_ LEGACY - Legacy receipt size, kept as a named constant for readers that want to quickly check if they received the shorter pre-0.2 receipt and ignore the failure-payload suffix.