Skip to content
Open
10 changes: 7 additions & 3 deletions packages/rs-dpp/src/data_contract/data_contract_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ impl DataContractFacade {
/// Create Data Contract Update State Transition
pub fn create_data_contract_update_transition(
&self,
data_contract: DataContract,
old_data_contract: &DataContract,
new_data_contract: &DataContract,
identity_contract_nonce: IdentityNonce,
) -> Result<DataContractUpdateTransition, ProtocolError> {
self.factory
.create_data_contract_update_transition(data_contract, identity_contract_nonce)
self.factory.create_data_contract_update_transition(
old_data_contract,
new_data_contract,
identity_contract_nonce,
)
}
}
6 changes: 4 additions & 2 deletions packages/rs-dpp/src/data_contract/factory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ impl DataContractFactory {
/// Create a DataContractUpdateTransition
pub fn create_data_contract_update_transition(
&self,
data_contract: DataContract,
old_data_contract: &DataContract,
new_data_contract: &DataContract,
identity_contract_nonce: IdentityNonce,
) -> Result<DataContractUpdateTransition, ProtocolError> {
match self {
DataContractFactory::V0(v0) => v0.create_unsigned_data_contract_update_transition(
data_contract,
old_data_contract,
new_data_contract,
identity_contract_nonce,
),
}
Expand Down
9 changes: 6 additions & 3 deletions packages/rs-dpp/src/data_contract/factory/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,14 @@ impl DataContractFactoryV0 {
#[cfg(feature = "state-transitions")]
pub fn create_unsigned_data_contract_update_transition(
&self,
data_contract: DataContract,
old_data_contract: &DataContract,
new_data_contract: &DataContract,
identity_contract_nonce: IdentityNonce,
) -> Result<DataContractUpdateTransition, ProtocolError> {
DataContractUpdateTransition::try_from_platform_versioned(
(data_contract, identity_contract_nonce),
DataContractUpdateTransition::from_contract_update(
old_data_contract,
new_data_contract,
identity_contract_nonce,
PlatformVersion::get(self.protocol_version)?,
)
}
Expand Down
58 changes: 58 additions & 0 deletions packages/rs-dpp/src/data_contract/methods/apply_update/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
mod v0;

use crate::block::block_info::BlockInfo;
use crate::data_contract::update_values::DataContractUpdateValues;
use crate::data_contract::DataContract;
use crate::validation::operations::ProtocolValidationOperation;
use crate::validation::ConsensusValidationResult;
use crate::ProtocolError;
use platform_version::version::PlatformVersion;

impl DataContract {
/// Applies update values to this contract to produce a new contract.
///
/// This method takes the current contract and applies the changes specified in the
/// update values to produce a new updated contract. It merges document schemas,
/// groups, tokens, and keywords from the update into the existing contract.
///
/// This method dispatches to a version-specific implementation based on the
/// platform version configuration. If the version is unrecognized, it returns a version mismatch error.
///
/// # Arguments
/// - `update_values`: The update values containing the changes to apply.
/// - `block_info`: Block information containing timestamp, epoch, and height for the update.
/// - `full_validation`: Whether to perform full validation on the resulting contract.
/// - `validation_operations`: A vector to collect validation operations.
/// - `platform_version`: The current platform version.
///
/// # Returns
/// - `Ok(ConsensusValidationResult<DataContract>)`: The validation result containing the new contract if successful.
/// - `Err(ProtocolError)`: If the platform version is unrecognized or if a protocol error occurs.
///
/// # Version Behavior
/// - Version 0: Applies updates using the standard merge logic for document schemas,
/// groups, tokens, keywords, and description.
pub fn apply_update(
&self,
update_values: DataContractUpdateValues<'_>,
block_info: &BlockInfo,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<ConsensusValidationResult<DataContract>, ProtocolError> {
match platform_version.dpp.contract_versions.methods.apply_update {
0 => self.apply_update_v0(
update_values,
block_info,
full_validation,
validation_operations,
platform_version,
),
version => Err(ProtocolError::UnknownVersionMismatch {
method: "DataContract::apply_update".to_string(),
known_versions: vec![0],
received: version,
}),
}
}
}
Loading
Loading