Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jan 7, 2025
1 parent e701008 commit 084f722
Show file tree
Hide file tree
Showing 30 changed files with 618 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,10 @@ impl DocumentsBatchTransitionMethodsV1 for BatchTransitionV1 {
identity_contract_nonce: IdentityNonce,
user_fee_increase: UserFeeIncrease,
signer: &S,
platform_version: &PlatformVersion,
batch_feature_version: Option<FeatureVersion>,
delete_feature_version: Option<FeatureVersion>,
base_feature_version: Option<FeatureVersion>,
_platform_version: &PlatformVersion,
_batch_feature_version: Option<FeatureVersion>,
_delete_feature_version: Option<FeatureVersion>,
_base_feature_version: Option<FeatureVersion>,
) -> Result<StateTransition, ProtocolError> {
let mut unfreeze_transition = TokenUnfreezeTransition::V0(TokenUnfreezeTransitionV0 {
base: TokenBaseTransition::V0(TokenBaseTransitionV0 {
Expand Down Expand Up @@ -761,10 +761,10 @@ impl DocumentsBatchTransitionMethodsV1 for BatchTransitionV1 {
identity_contract_nonce: IdentityNonce,
user_fee_increase: UserFeeIncrease,
signer: &S,
platform_version: &PlatformVersion,
batch_feature_version: Option<FeatureVersion>,
delete_feature_version: Option<FeatureVersion>,
base_feature_version: Option<FeatureVersion>,
_platform_version: &PlatformVersion,
_batch_feature_version: Option<FeatureVersion>,
_delete_feature_version: Option<FeatureVersion>,
_base_feature_version: Option<FeatureVersion>,
) -> Result<StateTransition, ProtocolError> {
let mut destroy_frozen_funds_transition =
TokenDestroyFrozenFundsTransition::V0(TokenDestroyFrozenFundsTransitionV0 {
Expand Down Expand Up @@ -832,10 +832,10 @@ impl DocumentsBatchTransitionMethodsV1 for BatchTransitionV1 {
identity_contract_nonce: IdentityNonce,
user_fee_increase: UserFeeIncrease,
signer: &S,
platform_version: &PlatformVersion,
batch_feature_version: Option<FeatureVersion>,
delete_feature_version: Option<FeatureVersion>,
base_feature_version: Option<FeatureVersion>,
_platform_version: &PlatformVersion,
_batch_feature_version: Option<FeatureVersion>,
_delete_feature_version: Option<FeatureVersion>,
_base_feature_version: Option<FeatureVersion>,
) -> Result<StateTransition, ProtocolError> {
let mut emergency_action_transition =
TokenEmergencyActionTransition::V0(TokenEmergencyActionTransitionV0 {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-dpp/src/tokens/emergency_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bincode::{Decode, Encode};
#[cfg(feature = "state-transition-serde-conversion")]
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, Default, Encode, Decode, PartialEq)]
#[derive(Debug, Clone, Copy, Default, Encode, Decode, PartialOrd, PartialEq, Eq)]
#[cfg_attr(
feature = "state-transition-serde-conversion",
derive(Serialize, Deserialize),
Expand Down
3 changes: 3 additions & 0 deletions packages/rs-dpp/src/tokens/token_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub type TokenEventPersonalEncryptedNote = Option<(
DerivationEncryptionKeyIndex,
Vec<u8>,
)>;
use crate::tokens::emergency_action::TokenEmergencyAction;
use crate::ProtocolError;

pub type RecipientIdentifier = Identifier;
Expand All @@ -27,11 +28,13 @@ pub enum TokenEvent {
Burn(TokenAmount, TokenEventPublicNote),
Freeze(FrozenIdentifier, TokenEventPublicNote),
Unfreeze(FrozenIdentifier, TokenEventPublicNote),
DestroyFrozenFunds(FrozenIdentifier, TokenAmount, TokenEventPublicNote),
Transfer(
RecipientIdentifier,
TokenEventPublicNote,
TokenEventSharedEncryptedNote,
TokenEventPersonalEncryptedNote,
TokenAmount,
),
EmergencyAction(TokenEmergencyAction, TokenEventPublicNote),
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,103 @@ impl Drive {
platform_version,
)?;
}
TokenEvent::DestroyFrozenFunds(frozen_identity_id, amount, public_note) => {
let document_type = contract.document_type_for_name("destroyFrozenFunds")?;
let document_id = Document::generate_document_id_v0(
&contract.id(),
&owner_id,
"destroyFrozenFunds",
owner_nonce.to_be_bytes().as_slice(),
);
let mut properties = BTreeMap::from([
("tokenId".to_string(), token_id.into()),
("frozenIdentityId".to_string(), frozen_identity_id.into()),
("amount".to_string(), amount.into()),
]);
if let Some(note) = public_note {
properties.insert("note".to_string(), note.into());
}
let document: Document = DocumentV0 {
id: document_id,
owner_id,
properties,
revision: None,
created_at: Some(block_info.time_ms),
updated_at: None,
transferred_at: None,
created_at_block_height: Some(block_info.height),
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,
}
.into();
operations = self.add_document_for_contract_operations(
DocumentAndContractInfo {
owned_document_info: OwnedDocumentInfo {
document_info: DocumentOwnedInfo((document, None)),
owner_id: Some(owner_id.to_buffer()),
},
contract: &contract,
document_type,
},
true,
block_info,
&mut None,
estimated_costs_only_with_layer_info,
transaction,
platform_version,
)?;
}
TokenEvent::EmergencyAction(action, public_note) => {
let document_type = contract.document_type_for_name("emergencyAction")?;
let document_id = Document::generate_document_id_v0(
&contract.id(),
&owner_id,
"emergencyAction",
owner_nonce.to_be_bytes().as_slice(),
);
let mut properties = BTreeMap::from([
("tokenId".to_string(), token_id.into()),
("action".to_string(), (action as u8).into()),
]);
if let Some(note) = public_note {
properties.insert("note".to_string(), note.into());
}
let document: Document = DocumentV0 {
id: document_id,
owner_id,
properties,
revision: None,
created_at: Some(block_info.time_ms),
updated_at: None,
transferred_at: None,
created_at_block_height: Some(block_info.height),
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,
}
.into();
operations = self.add_document_for_contract_operations(
DocumentAndContractInfo {
owned_document_info: OwnedDocumentInfo {
document_info: DocumentOwnedInfo((document, None)),
owner_id: Some(owner_id.to_buffer()),
},
contract: &contract,
document_type,
},
true,
block_info,
&mut None,
estimated_costs_only_with_layer_info,
transaction,
platform_version,
)?;
}
}

Ok(operations)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod document_create_transition;
mod document_delete_transition;
mod document_purchase_transition;
mod document_replace_transition;
mod document_transfer_transition;
mod document_transition;
mod document_update_price_transition;
mod documents_batch_transition;
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,8 @@ use dpp::platform_value::Identifier;
use dpp::version::PlatformVersion;

mod batch_transition;
mod document_create_transition;
mod document_delete_transition;
mod document_purchase_transition;
mod document_replace_transition;
mod document_transfer_transition;
mod document_transition;
mod document_update_price_transition;
mod documents_batch_transition;
mod token_burn_transition;
mod token_freeze_transition;
mod token_mint_transition;
mod token_transfer_transition;
mod token_transition;
mod token_unfreeze_transition;
mod document;
mod token;

/// A converter that will get High Level Drive Operations from State transitions
pub trait DriveHighLevelBatchOperationConverter {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod token_burn_transition;
mod token_destroy_frozen_funds_transition;
mod token_emergency_action_transition;
mod token_freeze_transition;
mod token_mint_transition;
mod token_transfer_transition;
mod token_transition;
mod token_unfreeze_transition;
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
use dpp::block::epoch::Epoch;
use dpp::data_contract::associated_token::token_configuration::accessors::v0::TokenConfigurationV0Getters;
use dpp::group::action_event::GroupActionEvent;
use dpp::group::group_action::GroupAction;
use dpp::group::group_action::v0::GroupActionV0;
use dpp::group::GroupStateTransitionResolvedInfo;
use dpp::identifier::Identifier;
use dpp::tokens::token_event::TokenEvent;
use platform_version::version::PlatformVersion;
use crate::error::drive::DriveError;
use crate::error::Error;
use crate::state_transition_action::action_convert_to_operations::batch::DriveHighLevelBatchOperationConverter;
use crate::state_transition_action::batch::batched_transition::token_transition::token_base_transition_action::TokenBaseTransitionActionAccessorsV0;
use crate::state_transition_action::batch::batched_transition::token_transition::token_destroy_frozen_funds_transition_action::{TokenDestroyFrozenFundsTransitionAction, TokenDestroyFrozenFundsTransitionActionAccessorsV0};
use crate::util::batch::{DriveOperation, IdentityOperationType};
use crate::util::batch::drive_op_batch::{GroupOperationType, TokenOperationType};
use crate::util::batch::DriveOperation::{GroupOperation, IdentityOperation, TokenOperation};

impl DriveHighLevelBatchOperationConverter for TokenDestroyFrozenFundsTransitionAction {
fn into_high_level_batch_drive_operations<'b>(
self,
_epoch: &Epoch,
owner_id: Identifier,
platform_version: &PlatformVersion,
) -> Result<Vec<DriveOperation<'b>>, Error> {
match platform_version
.drive
.methods
.state_transitions
.convert_to_high_level_operations
.token_destroy_frozen_funds_transition
{
0 => {
let data_contract_id = self.base().data_contract_id();

let identity_contract_nonce = self.base().identity_contract_nonce();

let mut ops = vec![IdentityOperation(
IdentityOperationType::UpdateIdentityContractNonce {
identity_id: owner_id.into_buffer(),
contract_id: data_contract_id.into_buffer(),
nonce: identity_contract_nonce,
},
)];

if let Some(GroupStateTransitionResolvedInfo {
group_contract_position,
action_id,
action_is_proposer,
signer_power,
..
}) = self.base().store_in_group()
{
let event =
TokenEvent::DestroyFrozenFunds(self.frozen_identity_id(), self.amount(), self.public_note().cloned());

let initialize_with_insert_action_info = if *action_is_proposer {
Some(GroupAction::V0(GroupActionV0 {
event: GroupActionEvent::TokenEvent(event),
}))
} else {
None
};

ops.push(GroupOperation(GroupOperationType::AddGroupAction {
contract_id: data_contract_id,
group_contract_position: *group_contract_position,
initialize_with_insert_action_info,
action_id: *action_id,
signer_identity_id: owner_id,
signer_power: *signer_power,
}));
}

if self.base().perform_action() {
ops.push(TokenOperation(TokenOperationType::TokenBurn {
token_id: self.token_id(),
identity_balance_holder_id: self.frozen_identity_id(),
burn_amount: self.amount(),
}));

let token_configuration = self.base().token_configuration()?;
if token_configuration.keeps_history() {
ops.push(TokenOperation(TokenOperationType::TokenHistory {
token_id: self.token_id(),
owner_id,
nonce: identity_contract_nonce,
event: TokenEvent::DestroyFrozenFunds(
self.frozen_identity_id(),
self.amount(),
self.public_note_owned(),
),
}));
}
}

Ok(ops)
}
version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
method: "TokenDestroyFrozenFundsTransitionAction::into_high_level_document_drive_operations"
.to_string(),
known_versions: vec![0],
received: version,
})),
}
}
}
Loading

0 comments on commit 084f722

Please sign in to comment.