diff --git a/packages/rs-sdk/src/platform.rs b/packages/rs-sdk/src/platform.rs index a5141f22060..233242abd09 100644 --- a/packages/rs-sdk/src/platform.rs +++ b/packages/rs-sdk/src/platform.rs @@ -7,7 +7,6 @@ pub mod block_info_from_metadata; mod delegate; -mod document_query; mod fetch; pub mod fetch_current_no_parameters; mod fetch_many; @@ -17,10 +16,12 @@ pub mod query; pub mod transition; pub mod types; +pub mod documents; pub mod group_actions; pub mod tokens; -pub use dapi_grpc::platform::v0::{self as proto}; +pub use dapi_grpc::platform::v0 as proto; +pub use documents::document_query::DocumentQuery; pub use dpp::{ self as dpp, document::Document, @@ -32,7 +33,6 @@ pub use drive_proof_verifier::ContextProvider; pub use drive_proof_verifier::MockContextProvider; pub use rs_dapi_client as dapi; pub use { - document_query::DocumentQuery, fetch::Fetch, fetch_many::FetchMany, fetch_unproved::FetchUnproved, diff --git a/packages/rs-sdk/src/platform/document_query.rs b/packages/rs-sdk/src/platform/documents/document_query.rs similarity index 99% rename from packages/rs-sdk/src/platform/document_query.rs rename to packages/rs-sdk/src/platform/documents/document_query.rs index 39ec37d736a..491d0cdf3b6 100644 --- a/packages/rs-sdk/src/platform/document_query.rs +++ b/packages/rs-sdk/src/platform/documents/document_query.rs @@ -27,7 +27,7 @@ use rs_dapi_client::transport::{ AppliedRequestSettings, BoxFuture, TransportError, TransportRequest, }; -use super::fetch::Fetch; +use crate::platform::Fetch; // TODO: remove DocumentQuery once ContextProvider that provides data contracts is merged. diff --git a/packages/rs-sdk/src/platform/documents/mod.rs b/packages/rs-sdk/src/platform/documents/mod.rs new file mode 100644 index 00000000000..94f890f14a0 --- /dev/null +++ b/packages/rs-sdk/src/platform/documents/mod.rs @@ -0,0 +1,2 @@ +pub mod document_query; +pub mod transitions; diff --git a/packages/rs-sdk/src/platform/documents/transitions/create.rs b/packages/rs-sdk/src/platform/documents/transitions/create.rs new file mode 100644 index 00000000000..8c38cc45496 --- /dev/null +++ b/packages/rs-sdk/src/platform/documents/transitions/create.rs @@ -0,0 +1,244 @@ +use crate::platform::transition::broadcast::BroadcastStateTransition; +use crate::platform::transition::put_settings::PutSettings; +use crate::{Error, Sdk}; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::data_contract::DataContract; +use dpp::document::{Document, DocumentV0Getters}; +use dpp::identity::signer::Signer; +use dpp::identity::IdentityPublicKey; +use dpp::prelude::UserFeeIncrease; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::batch_transition::methods::StateTransitionCreationOptions; +use dpp::state_transition::batch_transition::BatchTransition; +use dpp::state_transition::proof_result::StateTransitionProofResult; +use dpp::state_transition::StateTransition; +use dpp::tokens::token_payment_info::TokenPaymentInfo; +use dpp::version::PlatformVersion; +use std::sync::Arc; + +/// A builder to configure and broadcast document create transitions +pub struct DocumentCreateTransitionBuilder { + pub data_contract: Arc, + pub document_type_name: String, + pub document: Document, + pub document_state_transition_entropy: [u8; 32], + pub token_payment_info: Option, + pub settings: Option, + pub user_fee_increase: Option, + pub state_transition_creation_options: Option, +} + +impl DocumentCreateTransitionBuilder { + /// Start building a create document request for the provided DataContract. + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type to create + /// * `document` - The document to create + /// * `document_state_transition_entropy` - Entropy for the state transition + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn new( + data_contract: Arc, + document_type_name: String, + document: Document, + document_state_transition_entropy: [u8; 32], + ) -> Self { + Self { + data_contract, + document_type_name, + document, + document_state_transition_entropy, + token_payment_info: None, + settings: None, + user_fee_increase: None, + state_transition_creation_options: None, + } + } + + /// Adds token payment info to the document create transition + /// + /// # Arguments + /// + /// * `token_payment_info` - The token payment info to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_token_payment_info(mut self, token_payment_info: TokenPaymentInfo) -> Self { + self.token_payment_info = Some(token_payment_info); + self + } + + /// Adds a user fee increase to the document create transition + /// + /// # Arguments + /// + /// * `user_fee_increase` - The user fee increase to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_user_fee_increase(mut self, user_fee_increase: UserFeeIncrease) -> Self { + self.user_fee_increase = Some(user_fee_increase); + self + } + + /// Adds settings to the document create transition + /// + /// # Arguments + /// + /// * `settings` - The settings to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_settings(mut self, settings: PutSettings) -> Self { + self.settings = Some(settings); + self + } + + /// Adds creation_options to the document create transition + /// + /// # Arguments + /// + /// * `settings` - The settings to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_state_transition_creation_options( + mut self, + creation_options: StateTransitionCreationOptions, + ) -> Self { + self.state_transition_creation_options = Some(creation_options); + self + } + + /// Signs the document create transition + /// + /// # Arguments + /// + /// * `sdk` - The SDK instance + /// * `identity_public_key` - The public key of the identity + /// * `signer` - The signer instance + /// * `platform_version` - The platform version + /// * `options` - Optional state transition creation options + /// + /// # Returns + /// + /// * `Result` - The signed state transition or an error + pub async fn sign( + &self, + sdk: &Sdk, + identity_public_key: &IdentityPublicKey, + signer: &impl Signer, + platform_version: &PlatformVersion, + ) -> Result { + let identity_contract_nonce = sdk + .get_identity_contract_nonce( + self.document.owner_id(), + self.data_contract.id(), + true, + self.settings, + ) + .await?; + + let document_type = self + .data_contract + .document_type_for_name(&self.document_type_name) + .map_err(|e| Error::Protocol(e.into()))?; + + let state_transition = BatchTransition::new_document_creation_transition_from_document( + self.document.clone(), + document_type, + self.document_state_transition_entropy, + identity_public_key, + identity_contract_nonce, + self.user_fee_increase.unwrap_or_default(), + self.token_payment_info, + signer, + platform_version, + self.state_transition_creation_options, + )?; + + Ok(state_transition) + } +} + +/// Result types returned from document creation operations. +#[derive(Debug)] +pub enum DocumentCreateResult { + /// Document creation result containing the created document. + Document(Document), +} + +impl Sdk { + /// Creates a new document on the platform. + /// + /// This method broadcasts a document creation transition to add a new document + /// to the specified data contract. The result contains the created document. + /// + /// # Arguments + /// + /// * `create_document_transition_builder` - Builder containing document creation parameters + /// * `signing_key` - The identity public key for signing the transition + /// * `signer` - Implementation of the Signer trait for cryptographic signing + /// + /// # Returns + /// + /// Returns a `Result` containing a `DocumentCreateResult` on success, or an `Error` on failure. + /// + /// # Errors + /// + /// This function will return an error if: + /// - The transition signing fails + /// - Broadcasting the transition fails + /// - The proof verification returns an unexpected result type + /// - Document validation fails + pub async fn document_create( + &self, + create_document_transition_builder: DocumentCreateTransitionBuilder, + signing_key: &IdentityPublicKey, + signer: &S, + ) -> Result { + let platform_version = self.version(); + + let put_settings = create_document_transition_builder.settings; + + let state_transition = create_document_transition_builder + .sign(self, signing_key, signer, platform_version) + .await?; + + let proof_result = state_transition + .broadcast_and_wait::(self, put_settings) + .await?; + + match proof_result { + StateTransitionProofResult::VerifiedDocuments(documents) => { + if let Some((_, Some(document))) = documents.into_iter().next() { + Ok(DocumentCreateResult::Document(document)) + } else { + Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected document in VerifiedDocuments result for create transition" + .to_string(), + ), + vec![], + Default::default(), + )) + } + } + _ => Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected VerifiedDocuments for document create transition".to_string(), + ), + vec![], + Default::default(), + )), + } + } +} diff --git a/packages/rs-sdk/src/platform/documents/transitions/delete.rs b/packages/rs-sdk/src/platform/documents/transitions/delete.rs new file mode 100644 index 00000000000..55ccf4d8371 --- /dev/null +++ b/packages/rs-sdk/src/platform/documents/transitions/delete.rs @@ -0,0 +1,286 @@ +use crate::platform::transition::broadcast::BroadcastStateTransition; +use crate::platform::transition::put_settings::PutSettings; +use crate::platform::Identifier; +use crate::{Error, Sdk}; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::data_contract::DataContract; +use dpp::document::{Document, INITIAL_REVISION}; +use dpp::identity::signer::Signer; +use dpp::identity::IdentityPublicKey; +use dpp::prelude::UserFeeIncrease; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::batch_transition::methods::StateTransitionCreationOptions; +use dpp::state_transition::batch_transition::BatchTransition; +use dpp::state_transition::proof_result::StateTransitionProofResult; +use dpp::state_transition::StateTransition; +use dpp::tokens::token_payment_info::TokenPaymentInfo; +use dpp::version::PlatformVersion; +use std::sync::Arc; + +/// A builder to configure and broadcast document delete transitions +pub struct DocumentDeleteTransitionBuilder { + pub data_contract: Arc, + pub document_type_name: String, + pub document_id: Identifier, + pub owner_id: Identifier, + pub token_payment_info: Option, + pub settings: Option, + pub user_fee_increase: Option, + pub state_transition_creation_options: Option, +} + +impl DocumentDeleteTransitionBuilder { + /// Start building a delete document request for the provided DataContract. + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type to delete + /// * `document_id` - The ID of the document to delete + /// * `owner_id` - The owner ID of the document + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn new( + data_contract: Arc, + document_type_name: String, + document_id: Identifier, + owner_id: Identifier, + ) -> Self { + Self { + data_contract, + document_type_name, + document_id, + owner_id, + token_payment_info: None, + settings: None, + user_fee_increase: None, + state_transition_creation_options: None, + } + } + + /// Creates a new builder from an existing document + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type to delete + /// * `document` - The document to delete + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn from_document( + data_contract: Arc, + document_type_name: String, + document: &Document, + ) -> Self { + use dpp::document::DocumentV0Getters; + Self::new( + data_contract, + document_type_name, + document.id(), + document.owner_id(), + ) + } + + /// Adds token payment info to the document delete transition + /// + /// # Arguments + /// + /// * `token_payment_info` - The token payment info to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_token_payment_info(mut self, token_payment_info: TokenPaymentInfo) -> Self { + self.token_payment_info = Some(token_payment_info); + self + } + + /// Adds a user fee increase to the document delete transition + /// + /// # Arguments + /// + /// * `user_fee_increase` - The user fee increase to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_user_fee_increase(mut self, user_fee_increase: UserFeeIncrease) -> Self { + self.user_fee_increase = Some(user_fee_increase); + self + } + + /// Adds settings to the document delete transition + /// + /// # Arguments + /// + /// * `settings` - The settings to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_settings(mut self, settings: PutSettings) -> Self { + self.settings = Some(settings); + self + } + + /// Adds creation_options to the document delete transition + /// + /// # Arguments + /// + /// * `creation_options` - The creation options to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_state_transition_creation_options( + mut self, + creation_options: StateTransitionCreationOptions, + ) -> Self { + self.state_transition_creation_options = Some(creation_options); + self + } + + /// Signs the document delete transition + /// + /// # Arguments + /// + /// * `sdk` - The SDK instance + /// * `identity_public_key` - The public key of the identity + /// * `signer` - The signer instance + /// * `platform_version` - The platform version + /// + /// # Returns + /// + /// * `Result` - The signed state transition or an error + pub async fn sign( + &self, + sdk: &Sdk, + identity_public_key: &IdentityPublicKey, + signer: &impl Signer, + platform_version: &PlatformVersion, + ) -> Result { + let identity_contract_nonce = sdk + .get_identity_contract_nonce( + self.owner_id, + self.data_contract.id(), + true, + self.settings, + ) + .await?; + + let document_type = self + .data_contract + .document_type_for_name(&self.document_type_name) + .map_err(|e| Error::Protocol(e.into()))?; + + // Create a minimal document for deletion + let document = Document::V0(dpp::document::DocumentV0 { + id: self.document_id, + owner_id: self.owner_id, + properties: Default::default(), + revision: Some(INITIAL_REVISION), + created_at: None, + updated_at: None, + transferred_at: None, + created_at_block_height: None, + updated_at_block_height: None, + transferred_at_block_height: None, + created_at_core_block_height: None, + updated_at_core_block_height: None, + transferred_at_core_block_height: None, + }); + + let state_transition = BatchTransition::new_document_deletion_transition_from_document( + document, + document_type, + identity_public_key, + identity_contract_nonce, + self.user_fee_increase.unwrap_or_default(), + self.token_payment_info, + signer, + platform_version, + self.state_transition_creation_options, + )?; + + Ok(state_transition) + } +} + +/// Result types returned from document delete operations. +#[derive(Debug)] +pub enum DocumentDeleteResult { + /// Document deletion confirmed (document no longer exists). + Deleted(Identifier), +} + +impl Sdk { + /// Deletes an existing document from the platform. + /// + /// This method broadcasts a document deletion transition to permanently remove + /// a document from the platform. The result confirms the deletion. + /// + /// # Arguments + /// + /// * `delete_document_transition_builder` - Builder containing document deletion parameters + /// * `signing_key` - The identity public key for signing the transition + /// * `signer` - Implementation of the Signer trait for cryptographic signing + /// + /// # Returns + /// + /// Returns a `Result` containing a `DocumentDeleteResult` on success, or an `Error` on failure. + /// + /// # Errors + /// + /// This function will return an error if: + /// - The transition signing fails + /// - Broadcasting the transition fails + /// - The proof verification returns an unexpected result type + /// - Document not found or already deleted + /// - Insufficient permissions to delete the document + pub async fn document_delete( + &self, + delete_document_transition_builder: DocumentDeleteTransitionBuilder, + signing_key: &IdentityPublicKey, + signer: &S, + ) -> Result { + let platform_version = self.version(); + + let put_settings = delete_document_transition_builder.settings; + + let state_transition = delete_document_transition_builder + .sign(self, signing_key, signer, platform_version) + .await?; + + let proof_result = state_transition + .broadcast_and_wait::(self, put_settings) + .await?; + + match proof_result { + StateTransitionProofResult::VerifiedDocuments(documents) => { + if let Some((document_id, None)) = documents.into_iter().next() { + // None indicates the document has been deleted + Ok(DocumentDeleteResult::Deleted(document_id)) + } else { + Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected deleted document (None) in VerifiedDocuments result for delete transition".to_string(), + ), + vec![], + Default::default(), + )) + } + } + _ => Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected VerifiedDocuments for document delete transition".to_string(), + ), + vec![], + Default::default(), + )), + } + } +} diff --git a/packages/rs-sdk/src/platform/documents/transitions/mod.rs b/packages/rs-sdk/src/platform/documents/transitions/mod.rs new file mode 100644 index 00000000000..200a2164267 --- /dev/null +++ b/packages/rs-sdk/src/platform/documents/transitions/mod.rs @@ -0,0 +1,13 @@ +pub mod create; +pub mod delete; +pub mod purchase; +pub mod replace; +pub mod set_price; +pub mod transfer; + +pub use create::{DocumentCreateResult, DocumentCreateTransitionBuilder}; +pub use delete::{DocumentDeleteResult, DocumentDeleteTransitionBuilder}; +pub use purchase::{DocumentPurchaseResult, DocumentPurchaseTransitionBuilder}; +pub use replace::{DocumentReplaceResult, DocumentReplaceTransitionBuilder}; +pub use set_price::{DocumentSetPriceResult, DocumentSetPriceTransitionBuilder}; +pub use transfer::{DocumentTransferResult, DocumentTransferTransitionBuilder}; diff --git a/packages/rs-sdk/src/platform/documents/transitions/purchase.rs b/packages/rs-sdk/src/platform/documents/transitions/purchase.rs new file mode 100644 index 00000000000..83ec7117ed8 --- /dev/null +++ b/packages/rs-sdk/src/platform/documents/transitions/purchase.rs @@ -0,0 +1,303 @@ +use crate::platform::transition::broadcast::BroadcastStateTransition; +use crate::platform::transition::put_settings::PutSettings; +use crate::platform::Identifier; +use crate::{Error, Sdk}; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::data_contract::DataContract; +use dpp::document::Document; +use dpp::fee::Credits; +use dpp::identity::signer::Signer; +use dpp::identity::IdentityPublicKey; +use dpp::prelude::UserFeeIncrease; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::batch_transition::methods::StateTransitionCreationOptions; +use dpp::state_transition::batch_transition::BatchTransition; +use dpp::state_transition::proof_result::StateTransitionProofResult; +use dpp::state_transition::StateTransition; +use dpp::tokens::token_payment_info::TokenPaymentInfo; +use dpp::version::PlatformVersion; +use std::sync::Arc; + +/// A builder to configure and broadcast document purchase transitions +pub struct DocumentPurchaseTransitionBuilder { + pub data_contract: Arc, + pub document_type_name: String, + pub document: Document, + pub purchaser_id: Identifier, + pub price: Credits, + pub token_payment_info: Option, + pub settings: Option, + pub user_fee_increase: Option, + pub state_transition_creation_options: Option, +} + +impl DocumentPurchaseTransitionBuilder { + /// Start building a purchase document request for the provided DataContract. + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type + /// * `document` - The document to purchase + /// * `purchaser_id` - The identifier of the purchaser + /// * `price` - The price to pay for the document + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn new( + data_contract: Arc, + document_type_name: String, + document: Document, + purchaser_id: Identifier, + price: Credits, + ) -> Self { + Self { + data_contract, + document_type_name, + document, + purchaser_id, + price, + token_payment_info: None, + settings: None, + user_fee_increase: None, + state_transition_creation_options: None, + } + } + + /// Creates a new builder from document ID + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type + /// * `document_id` - The ID of the document + /// * `current_owner_id` - The current owner ID of the document + /// * `purchaser_id` - The identifier of the purchaser + /// * `price` - The price to pay for the document + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn from_document_info( + data_contract: Arc, + document_type_name: String, + document_id: Identifier, + current_owner_id: Identifier, + purchaser_id: Identifier, + price: Credits, + ) -> Self { + // Create a minimal document with just the required fields + // The actual document will be fetched during the transition + let document = Document::V0(dpp::document::DocumentV0 { + id: document_id, + owner_id: current_owner_id, + properties: Default::default(), + revision: Some(1), // Will be updated during transition + created_at: None, + updated_at: None, + transferred_at: None, + created_at_block_height: None, + updated_at_block_height: None, + transferred_at_block_height: None, + created_at_core_block_height: None, + updated_at_core_block_height: None, + transferred_at_core_block_height: None, + }); + + Self::new( + data_contract, + document_type_name, + document, + purchaser_id, + price, + ) + } + + /// Adds token payment info to the document purchase transition + /// + /// # Arguments + /// + /// * `token_payment_info` - The token payment info to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_token_payment_info(mut self, token_payment_info: TokenPaymentInfo) -> Self { + self.token_payment_info = Some(token_payment_info); + self + } + + /// Adds a user fee increase to the document purchase transition + /// + /// # Arguments + /// + /// * `user_fee_increase` - The user fee increase to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_user_fee_increase(mut self, user_fee_increase: UserFeeIncrease) -> Self { + self.user_fee_increase = Some(user_fee_increase); + self + } + + /// Adds settings to the document purchase transition + /// + /// # Arguments + /// + /// * `settings` - The settings to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_settings(mut self, settings: PutSettings) -> Self { + self.settings = Some(settings); + self + } + + /// Adds creation_options to the document purchase transition + /// + /// # Arguments + /// + /// * `creation_options` - The creation options to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_state_transition_creation_options( + mut self, + creation_options: StateTransitionCreationOptions, + ) -> Self { + self.state_transition_creation_options = Some(creation_options); + self + } + + /// Signs the document purchase transition + /// + /// # Arguments + /// + /// * `sdk` - The SDK instance + /// * `identity_public_key` - The public key of the identity + /// * `signer` - The signer instance + /// * `platform_version` - The platform version + /// + /// # Returns + /// + /// * `Result` - The signed state transition or an error + pub async fn sign( + &self, + sdk: &Sdk, + identity_public_key: &IdentityPublicKey, + signer: &impl Signer, + platform_version: &PlatformVersion, + ) -> Result { + let identity_contract_nonce = sdk + .get_identity_contract_nonce( + self.purchaser_id, + self.data_contract.id(), + true, + self.settings, + ) + .await?; + + let document_type = self + .data_contract + .document_type_for_name(&self.document_type_name) + .map_err(|e| Error::Protocol(e.into()))?; + + let state_transition = BatchTransition::new_document_purchase_transition_from_document( + self.document.clone(), + document_type, + self.purchaser_id, + self.price, + identity_public_key, + identity_contract_nonce, + self.user_fee_increase.unwrap_or_default(), + self.token_payment_info, + signer, + platform_version, + self.state_transition_creation_options, + )?; + + Ok(state_transition) + } +} + +/// Result types returned from document purchase operations. +#[derive(Debug)] +pub enum DocumentPurchaseResult { + /// Document purchased successfully, containing the document with new owner. + Document(Document), +} + +impl Sdk { + /// Purchases a document from its current owner. + /// + /// This method broadcasts a document purchase transition to buy a document + /// at its set price and transfer ownership to the purchaser. The result + /// contains the purchased document with updated ownership. + /// + /// # Arguments + /// + /// * `purchase_document_transition_builder` - Builder containing purchase parameters + /// * `signing_key` - The identity public key for signing the transition + /// * `signer` - Implementation of the Signer trait for cryptographic signing + /// + /// # Returns + /// + /// Returns a `Result` containing a `DocumentPurchaseResult` on success, or an `Error` on failure. + /// + /// # Errors + /// + /// This function will return an error if: + /// - The transition signing fails + /// - Broadcasting the transition fails + /// - The proof verification returns an unexpected result type + /// - Document not found or not for sale + /// - Insufficient funds to complete the purchase + /// - Price mismatch (document price changed) + /// - Invalid purchaser identity + pub async fn document_purchase( + &self, + purchase_document_transition_builder: DocumentPurchaseTransitionBuilder, + signing_key: &IdentityPublicKey, + signer: &S, + ) -> Result { + let platform_version = self.version(); + + let put_settings = purchase_document_transition_builder.settings; + + let state_transition = purchase_document_transition_builder + .sign(self, signing_key, signer, platform_version) + .await?; + + let proof_result = state_transition + .broadcast_and_wait::(self, put_settings) + .await?; + + match proof_result { + StateTransitionProofResult::VerifiedDocuments(documents) => { + if let Some((_, Some(document))) = documents.into_iter().next() { + Ok(DocumentPurchaseResult::Document(document)) + } else { + Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected document in VerifiedDocuments result for purchase transition" + .to_string(), + ), + vec![], + Default::default(), + )) + } + } + _ => Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected VerifiedDocuments for document purchase transition".to_string(), + ), + vec![], + Default::default(), + )), + } + } +} diff --git a/packages/rs-sdk/src/platform/documents/transitions/replace.rs b/packages/rs-sdk/src/platform/documents/transitions/replace.rs new file mode 100644 index 00000000000..097b305ddd0 --- /dev/null +++ b/packages/rs-sdk/src/platform/documents/transitions/replace.rs @@ -0,0 +1,239 @@ +use crate::platform::transition::broadcast::BroadcastStateTransition; +use crate::platform::transition::put_settings::PutSettings; +use crate::{Error, Sdk}; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::data_contract::DataContract; +use dpp::document::{Document, DocumentV0Getters}; +use dpp::identity::signer::Signer; +use dpp::identity::IdentityPublicKey; +use dpp::prelude::UserFeeIncrease; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::batch_transition::methods::StateTransitionCreationOptions; +use dpp::state_transition::batch_transition::BatchTransition; +use dpp::state_transition::proof_result::StateTransitionProofResult; +use dpp::state_transition::StateTransition; +use dpp::tokens::token_payment_info::TokenPaymentInfo; +use dpp::version::PlatformVersion; +use std::sync::Arc; + +/// A builder to configure and broadcast document replace transitions +pub struct DocumentReplaceTransitionBuilder { + pub data_contract: Arc, + pub document_type_name: String, + pub document: Document, + pub token_payment_info: Option, + pub settings: Option, + pub user_fee_increase: Option, + pub state_transition_creation_options: Option, +} + +impl DocumentReplaceTransitionBuilder { + /// Start building a replace document request for the provided DataContract. + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type to replace + /// * `document` - The document with updated values + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn new( + data_contract: Arc, + document_type_name: String, + document: Document, + ) -> Self { + Self { + data_contract, + document_type_name, + document, + token_payment_info: None, + settings: None, + user_fee_increase: None, + state_transition_creation_options: None, + } + } + + /// Adds token payment info to the document replace transition + /// + /// # Arguments + /// + /// * `token_payment_info` - The token payment info to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_token_payment_info(mut self, token_payment_info: TokenPaymentInfo) -> Self { + self.token_payment_info = Some(token_payment_info); + self + } + + /// Adds a user fee increase to the document replace transition + /// + /// # Arguments + /// + /// * `user_fee_increase` - The user fee increase to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_user_fee_increase(mut self, user_fee_increase: UserFeeIncrease) -> Self { + self.user_fee_increase = Some(user_fee_increase); + self + } + + /// Adds settings to the document replace transition + /// + /// # Arguments + /// + /// * `settings` - The settings to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_settings(mut self, settings: PutSettings) -> Self { + self.settings = Some(settings); + self + } + + /// Adds creation_options to the document replace transition + /// + /// # Arguments + /// + /// * `creation_options` - The creation options to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_state_transition_creation_options( + mut self, + creation_options: StateTransitionCreationOptions, + ) -> Self { + self.state_transition_creation_options = Some(creation_options); + self + } + + /// Signs the document replace transition + /// + /// # Arguments + /// + /// * `sdk` - The SDK instance + /// * `identity_public_key` - The public key of the identity + /// * `signer` - The signer instance + /// * `platform_version` - The platform version + /// + /// # Returns + /// + /// * `Result` - The signed state transition or an error + pub async fn sign( + &self, + sdk: &Sdk, + identity_public_key: &IdentityPublicKey, + signer: &impl Signer, + platform_version: &PlatformVersion, + ) -> Result { + let identity_contract_nonce = sdk + .get_identity_contract_nonce( + self.document.owner_id(), + self.data_contract.id(), + true, + self.settings, + ) + .await?; + + let document_type = self + .data_contract + .document_type_for_name(&self.document_type_name) + .map_err(|e| Error::Protocol(e.into()))?; + + let state_transition = BatchTransition::new_document_replacement_transition_from_document( + self.document.clone(), + document_type, + identity_public_key, + identity_contract_nonce, + self.user_fee_increase.unwrap_or_default(), + self.token_payment_info, + signer, + platform_version, + self.state_transition_creation_options, + )?; + + Ok(state_transition) + } +} + +/// Result types returned from document replace operations. +#[derive(Debug)] +pub enum DocumentReplaceResult { + /// Document replace result containing the updated document. + Document(Document), +} + +impl Sdk { + /// Replaces an existing document on the platform. + /// + /// This method broadcasts a document replacement transition to update an existing + /// document with new data. The result contains the updated document. + /// + /// # Arguments + /// + /// * `replace_document_transition_builder` - Builder containing document replacement parameters + /// * `signing_key` - The identity public key for signing the transition + /// * `signer` - Implementation of the Signer trait for cryptographic signing + /// + /// # Returns + /// + /// Returns a `Result` containing a `DocumentReplaceResult` on success, or an `Error` on failure. + /// + /// # Errors + /// + /// This function will return an error if: + /// - The transition signing fails + /// - Broadcasting the transition fails + /// - The proof verification returns an unexpected result type + /// - Document validation fails + /// - Document not found or revision mismatch + pub async fn document_replace( + &self, + replace_document_transition_builder: DocumentReplaceTransitionBuilder, + signing_key: &IdentityPublicKey, + signer: &S, + ) -> Result { + let platform_version = self.version(); + + let put_settings = replace_document_transition_builder.settings; + + let state_transition = replace_document_transition_builder + .sign(self, signing_key, signer, platform_version) + .await?; + + let proof_result = state_transition + .broadcast_and_wait::(self, put_settings) + .await?; + + match proof_result { + StateTransitionProofResult::VerifiedDocuments(documents) => { + if let Some((_, Some(document))) = documents.into_iter().next() { + Ok(DocumentReplaceResult::Document(document)) + } else { + Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected document in VerifiedDocuments result for replace transition" + .to_string(), + ), + vec![], + Default::default(), + )) + } + } + _ => Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected VerifiedDocuments for document replace transition".to_string(), + ), + vec![], + Default::default(), + )), + } + } +} diff --git a/packages/rs-sdk/src/platform/documents/transitions/set_price.rs b/packages/rs-sdk/src/platform/documents/transitions/set_price.rs new file mode 100644 index 00000000000..8b38a1ff24e --- /dev/null +++ b/packages/rs-sdk/src/platform/documents/transitions/set_price.rs @@ -0,0 +1,287 @@ +use crate::platform::transition::broadcast::BroadcastStateTransition; +use crate::platform::transition::put_settings::PutSettings; +use crate::platform::Identifier; +use crate::{Error, Sdk}; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::data_contract::DataContract; +use dpp::document::{Document, DocumentV0Getters}; +use dpp::fee::Credits; +use dpp::identity::signer::Signer; +use dpp::identity::IdentityPublicKey; +use dpp::prelude::UserFeeIncrease; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::batch_transition::methods::StateTransitionCreationOptions; +use dpp::state_transition::batch_transition::BatchTransition; +use dpp::state_transition::proof_result::StateTransitionProofResult; +use dpp::state_transition::StateTransition; +use dpp::tokens::token_payment_info::TokenPaymentInfo; +use dpp::version::PlatformVersion; +use std::sync::Arc; + +/// A builder to configure and broadcast document set price transitions +pub struct DocumentSetPriceTransitionBuilder { + pub data_contract: Arc, + pub document_type_name: String, + pub document: Document, + pub price: Credits, + pub token_payment_info: Option, + pub settings: Option, + pub user_fee_increase: Option, + pub state_transition_creation_options: Option, +} + +impl DocumentSetPriceTransitionBuilder { + /// Start building a set price document request for the provided DataContract. + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type + /// * `document` - The document to update price for + /// * `price` - The new price in credits + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn new( + data_contract: Arc, + document_type_name: String, + document: Document, + price: Credits, + ) -> Self { + Self { + data_contract, + document_type_name, + document, + price, + token_payment_info: None, + settings: None, + user_fee_increase: None, + state_transition_creation_options: None, + } + } + + /// Creates a new builder from document ID + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type + /// * `document_id` - The ID of the document + /// * `owner_id` - The owner ID of the document + /// * `price` - The new price in credits + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn from_document_info( + data_contract: Arc, + document_type_name: String, + document_id: Identifier, + owner_id: Identifier, + price: Credits, + ) -> Self { + // Create a minimal document with just the required fields + // The actual document will be fetched during the transition + let document = Document::V0(dpp::document::DocumentV0 { + id: document_id, + owner_id, + properties: Default::default(), + revision: Some(1), // Will be updated during transition + created_at: None, + updated_at: None, + transferred_at: None, + created_at_block_height: None, + updated_at_block_height: None, + transferred_at_block_height: None, + created_at_core_block_height: None, + updated_at_core_block_height: None, + transferred_at_core_block_height: None, + }); + + Self::new(data_contract, document_type_name, document, price) + } + + /// Adds token payment info to the document set price transition + /// + /// # Arguments + /// + /// * `token_payment_info` - The token payment info to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_token_payment_info(mut self, token_payment_info: TokenPaymentInfo) -> Self { + self.token_payment_info = Some(token_payment_info); + self + } + + /// Adds a user fee increase to the document set price transition + /// + /// # Arguments + /// + /// * `user_fee_increase` - The user fee increase to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_user_fee_increase(mut self, user_fee_increase: UserFeeIncrease) -> Self { + self.user_fee_increase = Some(user_fee_increase); + self + } + + /// Adds settings to the document set price transition + /// + /// # Arguments + /// + /// * `settings` - The settings to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_settings(mut self, settings: PutSettings) -> Self { + self.settings = Some(settings); + self + } + + /// Adds creation_options to the document set price transition + /// + /// # Arguments + /// + /// * `creation_options` - The creation options to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_state_transition_creation_options( + mut self, + creation_options: StateTransitionCreationOptions, + ) -> Self { + self.state_transition_creation_options = Some(creation_options); + self + } + + /// Signs the document set price transition + /// + /// # Arguments + /// + /// * `sdk` - The SDK instance + /// * `identity_public_key` - The public key of the identity + /// * `signer` - The signer instance + /// * `platform_version` - The platform version + /// + /// # Returns + /// + /// * `Result` - The signed state transition or an error + pub async fn sign( + &self, + sdk: &Sdk, + identity_public_key: &IdentityPublicKey, + signer: &impl Signer, + platform_version: &PlatformVersion, + ) -> Result { + let identity_contract_nonce = sdk + .get_identity_contract_nonce( + self.document.owner_id(), + self.data_contract.id(), + true, + self.settings, + ) + .await?; + + let document_type = self + .data_contract + .document_type_for_name(&self.document_type_name) + .map_err(|e| Error::Protocol(e.into()))?; + + let state_transition = BatchTransition::new_document_update_price_transition_from_document( + self.document.clone(), + document_type, + self.price, + identity_public_key, + identity_contract_nonce, + self.user_fee_increase.unwrap_or_default(), + self.token_payment_info, + signer, + platform_version, + self.state_transition_creation_options, + )?; + + Ok(state_transition) + } +} + +/// Result types returned from document set price operations. +#[derive(Debug)] +pub enum DocumentSetPriceResult { + /// Document price updated, containing the document with new price. + Document(Document), +} + +impl Sdk { + /// Sets the price for a document on the platform. + /// + /// This method broadcasts a document price update transition to set or change + /// the price of an existing document. The result contains the updated document. + /// + /// # Arguments + /// + /// * `set_price_document_transition_builder` - Builder containing price update parameters + /// * `signing_key` - The identity public key for signing the transition + /// * `signer` - Implementation of the Signer trait for cryptographic signing + /// + /// # Returns + /// + /// Returns a `Result` containing a `DocumentSetPriceResult` on success, or an `Error` on failure. + /// + /// # Errors + /// + /// This function will return an error if: + /// - The transition signing fails + /// - Broadcasting the transition fails + /// - The proof verification returns an unexpected result type + /// - Document not found + /// - Insufficient permissions to set price + /// - Invalid price value + pub async fn document_set_price( + &self, + set_price_document_transition_builder: DocumentSetPriceTransitionBuilder, + signing_key: &IdentityPublicKey, + signer: &S, + ) -> Result { + let platform_version = self.version(); + + let put_settings = set_price_document_transition_builder.settings; + + let state_transition = set_price_document_transition_builder + .sign(self, signing_key, signer, platform_version) + .await?; + + let proof_result = state_transition + .broadcast_and_wait::(self, put_settings) + .await?; + + match proof_result { + StateTransitionProofResult::VerifiedDocuments(documents) => { + if let Some((_, Some(document))) = documents.into_iter().next() { + Ok(DocumentSetPriceResult::Document(document)) + } else { + Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected document in VerifiedDocuments result for set price transition".to_string(), + ), + vec![], + Default::default(), + )) + } + } + _ => Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected VerifiedDocuments for document set price transition".to_string(), + ), + vec![], + Default::default(), + )), + } + } +} diff --git a/packages/rs-sdk/src/platform/documents/transitions/transfer.rs b/packages/rs-sdk/src/platform/documents/transitions/transfer.rs new file mode 100644 index 00000000000..f75237927c4 --- /dev/null +++ b/packages/rs-sdk/src/platform/documents/transitions/transfer.rs @@ -0,0 +1,287 @@ +use crate::platform::transition::broadcast::BroadcastStateTransition; +use crate::platform::transition::put_settings::PutSettings; +use crate::platform::Identifier; +use crate::{Error, Sdk}; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::data_contract::DataContract; +use dpp::document::{Document, DocumentV0Getters}; +use dpp::identity::signer::Signer; +use dpp::identity::IdentityPublicKey; +use dpp::prelude::UserFeeIncrease; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::batch_transition::methods::StateTransitionCreationOptions; +use dpp::state_transition::batch_transition::BatchTransition; +use dpp::state_transition::proof_result::StateTransitionProofResult; +use dpp::state_transition::StateTransition; +use dpp::tokens::token_payment_info::TokenPaymentInfo; +use dpp::version::PlatformVersion; +use std::sync::Arc; + +/// A builder to configure and broadcast document transfer transitions +pub struct DocumentTransferTransitionBuilder { + pub data_contract: Arc, + pub document_type_name: String, + pub document: Document, + pub recipient_id: Identifier, + pub token_payment_info: Option, + pub settings: Option, + pub user_fee_increase: Option, + pub state_transition_creation_options: Option, +} + +impl DocumentTransferTransitionBuilder { + /// Start building a transfer document request for the provided DataContract. + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type + /// * `document` - The document to transfer + /// * `recipient_id` - The identifier of the recipient + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn new( + data_contract: Arc, + document_type_name: String, + document: Document, + recipient_id: Identifier, + ) -> Self { + Self { + data_contract, + document_type_name, + document, + recipient_id, + token_payment_info: None, + settings: None, + user_fee_increase: None, + state_transition_creation_options: None, + } + } + + /// Creates a new builder from document ID + /// + /// # Arguments + /// + /// * `data_contract` - The data contract + /// * `document_type_name` - The name of the document type + /// * `document_id` - The ID of the document + /// * `owner_id` - The current owner ID of the document + /// * `recipient_id` - The identifier of the recipient + /// + /// # Returns + /// + /// * `Self` - The new builder instance + pub fn from_document_info( + data_contract: Arc, + document_type_name: String, + document_id: Identifier, + owner_id: Identifier, + recipient_id: Identifier, + ) -> Self { + // Create a minimal document with just the required fields + // The actual document will be fetched during the transition + let document = Document::V0(dpp::document::DocumentV0 { + id: document_id, + owner_id, + properties: Default::default(), + revision: Some(1), // Will be updated during transition + created_at: None, + updated_at: None, + transferred_at: None, + created_at_block_height: None, + updated_at_block_height: None, + transferred_at_block_height: None, + created_at_core_block_height: None, + updated_at_core_block_height: None, + transferred_at_core_block_height: None, + }); + + Self::new(data_contract, document_type_name, document, recipient_id) + } + + /// Adds token payment info to the document transfer transition + /// + /// # Arguments + /// + /// * `token_payment_info` - The token payment info to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_token_payment_info(mut self, token_payment_info: TokenPaymentInfo) -> Self { + self.token_payment_info = Some(token_payment_info); + self + } + + /// Adds a user fee increase to the document transfer transition + /// + /// # Arguments + /// + /// * `user_fee_increase` - The user fee increase to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_user_fee_increase(mut self, user_fee_increase: UserFeeIncrease) -> Self { + self.user_fee_increase = Some(user_fee_increase); + self + } + + /// Adds settings to the document transfer transition + /// + /// # Arguments + /// + /// * `settings` - The settings to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_settings(mut self, settings: PutSettings) -> Self { + self.settings = Some(settings); + self + } + + /// Adds creation_options to the document transfer transition + /// + /// # Arguments + /// + /// * `creation_options` - The creation options to add + /// + /// # Returns + /// + /// * `Self` - The updated builder + pub fn with_state_transition_creation_options( + mut self, + creation_options: StateTransitionCreationOptions, + ) -> Self { + self.state_transition_creation_options = Some(creation_options); + self + } + + /// Signs the document transfer transition + /// + /// # Arguments + /// + /// * `sdk` - The SDK instance + /// * `identity_public_key` - The public key of the identity + /// * `signer` - The signer instance + /// * `platform_version` - The platform version + /// + /// # Returns + /// + /// * `Result` - The signed state transition or an error + pub async fn sign( + &self, + sdk: &Sdk, + identity_public_key: &IdentityPublicKey, + signer: &impl Signer, + platform_version: &PlatformVersion, + ) -> Result { + let identity_contract_nonce = sdk + .get_identity_contract_nonce( + self.document.owner_id(), + self.data_contract.id(), + true, + self.settings, + ) + .await?; + + let document_type = self + .data_contract + .document_type_for_name(&self.document_type_name) + .map_err(|e| Error::Protocol(e.into()))?; + + let state_transition = BatchTransition::new_document_transfer_transition_from_document( + self.document.clone(), + document_type, + self.recipient_id, + identity_public_key, + identity_contract_nonce, + self.user_fee_increase.unwrap_or_default(), + self.token_payment_info, + signer, + platform_version, + self.state_transition_creation_options, + )?; + + Ok(state_transition) + } +} + +/// Result types returned from document transfer operations. +#[derive(Debug)] +pub enum DocumentTransferResult { + /// Document transferred successfully, containing the document with new owner. + Document(Document), +} + +impl Sdk { + /// Transfers ownership of a document to another identity. + /// + /// This method broadcasts a document transfer transition to change the ownership + /// of an existing document to a new identity. The result contains the transferred document. + /// + /// # Arguments + /// + /// * `transfer_document_transition_builder` - Builder containing transfer parameters + /// * `signing_key` - The identity public key for signing the transition + /// * `signer` - Implementation of the Signer trait for cryptographic signing + /// + /// # Returns + /// + /// Returns a `Result` containing a `DocumentTransferResult` on success, or an `Error` on failure. + /// + /// # Errors + /// + /// This function will return an error if: + /// - The transition signing fails + /// - Broadcasting the transition fails + /// - The proof verification returns an unexpected result type + /// - Document not found + /// - Insufficient permissions to transfer the document + /// - Invalid recipient identity + pub async fn document_transfer( + &self, + transfer_document_transition_builder: DocumentTransferTransitionBuilder, + signing_key: &IdentityPublicKey, + signer: &S, + ) -> Result { + let platform_version = self.version(); + + let put_settings = transfer_document_transition_builder.settings; + + let state_transition = transfer_document_transition_builder + .sign(self, signing_key, signer, platform_version) + .await?; + + let proof_result = state_transition + .broadcast_and_wait::(self, put_settings) + .await?; + + match proof_result { + StateTransitionProofResult::VerifiedDocuments(documents) => { + if let Some((_, Some(document))) = documents.into_iter().next() { + Ok(DocumentTransferResult::Document(document)) + } else { + Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected document in VerifiedDocuments result for transfer transition" + .to_string(), + ), + vec![], + Default::default(), + )) + } + } + _ => Err(Error::DriveProofError( + drive::error::proof::ProofError::UnexpectedResultProof( + "Expected VerifiedDocuments for document transfer transition".to_string(), + ), + vec![], + Default::default(), + )), + } + } +} diff --git a/packages/rs-sdk/src/platform/fetch_many.rs b/packages/rs-sdk/src/platform/fetch_many.rs index 59767c6acbc..b6541439898 100644 --- a/packages/rs-sdk/src/platform/fetch_many.rs +++ b/packages/rs-sdk/src/platform/fetch_many.rs @@ -6,13 +6,8 @@ //! - `[FetchMany]`: An async trait that fetches multiple items of a specific type from Platform. use super::LimitQuery; -use crate::{ - error::Error, - mock::MockResponse, - platform::{document_query::DocumentQuery, query::Query}, - sync::retry, - Sdk, -}; +use crate::platform::documents::document_query::DocumentQuery; +use crate::{error::Error, mock::MockResponse, platform::query::Query, sync::retry, Sdk}; use dapi_grpc::platform::v0::{ GetContestedResourceIdentityVotesRequest, GetContestedResourceVoteStateRequest, GetContestedResourceVotersForIdentityRequest, GetContestedResourcesRequest, @@ -315,7 +310,7 @@ where /// ## Supported query types /// /// * [DriveQuery](crate::platform::DriveDocumentQuery) - query that specifies document matching criteria -/// * [DocumentQuery](crate::platform::document_query::DocumentQuery) +/// * [DocumentQuery](crate::platform::documents::document_query::DocumentQuery) #[async_trait::async_trait] impl FetchMany for Document { // We need to use the DocumentQuery type here because the DocumentQuery diff --git a/packages/rs-sdk/src/platform/query.rs b/packages/rs-sdk/src/platform/query.rs index 0cdfbc81e9c..44a366895db 100644 --- a/packages/rs-sdk/src/platform/query.rs +++ b/packages/rs-sdk/src/platform/query.rs @@ -3,7 +3,8 @@ //! [Query] trait is used to specify individual objects as well as search criteria for fetching multiple objects from Platform. use super::types::epoch::EpochQuery; use super::types::evonode::EvoNode; -use crate::{error::Error, platform::document_query::DocumentQuery}; +use crate::error::Error; +use crate::platform::documents::document_query::DocumentQuery; use dapi_grpc::mock::Mockable; use dapi_grpc::platform::v0::get_contested_resource_identity_votes_request::GetContestedResourceIdentityVotesRequestV0; use dapi_grpc::platform::v0::get_contested_resource_voters_for_identity_request::GetContestedResourceVotersForIdentityRequestV0;