Skip to content

Rust refactor: derive Serialize/Deserialize on PendingStamp; drop hand-rolled JSON #332

Description

@willwashburn

Context

crates/relayburn-sdk/src/ingest/pending_stamps.rs:451-475 serialize_stamp and :406-444 parse_pending_stamp hand-roll JSON for PendingStamp. The struct already has Debug, Clone, PartialEq and the workspace already enables serde_json/preserve_order.

Adjacent: pending_stamps.rs:594-630 uuid_v4 shells out to read /dev/urandom per call. harnesses/claude.rs:62-105 mint_session_id rolls another v4-shaped UUID using DefaultHasher over now+pid — much weaker than OsRng, and the formatting code is 24 lines.

Proposed fix

  1. Derive Serialize, Deserialize on PendingStamp with #[serde(rename_all = "camelCase")]. The two ad-hoc fns collapse to 1-line serde_json::to_string / from_str calls. ~80 LOC removed.
  2. Replace both UUID generators with one consistent path. Two options:
    • Add uuid = "1" (pulls in ~one crate) with the v4 feature.
    • Add getrandom = "0.2" and keep a small format helper.
      The first is cleaner; the doc comments at harnesses/claude.rs explicitly avoided pulling uuid "for one call site," but now there are two.

Verification

  • The *_compat_tests.rs files are explicitly named to catch byte-identical-ness with the TS sibling. Run cargo test -p relayburn-sdk pending_stamps after the change.
  • The TS sibling produces JSON in a deterministic field order — verify the #[serde(rename_all = "camelCase")] field declaration order in the struct matches.

References

  • crates/relayburn-sdk/src/ingest/pending_stamps.rs:406-444, 451-475, 594-630
  • crates/relayburn-cli/src/harnesses/claude.rs:62-105
  • Ingest+ledger and CLI review notes from the May 2026 Rust review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions