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
27 changes: 18 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use std::ops::{Div, RangeInclusive};
#[cfg(feature = "token-reward-explanations")]
use platform_version::version::PlatformVersion;
use crate::balances::credits::TokenAmount;
use crate::block::epoch::EpochIndex;
use crate::data_contract::associated_token::token_perpetual_distribution::distribution_function::{DistributionFunction, MAX_DISTRIBUTION_CYCLES_PARAM};
use crate::data_contract::associated_token::token_perpetual_distribution::distribution_function::DistributionFunction;
#[cfg(feature = "token-reward-explanations")]
use crate::data_contract::associated_token::token_perpetual_distribution::distribution_function::MAX_DISTRIBUTION_CYCLES_PARAM;
use crate::data_contract::associated_token::token_perpetual_distribution::distribution_function::reward_ratio::RewardRatio;
use crate::data_contract::associated_token::token_perpetual_distribution::reward_distribution_moment::RewardDistributionMoment;
use crate::ProtocolError;
#[cfg(feature = "token-reward-explanations")]
use chrono::{Utc, TimeZone};
#[cfg(feature = "token-reward-explanations")]
use chrono_tz::Tz;
Expand Down
8 changes: 6 additions & 2 deletions packages/rs-dpp/src/errors/consensus/basic/basic_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ use crate::consensus::basic::identity::{
InvalidIdentityPublicKeyDataError, InvalidIdentityPublicKeySecurityLevelError,
InvalidIdentityUpdateTransitionDisableKeysError, InvalidIdentityUpdateTransitionEmptyError,
InvalidInstantAssetLockProofError, InvalidInstantAssetLockProofSignatureError,
MissingMasterPublicKeyError, NotImplementedIdentityCreditWithdrawalTransitionPoolingError,
TooManyMasterPublicKeyError, WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError,
InvalidKeyPurposeForContractBoundsError, MissingMasterPublicKeyError,
NotImplementedIdentityCreditWithdrawalTransitionPoolingError, TooManyMasterPublicKeyError,
WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError,
};
use crate::consensus::basic::invalid_identifier_error::InvalidIdentifierError;
use crate::consensus::basic::state_transition::{
Expand Down Expand Up @@ -587,6 +588,9 @@ pub enum BasicError {

#[error(transparent)]
GroupHasTooFewMembersError(GroupHasTooFewMembersError),

#[error(transparent)]
InvalidKeyPurposeForContractBoundsError(InvalidKeyPurposeForContractBoundsError),
}

impl From<BasicError> for ConsensusError {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::consensus::basic::BasicError;
use crate::errors::ProtocolError;
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use thiserror::Error;

use crate::consensus::ConsensusError;

use crate::identity::Purpose;
use bincode::{Decode, Encode};

#[derive(
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
)]
#[error("Key purpose {given_key_purpose} is not allowed for contract bounds. Allowed purposes: {allowed_key_purposes:?}")]
#[platform_serialize(unversioned)]
pub struct InvalidKeyPurposeForContractBoundsError {
/*

DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION

*/
given_key_purpose: Purpose,
allowed_key_purposes: Vec<Purpose>,
}

impl InvalidKeyPurposeForContractBoundsError {
pub fn new(given_key_purpose: Purpose, allowed_key_purposes: Vec<Purpose>) -> Self {
Self {
given_key_purpose,
allowed_key_purposes,
}
}

pub fn given_key_purpose(&self) -> Purpose {
self.given_key_purpose
}

pub fn allowed_key_purposes(&self) -> &Vec<Purpose> {
&self.allowed_key_purposes
}
}

impl From<InvalidKeyPurposeForContractBoundsError> for ConsensusError {
fn from(err: InvalidKeyPurposeForContractBoundsError) -> Self {
Self::BasicError(BasicError::InvalidKeyPurposeForContractBoundsError(err))
}
}
2 changes: 2 additions & 0 deletions packages/rs-dpp/src/errors/consensus/basic/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use invalid_identity_update_transition_disable_keys_error::*;
pub use invalid_identity_update_transition_empty_error::*;
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 too_many_master_public_key_error::*;
Expand Down Expand Up @@ -60,6 +61,7 @@ mod invalid_identity_update_transition_disable_keys_error;
mod invalid_identity_update_transition_empty_error;
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 too_many_master_public_key_error;
Expand Down
1 change: 1 addition & 0 deletions packages/rs-dpp/src/errors/consensus/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ impl ErrorWithCode for BasicError {
Self::IdentityAssetLockTransactionOutPointNotEnoughBalanceError(_) => 10530,
Self::IdentityAssetLockStateTransitionReplayError(_) => 10531,
Self::WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError(_) => 10532,
Self::InvalidKeyPurposeForContractBoundsError(_) => 10533,

// State Transition Errors: 10600-10699
Self::InvalidStateTransitionTypeError { .. } => 10600,
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3528,7 +3528,7 @@ mod tests {
.build_with_mock_rpc()
.set_genesis_state();

let (identity, signer, key) =
let (identity, signer, _, key) =
setup_identity_return_master_key(&mut platform, 958, dash_to_credits!(0.1));

let mut rng = StdRng::seed_from_u64(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::execution::types::state_transition_execution_context::StateTransition
use dpp::consensus::basic::document::{
DataContractNotPresentError, InvalidDocumentTypeError,
};
use dpp::consensus::basic::identity::DataContractBoundsNotPresentError;
use dpp::consensus::basic::identity::{DataContractBoundsNotPresentError, InvalidKeyPurposeForContractBoundsError};
use dpp::consensus::basic::BasicError;
use dpp::consensus::ConsensusError;
use dpp::consensus::state::identity::identity_public_key_already_exists_for_unique_contract_bounds_error::IdentityPublicKeyAlreadyExistsForUniqueContractBoundsError;
Expand Down Expand Up @@ -164,10 +164,13 @@ fn validate_identity_public_key_contract_bounds_v0(
}
}
}
_ => Ok(SimpleConsensusValidationResult::new_with_error(
purpose => Ok(SimpleConsensusValidationResult::new_with_error(
ConsensusError::BasicError(
BasicError::DataContractNotPresentError(
DataContractNotPresentError::new(*contract_id),
BasicError::InvalidKeyPurposeForContractBoundsError(
InvalidKeyPurposeForContractBoundsError::new(
purpose,
vec![ENCRYPTION, DECRYPTION],
),
),
),
)),
Expand Down Expand Up @@ -279,8 +282,11 @@ fn validate_identity_public_key_contract_bounds_v0(
}
_ => Ok(SimpleConsensusValidationResult::new_with_error(
ConsensusError::BasicError(
BasicError::DataContractNotPresentError(
DataContractNotPresentError::new(*contract_id),
BasicError::InvalidKeyPurposeForContractBoundsError(
InvalidKeyPurposeForContractBoundsError::new(
purpose,
vec![ENCRYPTION, DECRYPTION],
),
),
),
)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod token_selling_tests {

use super::*;

use crate::error::Error;
use dpp::{
dashcore::secp256k1::hashes::hex::{Case, DisplayHex},
prelude::{DataContract, Identity, IdentityPublicKey},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ impl BatchTransitionInternalTransformerV0 for BatchTransition {
)?
.1
else {
println!("contract id not found {}", data_contract_id);
return Ok(ConsensusValidationResult::new_with_error(
BasicError::DataContractNotPresentError(DataContractNotPresentError::new(
*data_contract_id,
Expand Down
Loading
Loading