Skip to content

Comments

feat(sdk): add client-side validate_structure() to remaining state transitions#3100

Closed
thepastaclaw wants to merge 1 commit intodashpay:v3.1-devfrom
thepastaclaw:feat/sdk-client-side-structure-validation
Closed

feat(sdk): add client-side validate_structure() to remaining state transitions#3100
thepastaclaw wants to merge 1 commit intodashpay:v3.1-devfrom
thepastaclaw:feat/sdk-client-side-structure-validation

Conversation

@thepastaclaw
Copy link
Contributor

@thepastaclaw thepastaclaw commented Feb 18, 2026

Summary

Add client-side validate_structure() calls to 6 remaining state transition SDK construction methods. This follows the pattern established in #3096 (which added it to IdentityCreate, IdentityUpdate, and IdentityCreateFromAddresses).

Per shumkov's review comment: extend validation to all state transitions for consistent SDK behavior.

Changes

Each state transition's try_from_* construction method now calls validate_structure() on the fully-constructed transition struct before returning, giving SDK users immediate error feedback instead of waiting for network rejection.

State Transition Method Validation Placement
AddressCreditWithdrawalTransition try_from_inputs_with_signer After input_witnesses set
AddressFundingFromAssetLockTransition try_from_asset_lock_with_signer After signature + input_witnesses set
AddressFundsTransferTransition try_from_inputs_with_signer After input_witnesses set
IdentityCreateFromAddressesTransition try_from_inputs_with_signer After public key sigs + input_witnesses set
IdentityCreditTransferToAddressesTransition try_from_identity Before .into() conversion
IdentityTopUpFromAddressesTransition try_from_inputs_with_signer After input_witnesses set

Pattern

Same pattern as #3096:

let validation_result = transition.validate_structure(platform_version);
if !validation_result.is_valid() {
    let first_error = validation_result.errors.into_iter().next().unwrap();
    return Err(ProtocolError::ConsensusError(Box::new(first_error)));
}

Build

cargo check -p dpp --features state-transition-signing,state-transition-validation passes clean (zero warnings).

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Added runtime validation for state transitions across address funding, address credit withdrawal, and identity operations to ensure structural integrity at construction time, preventing invalid transitions from being propagated and improving error detection.

…ansitions

Add client-side structure validation to 6 state transition SDK construction
methods, following the pattern established in PR dashpay#3096. This ensures invalid
transitions are caught early on the client side before being submitted.

State transitions updated:
- AddressCreditWithdrawalTransition
- AddressFundingFromAssetLockTransition
- AddressFundsTransferTransition
- IdentityCreateFromAddressesTransition
- IdentityCreditTransferToAddressesTransition
- IdentityTopUpFromAddressesTransition

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Runtime structure validation is added to six state transition v0 implementations. Each transition's try_from_*_with_signer method now invokes validate_structure() immediately after construction and returns ConsensusError if validation fails. Parameter _platform_version is renamed to platform_version across all files to reflect the actual usage.

Changes

Cohort / File(s) Summary
Address Funds Transitions
address_credit_withdrawal_transition/v0/v0_methods.rs, address_funding_from_asset_lock_transition/v0/v0_methods.rs, address_funds_transfer_transition/v0/v0_methods.rs
Added post-construction validate_structure(platform_version) call in try_from_*_with_signer methods with early ConsensusError return on validation failure. Renamed _platform_version parameter to platform_version. Imported StateTransitionStructureValidation.
Identity Transitions
identity_create_from_addresses_transition/v0/v0_methods.rs, identity_credit_transfer_to_addresses_transition/v0/v0_methods.rs, identity_topup_from_addresses_transition/v0/v0_methods.rs
Added post-construction validate_structure(platform_version) call in try_from_*_with_signer or try_from_identity methods with early ConsensusError return on validation failure. Renamed _platform_version parameter to platform_version. Imported StateTransitionStructureValidation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 Six transitions now stand tall,
With structure checked before they call,
Valid states flow through the code,
No bad data down the road!
Validation springs eternal true.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@thepastaclaw
Copy link
Contributor Author

Closing — this is duplicative of #3096 which was already updated to include validate_structure() for all state transitions. My mistake, I was working off a stale view of #3096's diff.

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.

1 participant