Skip to content

Commit

Permalink
more token work
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jan 7, 2025
1 parent 6aaadb6 commit 779114d
Show file tree
Hide file tree
Showing 71 changed files with 788 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ impl TokenConfigurationV0Getters for TokenConfiguration {
}
}

/// Returns if we start as paused.
fn start_as_paused(&self) -> bool {
match self {
TokenConfiguration::V0(v0) => v0.start_as_paused(),
}
}

/// Returns the maximum supply.
fn max_supply(&self) -> Option<u64> {
match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub trait TokenConfigurationV0Getters {
fn base_supply(&self) -> u64;
/// Returns the base supply.
fn keeps_history(&self) -> bool;
fn start_as_paused(&self) -> bool;

/// Returns the maximum supply.
fn max_supply(&self) -> Option<u64>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ impl TokenConfigurationV0Getters for TokenConfigurationV0 {
self.keeps_history
}

/// Returns if we start off as paused
fn start_as_paused(&self) -> bool {
self.start_as_paused
}

/// Returns the maximum supply.
fn max_supply(&self) -> Option<u64> {
self.max_supply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct TokenConfigurationV0 {
/// Do we keep history, default is true.
#[serde(default = "default_keeps_history")]
pub keeps_history: bool,
/// Do we start off as paused, meaning that we can not transfer till we unpause.
#[serde(default = "default_starts_as_paused")]
pub start_as_paused: bool,
/// Who can change the max supply
/// Even if set no one can ever change this under the base supply
#[serde(default = "default_change_control_rules")]
Expand Down Expand Up @@ -84,6 +87,11 @@ fn default_keeps_history() -> bool {
true // Default to `true` for keeps_history
}

// Default function for `starts_as_paused`
fn default_starts_as_paused() -> bool {
false
}

fn default_change_control_rules() -> ChangeControlRules {
ChangeControlRules::V0(ChangeControlRulesV0 {
authorized_to_make_change: AuthorizedActionTakers::NoOne,
Expand All @@ -106,10 +114,12 @@ impl fmt::Display for TokenConfigurationV0 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"TokenConfigurationV0 {{\n conventions: {:?},\n base_supply: {},\n max_supply: {:?},\n max_supply_change_rules: {:?},\n new_tokens_destination_identity: {:?},\n new_tokens_destination_identity_rules: {:?},\n minting_allow_choosing_destination: {},\n minting_allow_choosing_destination_rules: {:?},\n manual_minting_rules: {:?},\n manual_burning_rules: {:?},\n freeze_rules: {:?},\n unfreeze_rules: {:?},\n destroy_frozen_funds_rules: {:?},\n emergency_action_rules: {:?},\n main_control_group: {:?},\n main_control_group_can_be_modified: {:?}\n}}",
"TokenConfigurationV0 {{\n conventions: {:?},\n base_supply: {},\n max_supply: {:?},\n keeps_history: {},\n start_as_paused: {},\n max_supply_change_rules: {:?},\n new_tokens_destination_identity: {:?},\n new_tokens_destination_identity_rules: {:?},\n minting_allow_choosing_destination: {},\n minting_allow_choosing_destination_rules: {:?},\n manual_minting_rules: {:?},\n manual_burning_rules: {:?},\n freeze_rules: {:?},\n unfreeze_rules: {:?},\n destroy_frozen_funds_rules: {:?},\n emergency_action_rules: {:?},\n main_control_group: {:?},\n main_control_group_can_be_modified: {:?}\n}}",
self.conventions,
self.base_supply,
self.max_supply,
self.keeps_history,
self.start_as_paused,
self.max_supply_change_rules,
self.new_tokens_destination_identity,
self.new_tokens_destination_identity_rules,
Expand Down Expand Up @@ -137,6 +147,7 @@ impl TokenConfigurationV0 {
base_supply: 100000,
max_supply: None,
keeps_history: true,
start_as_paused: false,
max_supply_change_rules: ChangeControlRulesV0 {
authorized_to_make_change: AuthorizedActionTakers::NoOne,
authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne,
Expand Down
15 changes: 15 additions & 0 deletions packages/rs-dpp/src/tokens/emergency_action.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::tokens::status::TokenStatus;
use crate::ProtocolError;
use bincode::{Decode, Encode};
use platform_version::version::PlatformVersion;
#[cfg(feature = "state-transition-serde-conversion")]
use serde::{Deserialize, Serialize};

Expand All @@ -13,3 +16,15 @@ pub enum TokenEmergencyAction {
Pause = 0,
Resume = 1,
}

impl TokenEmergencyAction {
pub fn resulting_status(
&self,
platform_version: &PlatformVersion,
) -> Result<TokenStatus, ProtocolError> {
match self {
TokenEmergencyAction::Pause => TokenStatus::new(true, platform_version),
TokenEmergencyAction::Resume => TokenStatus::new(false, platform_version),
}
}
}
1 change: 1 addition & 0 deletions packages/rs-dpp/src/tokens/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod allowed_currency;
pub mod emergency_action;
pub mod errors;
pub mod info;
pub mod status;
pub mod token_event;

pub fn calculate_token_id(contract_id: &[u8; 32], token_pos: TokenContractPosition) -> [u8; 32] {
Expand Down
16 changes: 16 additions & 0 deletions packages/rs-dpp/src/tokens/status/methods.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::tokens::status::v0::TokenStatusV0Accessors;
use crate::tokens::status::TokenStatus;

impl TokenStatusV0Accessors for TokenStatus {
fn paused(&self) -> bool {
match self {
TokenStatus::V0(status) => status.paused,
}
}

fn set_paused(&mut self, frozen: bool) {
match self {
TokenStatus::V0(status) => status.set_paused(frozen),
}
}
}
44 changes: 44 additions & 0 deletions packages/rs-dpp/src/tokens/status/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::tokens::status::v0::TokenStatusV0;
use crate::ProtocolError;
use bincode::Encode;
use derive_more::From;
use platform_serialization::de::Decode;
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use platform_version::version::PlatformVersion;
use platform_versioning::PlatformVersioned;

mod methods;
pub mod v0;

#[derive(
Debug,
Clone,
Encode,
Decode,
PlatformDeserialize,
PlatformSerialize,
PlatformVersioned,
From,
PartialEq,
)]
#[platform_serialize(unversioned)] //versioned directly, no need to use platform_version
pub enum TokenStatus {
V0(TokenStatusV0),
}

impl TokenStatus {
pub fn new(paused: bool, platform_version: &PlatformVersion) -> Result<Self, ProtocolError> {
match platform_version
.dpp
.token_versions
.identity_token_status_default_structure_version
{
0 => Ok(TokenStatus::V0(TokenStatusV0 { paused })),
version => Err(ProtocolError::UnknownVersionMismatch {
method: "IdentityTokenStatus::new".to_string(),
known_versions: vec![0],
received: version,
}),
}
}
}
26 changes: 26 additions & 0 deletions packages/rs-dpp/src/tokens/status/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use bincode::{Decode, Encode};
use derive_more::From;

#[derive(Debug, Clone, Encode, Decode, From, PartialEq)]
/// Token status
pub struct TokenStatusV0 {
pub paused: bool,
}

pub trait TokenStatusV0Accessors {
/// Gets the paused state of the token.
fn paused(&self) -> bool;

/// Sets the paused state of the token.
fn set_paused(&mut self, paused: bool);
}

impl TokenStatusV0Accessors for TokenStatusV0 {
fn paused(&self) -> bool {
self.paused
}

fn set_paused(&mut self, paused: bool) {
self.paused = paused;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dashcore_rpc::dashcore::Network;
use dpp::block::block_info::BlockInfo;
use dpp::identifier::Identifier;
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_create_transition_action::DocumentCreateTransitionAction;
use drive::state_transition_action::batch::batched_transition::document_transition::document_create_transition_action::DocumentCreateTransitionAction;
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;
use crate::error::Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
use dpp::prelude::{ConsensusValidationResult, Identifier};
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_create_transition_action::{DocumentCreateTransitionAction, DocumentCreateTransitionActionAccessorsV0};
use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_create_transition_action::{DocumentCreateTransitionAction, DocumentCreateTransitionActionAccessorsV0};
use dpp::version::PlatformVersion;
use dpp::voting::vote_info_storage::contested_document_vote_poll_stored_info::{ContestedDocumentVotePollStatus, ContestedDocumentVotePollStoredInfoV0Getters};
use drive::error::drive::DriveError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
use dpp::prelude::{ConsensusValidationResult, Identifier};
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_create_transition_action::{DocumentCreateTransitionAction, DocumentCreateTransitionActionAccessorsV0};
use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_create_transition_action::{DocumentCreateTransitionAction, DocumentCreateTransitionActionAccessorsV0};
use dpp::version::PlatformVersion;
use dpp::voting::vote_info_storage::contested_document_vote_poll_stored_info::{ContestedDocumentVotePollStatus, ContestedDocumentVotePollStoredInfoV0Getters};
use drive::error::drive::DriveError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use dpp::data_contract::document_type::restricted_creation::CreationRestrictionM
use dpp::data_contract::validate_document::DataContractDocumentValidationMethodsV0;
use dpp::identifier::Identifier;
use dpp::validation::{SimpleConsensusValidationResult};
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_create_transition_action::{DocumentCreateTransitionAction, DocumentCreateTransitionActionAccessorsV0};
use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_create_transition_action::{DocumentCreateTransitionAction, DocumentCreateTransitionActionAccessorsV0};
use dpp::version::PlatformVersion;
use crate::error::Error;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dpp::block::block_info::BlockInfo;
use dpp::identifier::Identifier;
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_delete_transition_action::DocumentDeleteTransitionAction;
use drive::state_transition_action::batch::batched_transition::document_transition::document_delete_transition_action::DocumentDeleteTransitionAction;
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;
use crate::error::Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use dpp::document::{Document, DocumentV0Getters};
use dpp::identifier::Identifier;
use dpp::prelude::ConsensusValidationResult;
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_delete_transition_action::DocumentDeleteTransitionAction;
use drive::state_transition_action::batch::batched_transition::document_transition::document_delete_transition_action::DocumentDeleteTransitionAction;
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_delete_transition_action::v0::DocumentDeleteTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_delete_transition_action::v0::DocumentDeleteTransitionActionAccessorsV0;
use crate::error::Error;
use crate::execution::types::execution_operation::ValidationOperation;
use crate::execution::types::state_transition_execution_context::{StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use dpp::consensus::basic::document::{InvalidDocumentTransitionActionError, Inva
use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_delete_transition_action::DocumentDeleteTransitionAction;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_delete_transition_action::v0::DocumentDeleteTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_delete_transition_action::DocumentDeleteTransitionAction;
use drive::state_transition_action::batch::batched_transition::document_transition::document_delete_transition_action::v0::DocumentDeleteTransitionActionAccessorsV0;

use crate::error::Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dpp::block::block_info::BlockInfo;
use dpp::identifier::Identifier;

use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_purchase_transition_action::DocumentPurchaseTransitionAction;
use drive::state_transition_action::batch::batched_transition::document_transition::document_purchase_transition_action::DocumentPurchaseTransitionAction;
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;
use crate::error::Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
use dpp::identifier::Identifier;
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_purchase_transition_action::{DocumentPurchaseTransitionAction, DocumentPurchaseTransitionActionAccessorsV0};
use drive::state_transition_action::batch::batched_transition::document_transition::document_purchase_transition_action::{DocumentPurchaseTransitionAction, DocumentPurchaseTransitionActionAccessorsV0};
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use crate::error::Error;
use crate::execution::types::state_transition_execution_context::StateTransitionExecutionContext;
use crate::platform_types::platform::PlatformStateRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
use dpp::document::DocumentV0Getters;
use dpp::nft::TradeMode;
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_purchase_transition_action::{DocumentPurchaseTransitionAction, DocumentPurchaseTransitionActionAccessorsV0};
use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_purchase_transition_action::{DocumentPurchaseTransitionAction, DocumentPurchaseTransitionActionAccessorsV0};
use dpp::version::PlatformVersion;
use crate::error::Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dpp::block::block_info::BlockInfo;
use dpp::identifier::Identifier;

use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_replace_transition_action::DocumentReplaceTransitionAction;
use drive::state_transition_action::batch::batched_transition::document_transition::document_replace_transition_action::DocumentReplaceTransitionAction;
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;
use crate::error::Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
use dpp::identifier::Identifier;
use dpp::validation::SimpleConsensusValidationResult;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_replace_transition_action::{DocumentReplaceTransitionAction, DocumentReplaceTransitionActionAccessorsV0};
use drive::state_transition_action::batch::batched_transition::document_transition::document_replace_transition_action::{DocumentReplaceTransitionAction, DocumentReplaceTransitionActionAccessorsV0};
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;
use drive::state_transition_action::document::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use drive::state_transition_action::batch::batched_transition::document_transition::document_base_transition_action::DocumentBaseTransitionActionAccessorsV0;
use crate::error::Error;
use crate::execution::types::state_transition_execution_context::StateTransitionExecutionContext;
use crate::platform_types::platform::PlatformStateRef;
Expand Down
Loading

0 comments on commit 779114d

Please sign in to comment.