Skip to content

Commit

Permalink
docs: add doc blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Jan 27, 2025
1 parent d116b06 commit 7633aee
Show file tree
Hide file tree
Showing 9 changed files with 526 additions and 13 deletions.
42 changes: 42 additions & 0 deletions packages/rs-sdk/src/platform/transition/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,27 @@ use dpp::identity::IdentityPublicKey;
use dpp::state_transition::StateTransition;
use dpp::version::PlatformVersion;

/// Trait for building state transitions
pub trait StateTransitionBuilder {
/// Returns the settings for the state transition
///
/// # Returns
///
/// * `Option<PutSettings>` - The settings, if any
fn settings(&self) -> Option<PutSettings>;

/// Signs the state 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<StateTransition, Error>` - The signed state transition or an error
async fn sign(
&self,
sdk: &Sdk,
Expand All @@ -19,6 +37,18 @@ pub trait StateTransitionBuilder {
platform_version: &PlatformVersion,
) -> Result<StateTransition, Error>;

/// Broadcasts the state 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<StateTransition, Error>` - The broadcasted state transition or an error
async fn broadcast(
&self,
sdk: &Sdk,
Expand All @@ -35,6 +65,18 @@ pub trait StateTransitionBuilder {
Ok(state_transition)
}

/// Broadcasts the state transition and waits for the result
///
/// # 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<(Identifier, TokenAmount), Error>` - The result of the broadcasted state transition or an error
async fn broadcast_and_wait_for_result(
&self,
sdk: &Sdk,
Expand Down
68 changes: 62 additions & 6 deletions packages/rs-sdk/src/platform/transition/fungible_tokens/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use dpp::state_transition::StateTransition;
use dpp::tokens::calculate_token_id;
use dpp::version::PlatformVersion;

/// A builder to configure and broadcast burning tokens transition
/// A builder to configure and broadcast token burn transitions
pub struct TokenBurnTransitionBuilder<'a> {
data_contract: &'a DataContract,
token_position: TokenContractPosition,
Expand All @@ -28,14 +28,20 @@ pub struct TokenBurnTransitionBuilder<'a> {
}

impl<'a> TokenBurnTransitionBuilder<'a> {
/// Creates a new `TokenBurnTransitionBuilder`
///
/// # Arguments
///
/// * `data_contract` - A reference to the data contract
/// * `token_position` - The position of the token in the contract
/// * `owner_id` - The identifier of the token owner
/// * `amount` - The amount of tokens to burn
pub fn new(
data_contract: &'a DataContract,
token_position: TokenContractPosition,
owner_id: Identifier,
amount: TokenAmount,
) -> Self {
// TODO: Validate token position

Self {
data_contract,
token_position,
Expand All @@ -48,35 +54,85 @@ impl<'a> TokenBurnTransitionBuilder<'a> {
}
}

/// Adds a public note to the token burn transition
///
/// # Arguments
///
/// * `note` - The public note to add
///
/// # Returns
///
/// * `Self` - The updated builder
pub fn with_public_note(mut self, note: String) -> Self {
self.public_note = Some(note);
self
}

/// Adds a user fee increase to the token burn 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 group information to the token burn transition
///
/// # Arguments
///
/// * `group_info` - The group information to add
///
/// # Returns
///
/// * `Self` - The updated builder
pub fn with_using_group_info(mut self, group_info: GroupStateTransitionInfoStatus) -> Self {
self.using_group_info = Some(group_info);

// TODO: Simplify group actions automatically find position if group action is required

self
}

/// Adds settings to the token burn 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
}
}

impl StateTransitionBuilder for TokenBurnTransitionBuilder<'_> {
/// Returns the settings for the token burn transition
///
/// # Returns
///
/// * `Option<PutSettings>` - The settings, if any
fn settings(&self) -> Option<PutSettings> {
self.settings
}

/// Signs the token burn 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<StateTransition, Error>` - The signed state transition or an error
async fn sign(
&self,
sdk: &Sdk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use dpp::state_transition::StateTransition;
use dpp::tokens::calculate_token_id;
use dpp::version::PlatformVersion;

/// A builder to configure minting tokens.
/// A builder to configure and broadcast token destroy funds transitions
pub struct TokenDestroyFrozenFundsTransitionBuilder<'a> {
data_contract: &'a DataContract,
token_position: TokenContractPosition,
Expand All @@ -28,6 +28,17 @@ pub struct TokenDestroyFrozenFundsTransitionBuilder<'a> {

impl<'a> TokenDestroyFrozenFundsTransitionBuilder<'a> {
/// Start building a mint tokens request for the provided DataContract.
///
/// # Arguments
///
/// * `data_contract` - A reference to the data contract
/// * `token_position` - The position of the token in the contract
/// * `actor_id` - The identifier of the actor
/// * `frozen_identity_id` - The identifier of the frozen identity
///
/// # Returns
///
/// * `Self` - The new builder instance
pub fn new(
data_contract: &'a DataContract,
token_position: TokenContractPosition,
Expand All @@ -48,16 +59,43 @@ impl<'a> TokenDestroyFrozenFundsTransitionBuilder<'a> {
}
}

/// Adds a public note to the token destroy transition
///
/// # Arguments
///
/// * `note` - The public note to add
///
/// # Returns
///
/// * `Self` - The updated builder
pub fn with_public_note(mut self, note: String) -> Self {
self.public_note = Some(note);
self
}

/// Adds a user fee increase to the token destroy 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 group information to the token destroy transition
///
/// # Arguments
///
/// * `group_info` - The group information to add
///
/// # Returns
///
/// * `Self` - The updated builder
pub fn with_using_group_info(mut self, group_info: GroupStateTransitionInfoStatus) -> Self {
self.using_group_info = Some(group_info);

Expand All @@ -66,17 +104,43 @@ impl<'a> TokenDestroyFrozenFundsTransitionBuilder<'a> {
self
}

/// Adds settings to the token destroy 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
}
}

impl StateTransitionBuilder for TokenDestroyFrozenFundsTransitionBuilder<'_> {
/// Returns the settings for the token destroy transition
///
/// # Returns
///
/// * `Option<PutSettings>` - The settings, if any
fn settings(&self) -> Option<PutSettings> {
self.settings
}

/// Signs the token destroy 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<StateTransition, Error>` - The signed state transition or an error
async fn sign(
&self,
sdk: &Sdk,
Expand Down
Loading

0 comments on commit 7633aee

Please sign in to comment.