Skip to content

Move contract interface types (ThresholdParameters, protocol states) to contract-interface crate for Participants BTreeMap migration #2001

@pbeza

Description

@pbeza

Background

PR #1861 changes Participants from Vec<(AccountId, ParticipantId, ParticipantInfo)> to BTreeMap<AccountId, ParticipantData> for O(log n) lookups. To maintain JSON backward compatibility, we need to introduce DTO serialization types (ParticipantId, ParticipantInfo, ParticipantData, ParticipantsJson, ParticipantsField, ParticipantsJsonDeserialize) in the contract-interface crate.

As identified in Kevin's review, we need to:

  1. Use the DTO types in the actual contract interface — the contract should no longer serialize Participants directly; instead, it should convert to the DTO type via an .into_dto_type() (or similar) method.
  2. Move additional types to contract-interfaceParticipants is embedded in ThresholdParameters, which appears in the protocol contract states (Running, Initializing, Resharing), which are returned by the state() view function. These types must also be represented in the contract-interface crate to ensure backward compatibility is enforced at the DTO boundary.

This is significant but mostly mechanical/boilerplate work — defining DTO mirrors of the internal types and wiring up conversions.

User Story

As a contract developer, I need all types that appear in contract method inputs/outputs to be defined in the contract-interface crate, so that internal type changes (like the Participants Vec→BTreeMap migration in #1861) cannot accidentally break the JSON API.

Acceptance Criteria

  • The Participants DTO types from feat(dtos): add Participants JSON serialization types to contract-interface #1990 are used in the contract's public interface (not the internal Participants struct)
  • An .into_dto_type() (or From/Into impl) conversion exists from internal Participants to the DTO type
  • ThresholdParameters (or its DTO equivalent) is defined in contract-interface
  • Protocol state types (Running, Initializing, Resharing) that are returned by the state() view function have DTO representations in contract-interface
  • The state() view function serializes using the DTO types, not the internal types
  • Existing JSON output format is preserved (backward compatible) — validated by unit tests

Resources & Additional Notes

Metadata

Metadata

Assignees

Labels

contractrefactorImprovements to code structure, readability, or performance that don't add new features or fix bugs.tech-debt

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions