Skip to content

Conversation

@sanity
Copy link
Contributor

@sanity sanity commented Oct 28, 2025

Summary

Addresses file bloat in freenet-stdlib by splitting the 1992-line contract_interface.rs into 12 focused modules with clear separation of concerns.

Motivation

This file has been a pain point for navigation and maintenance. While it interfaces with WASM code (making API changes non-trivial), we can safely reorganize the internal structure without breaking the public API.

What Changed

Split rust/src/contract_interface.rs (1992 lines) into a module directory:

Core Type Modules:

  • error.rs - ContractError type (19 lines)
  • state.rs - State, StateDelta, StateSummary (225 lines)
  • key.rs - ContractInstanceId, ContractKey, helper functions (249 lines)
  • code.rs - ContractCode (138 lines)
  • update.rs - UpdateModification, RelatedContracts, UpdateData, etc. (330 lines)
  • contract.rs - Contract type (89 lines)
  • wrapped.rs - WrappedState, WrappedContract (183 lines)
  • trait_def.rs - ContractInterface trait (88 lines)

Special Modules:

  • wasm_interface.rs - WASM FFI boundary, pub(crate) (199 lines)
  • encoding.rs - Typed contract helpers, pub (384 lines)
  • tests.rs - Unit tests (51 lines)
  • mod.rs - Re-exports preserving public API (33 lines)

API Compatibility

No breaking changes - All public types re-exported from mod.rs
Same imports work - use freenet_stdlib::prelude::*; unchanged
All feature flags preserved - #[cfg(feature = "testing")], etc.
All tests pass - 6/6 tests green, builds with --all-features

Benefits

  • Easier navigation - Find types quickly by module name
  • Clear dependencies - Module structure shows type relationships
  • Better maintainability - Smaller files, focused responsibilities
  • No churn for users - Public API completely unchanged

Test Plan

cd rust
cargo test --lib contract_interface  # 3/3 tests pass
cargo test --lib                      # 6/6 tests pass
cargo build --all-features            #

Review Notes

This is a mechanical refactoring - code was moved but not modified. The only changes are:

  • Adjusting imports (use super::*; instead of use crate::contract_interface::*;)
  • Module re-exports in mod.rs
  • Removing duplicate feature flags from re-exported types

Requesting @iduartgomez review - This touches the WASM interface boundary, and while the API is preserved, I want sign-off that the module structure makes sense.

🤖 Generated with Claude Code

[AI-assisted debugging and comment]

Split the 1992-line contract_interface.rs into 12 focused modules:
- error.rs: ContractError type
- state.rs: State, StateDelta, StateSummary
- key.rs: ContractInstanceId, ContractKey
- code.rs: ContractCode
- update.rs: Update-related types (UpdateModification, RelatedContracts, etc.)
- contract.rs: Contract type
- wrapped.rs: WrappedState, WrappedContract
- trait_def.rs: ContractInterface trait
- wasm_interface.rs: WASM FFI boundary (pub(crate))
- encoding.rs: Typed contract helpers (pub)
- tests.rs: Unit tests
- mod.rs: Re-exports maintaining public API

Benefits:
- Improved code navigation and maintainability
- Clearer separation of concerns
- Easier to understand dependencies between types
- No breaking changes - all public APIs preserved via re-exports

All tests pass. No functional changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants