Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/rs-dpp/src/errors/consensus/basic/basic_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ use crate::consensus::basic::identity::{
InvalidIdentityAssetLockProofChainLockValidationError,
InvalidIdentityAssetLockTransactionError, InvalidIdentityAssetLockTransactionOutputError,
InvalidIdentityCreditTransferAmountError, InvalidIdentityCreditWithdrawalTransitionAmountError,
InvalidIdentityCreditWithdrawalTransitionCoreFeeError,
InvalidIdentityCreditWithdrawalTransitionOutputScriptError, InvalidIdentityKeySignatureError,
InvalidCreditWithdrawalTransitionCoreFeeError,
InvalidCreditWithdrawalTransitionOutputScriptError, InvalidIdentityKeySignatureError,
InvalidIdentityPublicKeyDataError, InvalidIdentityPublicKeySecurityLevelError,
InvalidIdentityUpdateTransitionDisableKeysError, InvalidIdentityUpdateTransitionEmptyError,
InvalidInstantAssetLockProofError, InvalidInstantAssetLockProofSignatureError,
InvalidKeyPurposeForContractBoundsError, MissingMasterPublicKeyError,
NotImplementedIdentityCreditWithdrawalTransitionPoolingError, TooManyMasterPublicKeyError,
NotImplementedCreditWithdrawalTransitionPoolingError, TooManyMasterPublicKeyError,
WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError,
};
use crate::consensus::basic::invalid_identifier_error::InvalidIdentifierError;
Expand Down Expand Up @@ -364,8 +364,8 @@ pub enum BasicError {
InvalidIdentityCreditTransferAmountError(InvalidIdentityCreditTransferAmountError),

#[error(transparent)]
InvalidIdentityCreditWithdrawalTransitionOutputScriptError(
InvalidIdentityCreditWithdrawalTransitionOutputScriptError,
InvalidCreditWithdrawalTransitionOutputScriptError(
InvalidCreditWithdrawalTransitionOutputScriptError,
),

#[error(transparent)]
Expand All @@ -374,8 +374,8 @@ pub enum BasicError {
),

#[error(transparent)]
InvalidIdentityCreditWithdrawalTransitionCoreFeeError(
InvalidIdentityCreditWithdrawalTransitionCoreFeeError,
InvalidCreditWithdrawalTransitionCoreFeeError(
InvalidCreditWithdrawalTransitionCoreFeeError,
),

#[error(transparent)]
Expand All @@ -392,8 +392,8 @@ pub enum BasicError {
),

#[error(transparent)]
NotImplementedIdentityCreditWithdrawalTransitionPoolingError(
NotImplementedIdentityCreditWithdrawalTransitionPoolingError,
NotImplementedCreditWithdrawalTransitionPoolingError(
NotImplementedCreditWithdrawalTransitionPoolingError,
),

// State Transition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bincode::{Decode, Encode};
)]
#[error("Core fee per byte {core_fee_per_byte:?} must be part of fibonacci sequence and not less than {min_core_fee_per_byte:?}")]
#[platform_serialize(unversioned)]
pub struct InvalidIdentityCreditWithdrawalTransitionCoreFeeError {
pub struct InvalidCreditWithdrawalTransitionCoreFeeError {
/*

DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION
Expand All @@ -22,7 +22,7 @@ pub struct InvalidIdentityCreditWithdrawalTransitionCoreFeeError {
min_core_fee_per_byte: u32,
}

impl InvalidIdentityCreditWithdrawalTransitionCoreFeeError {
impl InvalidCreditWithdrawalTransitionCoreFeeError {
pub fn new(core_fee_per_byte: u32, min_core_fee_per_byte: u32) -> Self {
Self {
core_fee_per_byte,
Expand All @@ -38,8 +38,8 @@ impl InvalidIdentityCreditWithdrawalTransitionCoreFeeError {
}
}

impl From<InvalidIdentityCreditWithdrawalTransitionCoreFeeError> for ConsensusError {
fn from(err: InvalidIdentityCreditWithdrawalTransitionCoreFeeError) -> Self {
Self::BasicError(BasicError::InvalidIdentityCreditWithdrawalTransitionCoreFeeError(err))
impl From<InvalidCreditWithdrawalTransitionCoreFeeError> for ConsensusError {
fn from(err: InvalidCreditWithdrawalTransitionCoreFeeError) -> Self {
Self::BasicError(BasicError::InvalidCreditWithdrawalTransitionCoreFeeError(err))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bincode::{Decode, Encode};
)]
#[error("Output script must be either p2pkh or p2sh")]
#[platform_serialize(unversioned)]
pub struct InvalidIdentityCreditWithdrawalTransitionOutputScriptError {
pub struct InvalidCreditWithdrawalTransitionOutputScriptError {
output_script: CoreScript,
}

Expand All @@ -23,7 +23,7 @@ DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION

*/

impl InvalidIdentityCreditWithdrawalTransitionOutputScriptError {
impl InvalidCreditWithdrawalTransitionOutputScriptError {
pub fn new(output_script: CoreScript) -> Self {
Self { output_script }
}
Expand All @@ -33,10 +33,10 @@ impl InvalidIdentityCreditWithdrawalTransitionOutputScriptError {
self.output_script.clone()
}
}
impl From<InvalidIdentityCreditWithdrawalTransitionOutputScriptError> for ConsensusError {
fn from(err: InvalidIdentityCreditWithdrawalTransitionOutputScriptError) -> Self {
impl From<InvalidCreditWithdrawalTransitionOutputScriptError> for ConsensusError {
fn from(err: InvalidCreditWithdrawalTransitionOutputScriptError) -> Self {
Self::BasicError(
BasicError::InvalidIdentityCreditWithdrawalTransitionOutputScriptError(err),
BasicError::InvalidCreditWithdrawalTransitionOutputScriptError(err),
)
}
}
12 changes: 6 additions & 6 deletions packages/rs-dpp/src/errors/consensus/basic/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub use invalid_identity_asset_lock_transaction_error::*;
pub use invalid_identity_asset_lock_transaction_output_error::*;
pub use invalid_identity_credit_transfer_amount_error::*;
pub use invalid_identity_credit_withdrawal_transition_amount_error::*;
pub use invalid_identity_credit_withdrawal_transition_core_fee_error::*;
pub use invalid_identity_credit_withdrawal_transition_output_script_error::*;
pub use invalid_credit_withdrawal_transition_core_fee_error::*;
pub use invalid_credit_withdrawal_transition_output_script_error::*;
pub use invalid_identity_key_signature_error::*;
pub use invalid_identity_public_key_data_error::*;
pub use invalid_identity_public_key_security_level_error::*;
Expand All @@ -28,7 +28,7 @@ pub use invalid_instant_asset_lock_proof_error::*;
pub use invalid_instant_asset_lock_proof_signature_error::*;
pub use invalid_key_purpose_for_contract_bounds_error::*;
pub use missing_master_public_key_error::*;
pub use not_implemented_identity_credit_withdrawal_transition_pooling_error::*;
pub use not_implemented_credit_withdrawal_transition_pooling_error::*;
pub use too_many_master_public_key_error::*;
pub use withdrawal_output_script_not_allowed_when_signing_with_owner_key::*;

Expand All @@ -52,8 +52,8 @@ mod invalid_identity_asset_lock_transaction_error;
mod invalid_identity_asset_lock_transaction_output_error;
mod invalid_identity_credit_transfer_amount_error;
mod invalid_identity_credit_withdrawal_transition_amount_error;
mod invalid_identity_credit_withdrawal_transition_core_fee_error;
mod invalid_identity_credit_withdrawal_transition_output_script_error;
mod invalid_credit_withdrawal_transition_core_fee_error;
mod invalid_credit_withdrawal_transition_output_script_error;
mod invalid_identity_key_signature_error;
mod invalid_identity_public_key_data_error;
mod invalid_identity_public_key_security_level_error;
Expand All @@ -63,6 +63,6 @@ mod invalid_instant_asset_lock_proof_error;
mod invalid_instant_asset_lock_proof_signature_error;
mod invalid_key_purpose_for_contract_bounds_error;
mod missing_master_public_key_error;
mod not_implemented_identity_credit_withdrawal_transition_pooling_error;
mod not_implemented_credit_withdrawal_transition_pooling_error;
mod too_many_master_public_key_error;
mod withdrawal_output_script_not_allowed_when_signing_with_owner_key;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bincode::{Decode, Encode};
"pooling {pooling:?} should be equal to 0. Other pooling mechanism are not implemented yet"
)]
#[platform_serialize(unversioned)]
pub struct NotImplementedIdentityCreditWithdrawalTransitionPoolingError {
pub struct NotImplementedCreditWithdrawalTransitionPoolingError {
/*

DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION
Expand All @@ -23,7 +23,7 @@ pub struct NotImplementedIdentityCreditWithdrawalTransitionPoolingError {
pooling: u8,
}

impl NotImplementedIdentityCreditWithdrawalTransitionPoolingError {
impl NotImplementedCreditWithdrawalTransitionPoolingError {
pub fn new(pooling: u8) -> Self {
Self { pooling }
}
Expand All @@ -33,10 +33,10 @@ impl NotImplementedIdentityCreditWithdrawalTransitionPoolingError {
}
}

impl From<NotImplementedIdentityCreditWithdrawalTransitionPoolingError> for ConsensusError {
fn from(err: NotImplementedIdentityCreditWithdrawalTransitionPoolingError) -> Self {
impl From<NotImplementedCreditWithdrawalTransitionPoolingError> for ConsensusError {
fn from(err: NotImplementedCreditWithdrawalTransitionPoolingError) -> Self {
Self::BasicError(
BasicError::NotImplementedIdentityCreditWithdrawalTransitionPoolingError(err),
BasicError::NotImplementedCreditWithdrawalTransitionPoolingError(err),
)
}
}
6 changes: 3 additions & 3 deletions packages/rs-dpp/src/errors/consensus/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ impl ErrorWithCode for BasicError {
Self::TooManyMasterPublicKeyError(_) => 10518,
Self::InvalidIdentityPublicKeySecurityLevelError(_) => 10519,
Self::InvalidIdentityKeySignatureError { .. } => 10520,
Self::InvalidIdentityCreditWithdrawalTransitionOutputScriptError(_) => 10521,
Self::InvalidIdentityCreditWithdrawalTransitionCoreFeeError(_) => 10522,
Self::NotImplementedIdentityCreditWithdrawalTransitionPoolingError(_) => 10523,
Self::InvalidCreditWithdrawalTransitionOutputScriptError(_) => 10521,
Self::InvalidCreditWithdrawalTransitionCoreFeeError(_) => 10522,
Self::NotImplementedCreditWithdrawalTransitionPoolingError(_) => 10523,
Self::InvalidIdentityCreditTransferAmountError(_) => 10524,
Self::InvalidIdentityCreditWithdrawalTransitionAmountError(_) => 10525,
Self::InvalidIdentityUpdateTransitionEmptyError(_) => 10526,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use crate::address_funds::AddressFundsFeeStrategyStep;
use crate::consensus::basic::identity::{
InvalidCreditWithdrawalTransitionCoreFeeError,
InvalidCreditWithdrawalTransitionOutputScriptError,
NotImplementedCreditWithdrawalTransitionPoolingError,
};
use crate::consensus::basic::overflow_error::OverflowError;
use crate::consensus::basic::state_transition::{
FeeStrategyDuplicateError, FeeStrategyEmptyError, FeeStrategyIndexOutOfBoundsError,
Expand All @@ -8,8 +13,11 @@ use crate::consensus::basic::state_transition::{
};
use crate::consensus::basic::BasicError;
use crate::state_transition::address_credit_withdrawal_transition::v0::AddressCreditWithdrawalTransitionV0;
use crate::state_transition::address_credit_withdrawal_transition::MIN_CORE_FEE_PER_BYTE;
use crate::state_transition::StateTransitionStructureValidation;
use crate::util::is_fibonacci_number::is_fibonacci_number;
use crate::validation::SimpleConsensusValidationResult;
use crate::withdrawal::Pooling;
use platform_version::version::PlatformVersion;
use std::collections::HashSet;

Expand Down Expand Up @@ -166,6 +174,36 @@ impl StateTransitionStructureValidation for AddressCreditWithdrawalTransitionV0
// Note: The withdrawal amount is implicitly input_sum - output_sum
// No explicit balance check needed here as the withdrawal amount is computed, not specified

// Validate pooling - currently we do not support pooling, so we must validate that pooling is `Never`
if self.pooling != Pooling::Never {
return SimpleConsensusValidationResult::new_with_error(
NotImplementedCreditWithdrawalTransitionPoolingError::new(
self.pooling as u8,
)
.into(),
);
}

// Validate core_fee_per_byte is a Fibonacci number
if !is_fibonacci_number(self.core_fee_per_byte as u64) {
return SimpleConsensusValidationResult::new_with_error(
InvalidCreditWithdrawalTransitionCoreFeeError::new(
self.core_fee_per_byte,
MIN_CORE_FEE_PER_BYTE,
)
.into(),
);
}

// Validate output_script is P2PKH or P2SH
if !self.output_script.is_p2pkh() && !self.output_script.is_p2sh() {
return SimpleConsensusValidationResult::new_with_error(
InvalidCreditWithdrawalTransitionOutputScriptError::new(
self.output_script.clone(),
)
.into(),
);
}
// Validate input sum doesn't overflow
let input_sum = self
.inputs
Expand Down
Loading
Loading