-
Notifications
You must be signed in to change notification settings - Fork 50
feat(sdk): add client-side validation to state transition construction methods #3096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.1-dev
Are you sure you want to change the base?
Changes from all commits
854957b
01ccf22
f86015e
7f5fdbf
82f1577
bfce46b
1cd4c6b
ed30f29
9cc4c85
465a55c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ use crate::serialization::Signable; | |
| use crate::state_transition::address_credit_withdrawal_transition::methods::AddressCreditWithdrawalTransitionMethodsV0; | ||
| use crate::state_transition::address_credit_withdrawal_transition::v0::AddressCreditWithdrawalTransitionV0; | ||
| #[cfg(feature = "state-transition-signing")] | ||
| use crate::state_transition::StateTransitionStructureValidation; | ||
| #[cfg(feature = "state-transition-signing")] | ||
| use crate::withdrawal::Pooling; | ||
| #[cfg(feature = "state-transition-signing")] | ||
| use crate::{ | ||
|
|
@@ -35,7 +37,7 @@ impl AddressCreditWithdrawalTransitionMethodsV0 for AddressCreditWithdrawalTrans | |
| output_script: CoreScript, | ||
| signer: &S, | ||
| user_fee_increase: UserFeeIncrease, | ||
| _platform_version: &PlatformVersion, | ||
| platform_version: &PlatformVersion, | ||
| ) -> Result<StateTransition, ProtocolError> { | ||
| tracing::debug!("try_from_inputs_with_signer: Started"); | ||
| tracing::debug!( | ||
|
|
@@ -66,6 +68,14 @@ impl AddressCreditWithdrawalTransitionMethodsV0 for AddressCreditWithdrawalTrans | |
| .map(|address| signer.sign_create_witness(address, &signable_bytes)) | ||
| .collect::<Result<Vec<AddressWitness>, ProtocolError>>()?; | ||
|
|
||
| // Validate the fully-constructed transition structure | ||
| let validation_result = | ||
| address_credit_withdrawal_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))); | ||
| } | ||
|
Comment on lines
+74
to
+77
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: Only the first validation error is returned; remaining errors are discarded All 9 validation sites extract only the first error from source: ['claude'] 🤖 Fix this with AI agents |
||
|
|
||
| tracing::debug!("try_from_inputs_with_signer: Successfully created transition"); | ||
| Ok(address_credit_withdrawal_transition.into()) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Replace unwrap() with if-let across 9 validation sites
The pattern
validation_result.errors.into_iter().next().unwrap()appears 9 times across production code gated behindstate-transition-signing. The unwrap is logically safe —!is_valid()guaranteeserrorsis non-empty sinceis_valid()returnsself.errors.is_empty(). However, it violates the project convention of nounwrap()in production code, and the panic-free alternative is trivial.Affected files (all in
packages/rs-dpp/src/state_transition/state_transitions/):address_funds/address_credit_withdrawal_transition/v0/v0_methods.rsaddress_funds/address_funding_from_asset_lock_transition/v0/v0_methods.rsaddress_funds/address_funds_transfer_transition/v0/v0_methods.rsidentity/identity_create_from_addresses_transition/v0/v0_methods.rs(×2)identity/identity_create_transition/v0/v0_methods.rsidentity/identity_credit_transfer_to_addresses_transition/v0/v0_methods.rsidentity/identity_topup_from_addresses_transition/v0/v0_methods.rsidentity/identity_update_transition/v0/v0_methods.rssource: ['claude']
🤖 Fix this with AI agents