diff --git a/.yarn/cache/fsevents-patch-19706e7e35-10.zip b/.yarn/cache/fsevents-patch-19706e7e35-10.zip new file mode 100644 index 0000000000..aff1ab12ce Binary files /dev/null and b/.yarn/cache/fsevents-patch-19706e7e35-10.zip differ diff --git a/Cargo.lock b/Cargo.lock index 163a9e8240..dc4f8a653e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2065,9 +2065,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "grovedb" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77097f0a4cc70c4a69fa400f633c5f18739e446eaed05269a3d76e17fa4d33d2" +checksum = "7d91e8f87926c834c7338d0c69a48816c043e0cddf0062a8a567483db2fb1e24" dependencies = [ "axum 0.7.5", "bincode", @@ -2093,15 +2093,16 @@ dependencies = [ "tempfile", "thiserror", "tokio", + "tokio-util", "tower-http", "zip-extensions", ] [[package]] name = "grovedb-costs" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0487d63a68621b910567a911b3708a8246501ae1912fa2f1920474dcb28a207" +checksum = "360f7c8d3b20beafcbf3cde8754bbcfd201ae2a30ec7594a4b9678fd2fa3c7a8" dependencies = [ "integer-encoding", "intmap", @@ -2110,9 +2111,9 @@ dependencies = [ [[package]] name = "grovedb-epoch-based-storage-flags" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53eb4b99b056e34bcceef2d604c883aee40daa688ceb7ec558456e10bef27c64" +checksum = "acec1b6962d99d7b079c0fd1532cd3a2c83a3d659ffd9fcf02edda4599334bb4" dependencies = [ "grovedb-costs", "hex", @@ -2123,9 +2124,9 @@ dependencies = [ [[package]] name = "grovedb-merk" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daedc296cac3093d244cbda0a11a5ef378bd4f747fcbe45b6cbed040c78cfb36" +checksum = "72057865f239fdd24f92eaa8668acc0d618da168f330546577a62eda1701210e" dependencies = [ "bincode", "blake3", @@ -2149,15 +2150,15 @@ dependencies = [ [[package]] name = "grovedb-path" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3552accddbfe6e586853f50a102d665efc0449a63504e5e2113389be924f98c" +checksum = "5d96cc6106e5ca88e548d66f130b877b664da78be226dfdba555fc210f8508f4" [[package]] name = "grovedb-storage" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868d74460c6205563e7bc72549f3fa057ed8bd0f83d96e04b2286ca0a216149" +checksum = "e1c9b59bc9fa7123b8485f87f88a886dd109e7aff5f34a29a3812cb64eb897ff" dependencies = [ "blake3", "grovedb-costs", @@ -2175,9 +2176,9 @@ dependencies = [ [[package]] name = "grovedb-version" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d62bd20c621681dfd8aa6ca128702de775c67560c1fe412f380c5278d5c48ba" +checksum = "f4be0c1a1ef97068fe93212e7b6f349e0b44a9fc90063c8c28e110cfb8c2fcb2" dependencies = [ "thiserror", "versioned-feature-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2185,9 +2186,9 @@ dependencies = [ [[package]] name = "grovedb-visualize" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6cd92c3a11055b1d841d071f801517b98575f9704f5a757a016fe83d35a37b8" +checksum = "5865f4335eb99644512a7d80d6b1698ba1099a8268fdfd3ffb1a3a32dcb4af28" dependencies = [ "hex", "itertools 0.12.1", @@ -2195,9 +2196,9 @@ dependencies = [ [[package]] name = "grovedbg-types" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "003e5066965932dbb617e5966df5f73a066eb721579840b30ddd46bf04311fc8" +checksum = "921b9a29facf9d3f0de667cd1da083a34695ede9e7bfacd74bb5bd29f8f7c178" dependencies = [ "serde", "serde_with 3.9.0", diff --git a/packages/js-dash-sdk/src/SDK/Client/Platform/methods/identities/creditWithdrawal.ts b/packages/js-dash-sdk/src/SDK/Client/Platform/methods/identities/creditWithdrawal.ts index a2bd513397..4be23a4a67 100644 --- a/packages/js-dash-sdk/src/SDK/Client/Platform/methods/identities/creditWithdrawal.ts +++ b/packages/js-dash-sdk/src/SDK/Client/Platform/methods/identities/creditWithdrawal.ts @@ -28,37 +28,50 @@ const MIN_ASSET_UNLOCK_CORE_FEE_PER_BYTE = 1; const MINIMAL_WITHDRAWAL_AMOUNT = ASSET_UNLOCK_TX_SIZE * MIN_ASSET_UNLOCK_CORE_FEE_PER_BYTE * 1000; type WithdrawalOptions = { - signingKeyIndex: number + signingKeyIndex?: number + toAddress?: string }; /** Creates platform credits withdrawal request * @param identity - identity to withdraw from * @param amount - amount of credits to withdraw - * @param to - Dash L1 address * @param options - withdrawal options + * @param [options] - withdrawal options + * @param [options.toAddress] - withdrawal destination address */ export async function creditWithdrawal( this: Platform, identity: Identity, amount: number, - to: string, - options: WithdrawalOptions = { - signingKeyIndex: 3, - }, + options: WithdrawalOptions = { }, ): Promise { await this.initialize(); + // eslint-disable-next-line no-param-reassign + options = { + ...options, + signingKeyIndex: 3, + }; + const { dpp } = this; - let toAddress: Address; - try { - toAddress = new Address(to, this.client.network); - } catch (e) { - throw new Error(`Invalid core recipient "${to}" for network ${this.client.network}`); + let outputScriptBytes: Buffer | undefined; + if (options.toAddress) { + let toAddress: Address; + try { + toAddress = new Address(options.toAddress, this.client.network); + } catch (e) { + throw new Error(`Invalid core recipient "${options.toAddress}" for network ${this.client.network}`); + } + + const outputScript = Script.buildPublicKeyHashOut(toAddress); + // @ts-ignore + outputScriptBytes = outputScript.toBuffer(); + + this.logger.debug(`[Identity#creditWithdrawal] credits withdrawal from ${identity.getId().toString()} to ${toAddress.toString()} with amount ${amount}`); + } else { + this.logger.debug(`[Identity#creditWithdrawal] credits withdrawal from ${identity.getId().toString()} to recent withdrawal address with amount ${amount}`); } - this.logger.debug(`[Identity#creditWithdrawal] credits withdrawal from ${identity.getId().toString()} to ${toAddress.toString()} with amount ${amount}`); - - const outputScript = Script.buildPublicKeyHashOut(toAddress); const balance = identity.getBalance(); if (amount > balance) { @@ -88,8 +101,7 @@ export async function creditWithdrawal( BigInt(amount), coreFeePerByte, DEFAULT_POOLING, - // @ts-ignore - outputScript.toBuffer(), + outputScriptBytes, BigInt(identityNonce), ); diff --git a/packages/rs-dpp/src/identity/identity_facade.rs b/packages/rs-dpp/src/identity/identity_facade.rs index 919c68c624..eecdf45e6e 100644 --- a/packages/rs-dpp/src/identity/identity_facade.rs +++ b/packages/rs-dpp/src/identity/identity_facade.rs @@ -123,7 +123,7 @@ impl IdentityFacade { amount: u64, core_fee_per_byte: u32, pooling: Pooling, - output_script: CoreScript, + output_script: Option, identity_nonce: u64, ) -> Result { self.factory.create_identity_credit_withdrawal_transition( diff --git a/packages/rs-dpp/src/identity/identity_factory.rs b/packages/rs-dpp/src/identity/identity_factory.rs index c6aface591..48f7369818 100644 --- a/packages/rs-dpp/src/identity/identity_factory.rs +++ b/packages/rs-dpp/src/identity/identity_factory.rs @@ -43,6 +43,8 @@ use crate::state_transition::identity_credit_transfer_transition::IdentityCredit #[cfg(all(feature = "state-transitions", feature = "client"))] use crate::state_transition::identity_credit_withdrawal_transition::v0::IdentityCreditWithdrawalTransitionV0; #[cfg(all(feature = "state-transitions", feature = "client"))] +use crate::state_transition::identity_credit_withdrawal_transition::v1::IdentityCreditWithdrawalTransitionV1; +#[cfg(all(feature = "state-transitions", feature = "client"))] use crate::state_transition::identity_credit_withdrawal_transition::IdentityCreditWithdrawalTransition; #[cfg(all(feature = "state-transitions", feature = "client"))] use crate::state_transition::identity_topup_transition::accessors::IdentityTopUpTransitionAccessorsV0; @@ -233,22 +235,61 @@ impl IdentityFactory { amount: u64, core_fee_per_byte: u32, pooling: Pooling, - output_script: CoreScript, + output_script: Option, identity_nonce: IdentityNonce, ) -> Result { - let identity_credit_withdrawal_transition = IdentityCreditWithdrawalTransitionV0 { - identity_id, - amount, - core_fee_per_byte, - pooling, - output_script, - nonce: identity_nonce, - ..Default::default() + let platform_version = PlatformVersion::get(self.protocol_version)?; + + let identity_credit_withdrawal_transition = match platform_version + .dpp + .state_transitions + .identities + .credit_withdrawal + .default_constructor + { + 0 => { + let output_script = output_script.ok_or_else(|| { + ProtocolError::Generic( + "Output script is required for IdentityCreditWithdrawalTransitionV0" + .to_string(), + ) + })?; + + let transition = IdentityCreditWithdrawalTransitionV0 { + identity_id, + amount, + core_fee_per_byte, + pooling, + output_script, + nonce: identity_nonce, + ..Default::default() + }; + + IdentityCreditWithdrawalTransition::from(transition) + } + 1 => { + let transition = IdentityCreditWithdrawalTransitionV1 { + identity_id, + amount, + core_fee_per_byte, + pooling, + output_script, + nonce: identity_nonce, + ..Default::default() + }; + + IdentityCreditWithdrawalTransition::from(transition) + } + version => { + return Err(ProtocolError::UnknownVersionMismatch { + method: "create_identity_credit_withdrawal_transition".to_string(), + known_versions: vec![0, 1], + received: version, + }); + } }; - Ok(IdentityCreditWithdrawalTransition::from( - identity_credit_withdrawal_transition, - )) + Ok(identity_credit_withdrawal_transition) } #[cfg(all(feature = "state-transitions", feature = "client"))] diff --git a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_withdrawal_transition/mod.rs b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_withdrawal_transition/mod.rs index 5b93592a36..0badee88b9 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_withdrawal_transition/mod.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_withdrawal_transition/mod.rs @@ -73,8 +73,10 @@ impl IdentityCreditWithdrawalTransition { pub fn default_versioned(platform_version: &PlatformVersion) -> Result { match platform_version .dpp - .identity_versions - .identity_structure_version + .state_transitions + .identities + .credit_withdrawal + .default_constructor { 0 => Ok(IdentityCreditWithdrawalTransition::V0( IdentityCreditWithdrawalTransitionV0::default(), diff --git a/packages/rs-drive/Cargo.toml b/packages/rs-drive/Cargo.toml index 50915b06e2..94938455c5 100644 --- a/packages/rs-drive/Cargo.toml +++ b/packages/rs-drive/Cargo.toml @@ -51,12 +51,12 @@ enum-map = { version = "2.0.3", optional = true } intmap = { version = "2.0.0", features = ["serde"], optional = true } chrono = { version = "0.4.35", optional = true } itertools = { version = "0.11.0", optional = true } -grovedb = { version = "2.0.3", optional = true, default-features = false } -grovedb-costs = { version = "2.0.3", optional = true } -grovedb-path = { version = "2.0.3" } -grovedb-storage = { version = "2.0.3", optional = true } -grovedb-version = { version = "2.0.3"} -grovedb-epoch-based-storage-flags = { version = "2.0.3"} +grovedb = { version = "2.1.0", optional = true, default-features = false } +grovedb-costs = { version = "2.1.0", optional = true } +grovedb-path = { version = "2.1.0" } +grovedb-storage = { version = "2.1.0", optional = true } +grovedb-version = { version = "2.1.0"} +grovedb-epoch-based-storage-flags = { version = "2.1.0"} [dev-dependencies] criterion = "0.3.5" diff --git a/packages/rs-drive/src/util/grove_operations/grove_insert_if_not_exists_return_existing_element/mod.rs b/packages/rs-drive/src/util/grove_operations/grove_insert_if_not_exists_return_existing_element/mod.rs index 8c5455a038..6727b72014 100644 --- a/packages/rs-drive/src/util/grove_operations/grove_insert_if_not_exists_return_existing_element/mod.rs +++ b/packages/rs-drive/src/util/grove_operations/grove_insert_if_not_exists_return_existing_element/mod.rs @@ -1,54 +1,53 @@ -//todo: uncomment once version 2.1 of GroveDB is released. -// mod v0; -// -// use crate::drive::Drive; -// use crate::error::drive::DriveError; -// use crate::error::Error; -// use crate::fees::op::LowLevelDriveOperation; -// use dpp::version::drive_versions::DriveVersion; -// use grovedb::{Element, TransactionArg}; -// use grovedb_path::SubtreePath; -// -// impl Drive { -// /// Inserts an element into groveDB only if the specified path and key do not exist. -// /// This operation costs are then stored in `drive_operations`. -// /// -// /// # Parameters -// /// * `path`: The groveDB hierarchical authenticated structure path where the new element is to be inserted. -// /// * `key`: The key where the new element should be inserted in the subtree. -// /// * `element`: The element to be inserted. -// /// * `transaction`: The groveDB transaction associated with this operation. -// /// * `drive_operations`: A vector to collect the costs of operations for later computation. In this case, -// /// it collects the cost of this insert operation if the path and key did not exist. -// /// * `platform_version`: The platform version to select the correct function version to run. -// /// -// /// # Returns -// /// * `Ok(true)` if the insertion was successful. -// /// * `Ok(false)` if the path and key already existed. -// /// * `Err(DriveError::UnknownVersionMismatch)` if the platform version does not match known versions. -// pub fn grove_insert_if_not_exists_return_existing_element>( -// &self, -// path: SubtreePath<'_, B>, -// key: &[u8], -// element: Element, -// transaction: TransactionArg, -// drive_operations: Option<&mut Vec>, -// drive_version: &DriveVersion, -// ) -> Result, Error> { -// match drive_version.grove_methods.basic.grove_insert_if_not_exists { -// 0 => self.grove_insert_if_not_exists_return_existing_element_v0( -// path, -// key, -// element, -// transaction, -// drive_operations, -// drive_version, -// ), -// version => Err(Error::Drive(DriveError::UnknownVersionMismatch { -// method: "grove_insert_if_not_exists_return_existing_element".to_string(), -// known_versions: vec![0], -// received: version, -// })), -// } -// } -// } +mod v0; + +use crate::drive::Drive; +use crate::error::drive::DriveError; +use crate::error::Error; +use crate::fees::op::LowLevelDriveOperation; +use dpp::version::drive_versions::DriveVersion; +use grovedb::{Element, TransactionArg}; +use grovedb_path::SubtreePath; + +impl Drive { + /// Inserts an element into groveDB only if the specified path and key do not exist. + /// This operation costs are then stored in `drive_operations`. + /// + /// # Parameters + /// * `path`: The groveDB hierarchical authenticated structure path where the new element is to be inserted. + /// * `key`: The key where the new element should be inserted in the subtree. + /// * `element`: The element to be inserted. + /// * `transaction`: The groveDB transaction associated with this operation. + /// * `drive_operations`: A vector to collect the costs of operations for later computation. In this case, + /// it collects the cost of this insert operation if the path and key did not exist. + /// * `platform_version`: The platform version to select the correct function version to run. + /// + /// # Returns + /// * `Ok(true)` if the insertion was successful. + /// * `Ok(false)` if the path and key already existed. + /// * `Err(DriveError::UnknownVersionMismatch)` if the platform version does not match known versions. + pub fn grove_insert_if_not_exists_return_existing_element>( + &self, + path: SubtreePath<'_, B>, + key: &[u8], + element: Element, + transaction: TransactionArg, + drive_operations: Option<&mut Vec>, + drive_version: &DriveVersion, + ) -> Result, Error> { + match drive_version.grove_methods.basic.grove_insert_if_not_exists { + 0 => self.grove_insert_if_not_exists_return_existing_element_v0( + path, + key, + element, + transaction, + drive_operations, + drive_version, + ), + version => Err(Error::Drive(DriveError::UnknownVersionMismatch { + method: "grove_insert_if_not_exists_return_existing_element".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive/src/util/grove_operations/grove_insert_if_not_exists_return_existing_element/v0/mod.rs b/packages/rs-drive/src/util/grove_operations/grove_insert_if_not_exists_return_existing_element/v0/mod.rs index 5030cd6cc5..69b55ba2d7 100644 --- a/packages/rs-drive/src/util/grove_operations/grove_insert_if_not_exists_return_existing_element/v0/mod.rs +++ b/packages/rs-drive/src/util/grove_operations/grove_insert_if_not_exists_return_existing_element/v0/mod.rs @@ -1,30 +1,30 @@ -// use crate::drive::Drive; -// use crate::error::Error; -// use crate::fees::op::LowLevelDriveOperation; -// use crate::util::grove_operations::push_drive_operation_result_optional; -// use grovedb::{Element, TransactionArg}; -// use grovedb_path::SubtreePath; -// use platform_version::version::drive_versions::DriveVersion; -// -// impl Drive { -// /// Pushes the `OperationCost` of inserting an element in groveDB where the path key does not yet exist -// /// to `drive_operations`. -// pub(crate) fn grove_insert_if_not_exists_return_existing_element_v0>( -// &self, -// path: SubtreePath<'_, B>, -// key: &[u8], -// element: Element, -// transaction: TransactionArg, -// drive_operations: Option<&mut Vec>, -// drive_version: &DriveVersion, -// ) -> Result { -// let cost_context = self.grove.insert_if_not_exists_return_existing_element( -// path, -// key, -// element, -// transaction, -// &drive_version.grove_version, -// ); -// push_drive_operation_result_optional(cost_context, drive_operations) -// } -// } +use crate::drive::Drive; +use crate::error::Error; +use crate::fees::op::LowLevelDriveOperation; +use crate::util::grove_operations::push_drive_operation_result_optional; +use grovedb::{Element, TransactionArg}; +use grovedb_path::SubtreePath; +use platform_version::version::drive_versions::DriveVersion; + +impl Drive { + /// Pushes the `OperationCost` of inserting an element in groveDB where the path key does not yet exist + /// to `drive_operations`. + pub(crate) fn grove_insert_if_not_exists_return_existing_element_v0>( + &self, + path: SubtreePath<'_, B>, + key: &[u8], + element: Element, + transaction: TransactionArg, + drive_operations: Option<&mut Vec>, + drive_version: &DriveVersion, + ) -> Result, Error> { + let cost_context = self.grove.insert_if_not_exists_return_existing_element( + path, + key, + element, + transaction, + &drive_version.grove_version, + ); + push_drive_operation_result_optional(cost_context, drive_operations) + } +} diff --git a/packages/rs-platform-version/Cargo.toml b/packages/rs-platform-version/Cargo.toml index 01b8e5380a..546704554d 100644 --- a/packages/rs-platform-version/Cargo.toml +++ b/packages/rs-platform-version/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT" thiserror = { version = "1.0.63" } bincode = { version = "2.0.0-rc.3"} versioned-feature-core = { git = "https://github.com/dashpay/versioned-feature-core", version = "1.0.0" } -grovedb-version = { version = "2.0.3"} +grovedb-version = { version = "2.1.0"} once_cell = "1.19.0" [features] diff --git a/packages/rs-platform-version/src/version/dpp_versions.rs b/packages/rs-platform-version/src/version/dpp_versions.rs index 7c84e660a4..713f9dc54a 100644 --- a/packages/rs-platform-version/src/version/dpp_versions.rs +++ b/packages/rs-platform-version/src/version/dpp_versions.rs @@ -27,6 +27,12 @@ pub struct StateTransitionVersions { pub struct IdentityTransitionVersions { pub max_public_keys_in_creation: u16, pub asset_locks: IdentityTransitionAssetLockVersions, + pub credit_withdrawal: IdentityCreditWithdrawalTransitionVersions, +} + +#[derive(Clone, Debug, Default)] +pub struct IdentityCreditWithdrawalTransitionVersions { + pub default_constructor: FeatureVersion, } #[derive(Clone, Debug, Default)] diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index 1869831859..28db2e2a7b 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -7,8 +7,9 @@ use crate::version::dpp_versions::{ DocumentTypeClassMethodVersions, DocumentTypeIndexVersions, DocumentTypeMethodVersions, DocumentTypeSchemaVersions, DocumentTypeValidationVersions, DocumentTypeVersions, DocumentVersions, DocumentsBatchTransitionValidationVersions, DocumentsBatchTransitionVersions, - IdentityKeyTypeMethodVersions, IdentityTransitionAssetLockVersions, IdentityTransitionVersions, - IdentityVersions, JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, + IdentityCreditWithdrawalTransitionVersions, IdentityKeyTypeMethodVersions, + IdentityTransitionAssetLockVersions, IdentityTransitionVersions, IdentityVersions, + JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, RecursiveSchemaValidatorVersions, StateTransitionConversionVersions, StateTransitionMethodVersions, StateTransitionSerializationVersions, StateTransitionVersions, VotingValidationVersions, VotingVersions, @@ -1183,6 +1184,9 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { validate_asset_lock_transaction_structure: 0, validate_instant_asset_lock_proof_structure: 0, }, + credit_withdrawal: IdentityCreditWithdrawalTransitionVersions { + default_constructor: 0, + }, }, }, contract_versions: ContractVersions { diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index 9fef855e85..aab569b63e 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -7,8 +7,9 @@ use crate::version::dpp_versions::{ DocumentTypeClassMethodVersions, DocumentTypeIndexVersions, DocumentTypeMethodVersions, DocumentTypeSchemaVersions, DocumentTypeValidationVersions, DocumentTypeVersions, DocumentVersions, DocumentsBatchTransitionValidationVersions, DocumentsBatchTransitionVersions, - IdentityKeyTypeMethodVersions, IdentityTransitionAssetLockVersions, IdentityTransitionVersions, - IdentityVersions, JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, + IdentityCreditWithdrawalTransitionVersions, IdentityKeyTypeMethodVersions, + IdentityTransitionAssetLockVersions, IdentityTransitionVersions, IdentityVersions, + JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, RecursiveSchemaValidatorVersions, StateTransitionConversionVersions, StateTransitionMethodVersions, StateTransitionSerializationVersions, StateTransitionVersions, VotingValidationVersions, VotingVersions, @@ -1183,6 +1184,9 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { validate_asset_lock_transaction_structure: 0, validate_instant_asset_lock_proof_structure: 0, }, + credit_withdrawal: IdentityCreditWithdrawalTransitionVersions { + default_constructor: 0, + }, }, }, contract_versions: ContractVersions { diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index 38200b9a61..8104775a5e 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -7,8 +7,9 @@ use crate::version::dpp_versions::{ DocumentTypeClassMethodVersions, DocumentTypeIndexVersions, DocumentTypeMethodVersions, DocumentTypeSchemaVersions, DocumentTypeValidationVersions, DocumentTypeVersions, DocumentVersions, DocumentsBatchTransitionValidationVersions, DocumentsBatchTransitionVersions, - IdentityKeyTypeMethodVersions, IdentityTransitionAssetLockVersions, IdentityTransitionVersions, - IdentityVersions, JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, + IdentityCreditWithdrawalTransitionVersions, IdentityKeyTypeMethodVersions, + IdentityTransitionAssetLockVersions, IdentityTransitionVersions, IdentityVersions, + JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, RecursiveSchemaValidatorVersions, StateTransitionConversionVersions, StateTransitionMethodVersions, StateTransitionSerializationVersions, StateTransitionVersions, VotingValidationVersions, VotingVersions, @@ -1182,6 +1183,9 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { validate_asset_lock_transaction_structure: 0, validate_instant_asset_lock_proof_structure: 0, }, + credit_withdrawal: IdentityCreditWithdrawalTransitionVersions { + default_constructor: 0, + }, }, }, contract_versions: ContractVersions { diff --git a/packages/rs-platform-version/src/version/v2.rs b/packages/rs-platform-version/src/version/v2.rs index 591e17d0c4..3f9931df8a 100644 --- a/packages/rs-platform-version/src/version/v2.rs +++ b/packages/rs-platform-version/src/version/v2.rs @@ -7,8 +7,9 @@ use crate::version::dpp_versions::{ DocumentTypeClassMethodVersions, DocumentTypeIndexVersions, DocumentTypeMethodVersions, DocumentTypeSchemaVersions, DocumentTypeValidationVersions, DocumentTypeVersions, DocumentVersions, DocumentsBatchTransitionValidationVersions, DocumentsBatchTransitionVersions, - IdentityKeyTypeMethodVersions, IdentityTransitionAssetLockVersions, IdentityTransitionVersions, - IdentityVersions, JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, + IdentityCreditWithdrawalTransitionVersions, IdentityKeyTypeMethodVersions, + IdentityTransitionAssetLockVersions, IdentityTransitionVersions, IdentityVersions, + JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, RecursiveSchemaValidatorVersions, StateTransitionConversionVersions, StateTransitionMethodVersions, StateTransitionSerializationVersions, StateTransitionVersions, VotingValidationVersions, VotingVersions, @@ -1182,6 +1183,9 @@ pub const PLATFORM_V2: PlatformVersion = PlatformVersion { validate_asset_lock_transaction_structure: 0, validate_instant_asset_lock_proof_structure: 0, }, + credit_withdrawal: IdentityCreditWithdrawalTransitionVersions { + default_constructor: 0, + }, }, }, contract_versions: ContractVersions { diff --git a/packages/rs-platform-version/src/version/v3.rs b/packages/rs-platform-version/src/version/v3.rs index 543c759df7..8a57cb65a6 100644 --- a/packages/rs-platform-version/src/version/v3.rs +++ b/packages/rs-platform-version/src/version/v3.rs @@ -7,8 +7,9 @@ use crate::version::dpp_versions::{ DocumentTypeClassMethodVersions, DocumentTypeIndexVersions, DocumentTypeMethodVersions, DocumentTypeSchemaVersions, DocumentTypeValidationVersions, DocumentTypeVersions, DocumentVersions, DocumentsBatchTransitionValidationVersions, DocumentsBatchTransitionVersions, - IdentityKeyTypeMethodVersions, IdentityTransitionAssetLockVersions, IdentityTransitionVersions, - IdentityVersions, JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, + IdentityCreditWithdrawalTransitionVersions, IdentityKeyTypeMethodVersions, + IdentityTransitionAssetLockVersions, IdentityTransitionVersions, IdentityVersions, + JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, RecursiveSchemaValidatorVersions, StateTransitionConversionVersions, StateTransitionMethodVersions, StateTransitionSerializationVersions, StateTransitionVersions, VotingValidationVersions, VotingVersions, @@ -1189,6 +1190,9 @@ pub const PLATFORM_V3: PlatformVersion = PlatformVersion { validate_asset_lock_transaction_structure: 0, validate_instant_asset_lock_proof_structure: 0, }, + credit_withdrawal: IdentityCreditWithdrawalTransitionVersions { + default_constructor: 1, + }, }, }, contract_versions: ContractVersions { diff --git a/packages/rs-platform-version/src/version/v4.rs b/packages/rs-platform-version/src/version/v4.rs index 7c2752f29a..0082ec2743 100644 --- a/packages/rs-platform-version/src/version/v4.rs +++ b/packages/rs-platform-version/src/version/v4.rs @@ -7,8 +7,9 @@ use crate::version::dpp_versions::{ DocumentTypeClassMethodVersions, DocumentTypeIndexVersions, DocumentTypeMethodVersions, DocumentTypeSchemaVersions, DocumentTypeValidationVersions, DocumentTypeVersions, DocumentVersions, DocumentsBatchTransitionValidationVersions, DocumentsBatchTransitionVersions, - IdentityKeyTypeMethodVersions, IdentityTransitionAssetLockVersions, IdentityTransitionVersions, - IdentityVersions, JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, + IdentityCreditWithdrawalTransitionVersions, IdentityKeyTypeMethodVersions, + IdentityTransitionAssetLockVersions, IdentityTransitionVersions, IdentityVersions, + JsonSchemaValidatorVersions, PublicKeyInCreationMethodVersions, RecursiveSchemaValidatorVersions, StateTransitionConversionVersions, StateTransitionMethodVersions, StateTransitionSerializationVersions, StateTransitionVersions, VotingValidationVersions, VotingVersions, @@ -1184,6 +1185,9 @@ pub const PLATFORM_V4: PlatformVersion = PlatformVersion { validate_asset_lock_transaction_structure: 0, validate_instant_asset_lock_proof_structure: 0, }, + credit_withdrawal: IdentityCreditWithdrawalTransitionVersions { + default_constructor: 1, + }, }, }, contract_versions: ContractVersions { diff --git a/packages/wasm-dpp/lib/test/fixtures/getIdentityCreditWithdrawalTransitionFixture.js b/packages/wasm-dpp/lib/test/fixtures/getIdentityCreditWithdrawalTransitionFixture.js index 892acc55c1..2bc8478f3b 100644 --- a/packages/wasm-dpp/lib/test/fixtures/getIdentityCreditWithdrawalTransitionFixture.js +++ b/packages/wasm-dpp/lib/test/fixtures/getIdentityCreditWithdrawalTransitionFixture.js @@ -6,7 +6,7 @@ module.exports = function getIdentityCreditWithdrawalTransitionFixture() { const privateKey = new PrivateKey('cSBnVM4xvxarwGQuAfQFwqDg9k5tErHUHzgWsEfD4zdwUasvqRVY'); const address = privateKey.toAddress(); - const stateTransition = new IdentityCreditWithdrawalTransition(1); + const stateTransition = new IdentityCreditWithdrawalTransition(3); stateTransition.setIdentityId(generateRandomIdentifier()); // eslint-disable-next-line stateTransition.setAmount(BigInt(1000)); diff --git a/packages/wasm-dpp/src/identity/identity_facade.rs b/packages/wasm-dpp/src/identity/identity_facade.rs index d14892d4f9..bd4db7d491 100644 --- a/packages/wasm-dpp/src/identity/identity_facade.rs +++ b/packages/wasm-dpp/src/identity/identity_facade.rs @@ -206,7 +206,7 @@ impl IdentityFacadeWasm { amount: u64, core_fee_per_byte: u32, pooling: u8, - output_script: Vec, + output_script: Option>, identity_nonce: u64, ) -> Result { let pooling = match pooling { @@ -222,7 +222,7 @@ impl IdentityFacadeWasm { amount, core_fee_per_byte, pooling, - CoreScript::from_bytes(output_script), + output_script.map(CoreScript::from_bytes), identity_nonce as IdentityNonce, ) .map(Into::into) diff --git a/packages/wasm-dpp/src/identity/identity_factory.rs b/packages/wasm-dpp/src/identity/identity_factory.rs index b4fcf35d55..799598b456 100644 --- a/packages/wasm-dpp/src/identity/identity_factory.rs +++ b/packages/wasm-dpp/src/identity/identity_factory.rs @@ -210,7 +210,7 @@ impl IdentityFactoryWasm { amount: u64, core_fee_per_byte: u32, pooling: u8, - output_script: Vec, + output_script: Option>, identity_nonce: u64, ) -> Result { let pooling = match pooling { @@ -226,7 +226,7 @@ impl IdentityFactoryWasm { amount, core_fee_per_byte, pooling, - CoreScript::from_bytes(output_script), + output_script.map(CoreScript::from_bytes), identity_nonce as IdentityNonce, ) .map(Into::into) diff --git a/packages/wasm-dpp/test/integration/identity/IdentityFacade.spec.js b/packages/wasm-dpp/test/integration/identity/IdentityFacade.spec.js index 90778aa72e..2ed05d3bcb 100644 --- a/packages/wasm-dpp/test/integration/identity/IdentityFacade.spec.js +++ b/packages/wasm-dpp/test/integration/identity/IdentityFacade.spec.js @@ -24,7 +24,7 @@ describe('IdentityFacade', () => { beforeEach(async () => { dpp = new DashPlatformProtocol( { generate: () => crypto.randomBytes(32) }, - 1, + 3, ); const chainAssetLockProofJS = getChainAssetLockProofFixture(); diff --git a/packages/wasm-dpp/test/unit/identity/IdentityFactory.spec.js b/packages/wasm-dpp/test/unit/identity/IdentityFactory.spec.js index 25c23be0c9..1cd8fc8469 100644 --- a/packages/wasm-dpp/test/unit/identity/IdentityFactory.spec.js +++ b/packages/wasm-dpp/test/unit/identity/IdentityFactory.spec.js @@ -26,7 +26,7 @@ describe('IdentityFactory', () => { // const identityValidator = new IdentityValidator(blsAdapter); - factory = new IdentityFactory(1); + factory = new IdentityFactory(3); identity = await getIdentityFixture(instantAssetLockProof.createIdentifier()); identity.setBalance(0); diff --git a/packages/wasm-dpp/test/unit/identity/stateTransition/IdentityCreditWithdrawalTransition/IdentityCreditWithdrawalTransition.spec.js b/packages/wasm-dpp/test/unit/identity/stateTransition/IdentityCreditWithdrawalTransition/IdentityCreditWithdrawalTransition.spec.js index b80c611116..503ecf4bef 100644 --- a/packages/wasm-dpp/test/unit/identity/stateTransition/IdentityCreditWithdrawalTransition/IdentityCreditWithdrawalTransition.spec.js +++ b/packages/wasm-dpp/test/unit/identity/stateTransition/IdentityCreditWithdrawalTransition/IdentityCreditWithdrawalTransition.spec.js @@ -75,7 +75,7 @@ describe('IdentityCreditWithdrawalTransition', () => { rawStateTransition = stateTransition.toObject(); expect(rawStateTransition).to.deep.equal({ - $version: '0', + $version: '1', type: StateTransitionTypes.IdentityCreditWithdrawal, identityId: stateTransition.getIdentityId().toBuffer(), amount: stateTransition.getAmount(), @@ -92,7 +92,7 @@ describe('IdentityCreditWithdrawalTransition', () => { rawStateTransition = stateTransition.toObject({ skipSignature: true }); expect(rawStateTransition).to.deep.equal({ - $version: '0', + $version: '1', type: StateTransitionTypes.IdentityCreditWithdrawal, identityId: stateTransition.getIdentityId().toBuffer(), amount: stateTransition.getAmount(), @@ -109,7 +109,7 @@ describe('IdentityCreditWithdrawalTransition', () => { const jsonStateTransition = stateTransition.toJSON(); expect(jsonStateTransition).to.deep.equal({ - $version: '0', + $version: '1', type: StateTransitionTypes.IdentityCreditWithdrawal, identityId: stateTransition.getIdentityId().toString(), amount: stateTransition.getAmount().toString(),