Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 99 additions & 1 deletion .pnp.cjs

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

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/dashmate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"chalk": "^4.1.0",
"cron": "^2.1.0",
"diskusage": "^1.2.0",
"dockerode": "^3.3.5",
"dockerode": "^4.0.5",
"dot": "^1.1.3",
"dotenv": "^8.6.0",
"enquirer": "github:dashpay/enquirer#patch-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use thiserror::Error;
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
)]
#[error(
"Token claim error: expected claimant '{}' for token ID '{}', but received claim from '{}'",
expected_claimant_id,
"Token claim error: Identity '{}' is not a valid claimant for this distribution type of token '{}'. The valid claimaint is '{}'.",
claimant_id,
token_id,
claimant_id
expected_claimant_id
)]
#[platform_serialize(unversioned)]
pub struct InvalidTokenClaimWrongClaimant {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,7 @@ impl TokenTransitionV0Methods for TokenTransition {
TokenDistributionResolvedRecipient::ContractOwnerIdentity(owner_id)
}
TokenDistributionRecipient::Identity(identifier) => {
TokenDistributionResolvedRecipient::ContractOwnerIdentity(
identifier,
)
TokenDistributionResolvedRecipient::Identity(identifier)
}
TokenDistributionRecipient::EvonodesByParticipation => {
TokenDistributionResolvedRecipient::Evonode(owner_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl TokenTransitionAction {
)
}

/// Historical document id
/// Historical document
pub fn build_historical_document(
&self,
token_id: Identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,19 @@ impl Drive {
platform_version,
)?;

// Some fields are populated by the drive,
// so we need to ignore them
let ignore_fields = match token_transition {
TokenTransition::DestroyFrozenFunds(_) => {
Some(vec!["destroyedAmount"])
}
TokenTransition::Claim(_) => Some(vec!["amount"]),
_ => None,
};

if !document.is_equal_ignoring_time_based_fields(
&expected_document,
Some(vec!["destroyedAmount"]),
ignore_fields,
platform_version,
)? {
return Err(Error::Proof(ProofError::IncorrectProof(format!("proof of state transition execution did not show the correct historical document {}, {}", document, expected_document))));
Expand Down
153 changes: 153 additions & 0 deletions packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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::associated_token::token_distribution_key::TokenDistributionType;
use dpp::data_contract::{DataContract, TokenContractPosition};
use dpp::identity::signer::Signer;
use dpp::identity::IdentityPublicKey;
use dpp::prelude::UserFeeIncrease;
use dpp::state_transition::batch_transition::methods::v1::DocumentsBatchTransitionMethodsV1;
use dpp::state_transition::batch_transition::BatchTransition;
use dpp::state_transition::StateTransition;
use dpp::tokens::calculate_token_id;
use dpp::version::PlatformVersion;

/// A builder to configure and broadcast token claim transitions
pub struct TokenClaimTransitionBuilder<'a> {
data_contract: &'a DataContract,
token_position: TokenContractPosition,
owner_id: Identifier,
distribution_type: TokenDistributionType,
public_note: Option<String>,
settings: Option<PutSettings>,
user_fee_increase: Option<UserFeeIncrease>,
}

impl<'a> TokenClaimTransitionBuilder<'a> {
/// Start building a claim tokens transition for the provided DataContract.
///
/// # 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 state transition owner
/// * `distribution_type` - The token distribution type
///
/// # Returns
///
/// * `Self` - The new builder instance
pub fn new(
data_contract: &'a DataContract,
token_position: TokenContractPosition,
owner_id: Identifier,
distribution_type: TokenDistributionType,
) -> Self {
// TODO: Validate token position

Self {
data_contract,
token_position,
owner_id,
distribution_type,
public_note: None,
settings: None,
user_fee_increase: None,
}
}

/// Adds a public note to the token claim 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 claim 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 token claim 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
}

/// Signs the token claim 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
pub async fn sign(
&self,
sdk: &Sdk,
identity_public_key: &IdentityPublicKey,
signer: &impl Signer,
platform_version: &PlatformVersion,
) -> Result<StateTransition, Error> {
let token_id = Identifier::from(calculate_token_id(
self.data_contract.id().as_bytes(),
self.token_position,
));

let identity_contract_nonce = sdk
.get_identity_contract_nonce(
self.owner_id,
self.data_contract.id(),
true,
self.settings,
)
.await?;

let state_transition = BatchTransition::new_token_claim_transition(
token_id,
self.owner_id,
self.data_contract.id(),
self.token_position,
self.distribution_type,
self.public_note.clone(),
identity_public_key,
identity_contract_nonce,
self.user_fee_increase.unwrap_or_default(),
signer,
platform_version,
None,
None,
None,
)?;

Ok(state_transition)
}
}
Loading
Loading