From e23bcdafc6e82bfc3d1ae12b48c62ff34a7c9bcf Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Sat, 28 Dec 2024 19:00:51 +0700 Subject: [PATCH] a lot more work --- packages/data-contracts/src/error.rs | 1 - packages/data-contracts/src/lib.rs | 2 +- .../src/data_contract/accessors/v1/mod.rs | 4 +- .../token_configuration/accessors/mod.rs | 7 + .../token_configuration/accessors/v0/mod.rs | 3 + .../token_configuration/v0/accessors.rs | 5 + .../token_configuration/v0/mod.rs | 28 ++- .../src/data_contract/v1/accessors/mod.rs | 2 +- .../src/document/generate_document_id.rs | 1 + packages/rs-dpp/src/lib.rs | 9 + .../token_burn_transition/v0/mod.rs | 11 +- .../token_burn_transition/v0/v0_methods.rs | 21 ++ .../token_burn_transition/v0_methods.rs | 18 ++ .../token_issuance_transition/v0/mod.rs | 11 +- .../v0/v0_methods.rs | 35 +++ .../token_issuance_transition/v0_methods.rs | 31 +++ .../token_transfer_transition/v0/mod.rs | 30 ++- .../v0/v0_methods.rs | 149 +++++++++++- .../token_transfer_transition/v0_methods.rs | 99 ++++++++ .../batch_transition/value_conversion.rs | 4 +- packages/rs-dpp/src/tokens/mod.rs | 1 + packages/rs-dpp/src/tokens/token_event.rs | 26 +++ .../v0/mod.rs | 3 +- .../rs-drive/src/cache/system_contracts.rs | 11 + .../contract/insert/insert_contract/v1/mod.rs | 32 ++- .../contract/update/update_contract/v1/mod.rs | 35 ++- .../src/drive/initialization/v0/mod.rs | 5 +- .../src/drive/initialization/v1/mod.rs | 13 +- .../tokens/add_transaction_history/mod.rs | 1 - .../tokens/add_transaction_history/v0/mod.rs | 1 - .../add_transaction_history_operations/mod.rs | 56 +++++ .../v0/mod.rs | 213 ++++++++++++++++++ .../prove_identities_token_balances/v0/mod.rs | 192 ++++++++++------ packages/rs-drive/src/drive/tokens/mod.rs | 7 +- .../system/create_token_trees/v0/mod.rs | 4 +- .../document/token_burn_transition.rs | 12 + .../document/token_issuance_transition.rs | 14 +- .../document/token_transfer_transition.rs | 35 ++- .../document_transition/mod.rs | 3 +- .../token_burn_transition_action/mod.rs | 64 ++---- .../token_burn_transition_action/v0/mod.rs | 60 ++++- .../v0/transformer.rs | 14 +- .../token_mint_transition_action/mod.rs | 26 ++- .../token_mint_transition_action/v0/mod.rs | 37 ++- .../v0/transformer.rs | 8 +- .../token_transfer_transition_action/mod.rs | 130 +++++++---- .../v0/mod.rs | 162 ++++++++++++- .../v0/transformer.rs | 12 + .../src/util/batch/drive_op_batch/token.rs | 33 ++- .../batch_insert_empty_sum_tree/mod.rs | 10 +- .../batch_insert_empty_sum_tree/v0/mod.rs | 12 +- packages/rs-drive/src/verify/mod.rs | 2 +- packages/rs-drive/src/verify/tokens/mod.rs | 2 +- .../mod.rs | 10 +- .../v0/mod.rs | 4 +- .../drive_token_method_versions/mod.rs | 1 + .../drive_token_method_versions/v1.rs | 1 + .../drive_verify_method_versions/v1.rs | 7 +- .../rs-platform-version/src/version/mod.rs | 2 +- .../v1/token-history-contract-documents.json | 48 +++- .../batched_transition/mod.rs | 2 +- .../state_transition/batch_transition/mod.rs | 4 +- .../batch_transition/token_transition/mod.rs | 2 +- .../src/errors/consensus/consensus_error.rs | 6 +- .../state_transition_factory.rs | 2 +- 65 files changed, 1526 insertions(+), 270 deletions(-) create mode 100644 packages/rs-dpp/src/tokens/token_event.rs delete mode 100644 packages/rs-drive/src/drive/tokens/add_transaction_history/mod.rs delete mode 100644 packages/rs-drive/src/drive/tokens/add_transaction_history/v0/mod.rs create mode 100644 packages/rs-drive/src/drive/tokens/add_transaction_history_operations/mod.rs create mode 100644 packages/rs-drive/src/drive/tokens/add_transaction_history_operations/v0/mod.rs diff --git a/packages/data-contracts/src/error.rs b/packages/data-contracts/src/error.rs index d2f33d32250..7c0c802b71e 100644 --- a/packages/data-contracts/src/error.rs +++ b/packages/data-contracts/src/error.rs @@ -136,4 +136,3 @@ impl From for Error { } } } - diff --git a/packages/data-contracts/src/lib.rs b/packages/data-contracts/src/lib.rs index cf82480300f..a78ffefc373 100644 --- a/packages/data-contracts/src/lib.rs +++ b/packages/data-contracts/src/lib.rs @@ -9,9 +9,9 @@ pub use feature_flags_contract; pub use masternode_reward_shares_contract; use platform_value::Identifier; use platform_version::version::PlatformVersion; +pub use token_history_contract; pub use wallet_utils_contract; pub use withdrawals_contract; -pub use token_history_contract; #[repr(u8)] #[derive(PartialEq, Eq, Clone, Copy, Debug, Ord, PartialOrd, Hash)] diff --git a/packages/rs-dpp/src/data_contract/accessors/v1/mod.rs b/packages/rs-dpp/src/data_contract/accessors/v1/mod.rs index 57a3212cef2..78a0df7a9b7 100644 --- a/packages/rs-dpp/src/data_contract/accessors/v1/mod.rs +++ b/packages/rs-dpp/src/data_contract/accessors/v1/mod.rs @@ -2,8 +2,8 @@ use crate::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0S use crate::data_contract::associated_token::token_configuration::TokenConfiguration; use crate::data_contract::group::{Group, GroupName}; use crate::data_contract::TokenContractPosition; -use std::collections::BTreeMap; use platform_value::Identifier; +use std::collections::BTreeMap; pub trait DataContractV1Getters: DataContractV0Getters { /// Returns a reference to the groups map. @@ -17,7 +17,7 @@ pub trait DataContractV1Getters: DataContractV0Getters { /// Returns a mutable reference to the tokens map. fn tokens_mut(&mut self) -> Option<&mut BTreeMap>; - + /// Returns the token id at a certain position fn token_id(&self, position: TokenContractPosition) -> Option; } diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs index 8c51014c0a6..580288845c6 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs @@ -34,6 +34,13 @@ impl TokenConfigurationV0Getters for TokenConfiguration { } } + /// Returns if we keep history. + fn keeps_history(&self) -> bool { + match self { + TokenConfiguration::V0(v0) => v0.keeps_history(), + } + } + /// Returns the maximum supply. fn max_supply(&self) -> Option { match self { diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs index 866a400658b..a08b4590185 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs @@ -1,4 +1,5 @@ use crate::data_contract::associated_token::token_configuration::v0::TokenConfigurationConventionV0; +use crate::data_contract::associated_token::token_configuration::TokenConfiguration; use crate::data_contract::change_control_rules::authorized_action_takers::AuthorizedActionTakers; use crate::data_contract::change_control_rules::ChangeControlRules; use crate::data_contract::group::RequiredSigners; @@ -15,6 +16,8 @@ pub trait TokenConfigurationV0Getters { /// Returns the base supply. fn base_supply(&self) -> u64; + /// Returns the base supply. + fn keeps_history(&self) -> bool; /// Returns the maximum supply. fn max_supply(&self) -> Option; diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs index 538297c5782..c93436316f2 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs @@ -27,6 +27,11 @@ impl TokenConfigurationV0Getters for TokenConfigurationV0 { self.base_supply } + /// Returns if we keep history. + fn keeps_history(&self) -> bool { + self.keeps_history + } + /// Returns the maximum supply. fn max_supply(&self) -> Option { self.max_supply diff --git a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs index af7b3052212..d6f32abdf25 100644 --- a/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs +++ b/packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs @@ -1,6 +1,7 @@ mod accessors; use crate::data_contract::change_control_rules::authorized_action_takers::AuthorizedActionTakers; +use crate::data_contract::change_control_rules::v0::ChangeControlRulesV0; use crate::data_contract::change_control_rules::ChangeControlRules; use crate::data_contract::group::RequiredSigners; use crate::identity::state_transition::asset_lock_proof::{Decode, Encode}; @@ -8,7 +9,6 @@ use platform_value::Identifier; use serde::{Deserialize, Serialize}; use std::collections::{BTreeMap, BTreeSet}; use std::fmt; -use crate::data_contract::change_control_rules::v0::ChangeControlRulesV0; #[derive(Serialize, Deserialize, Decode, Encode, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] @@ -33,6 +33,8 @@ pub struct TokenConfigurationV0 { pub base_supply: u64, /// The maximum supply the token can ever have pub max_supply: Option, + /// Do we keep history, default is true. + pub keeps_history: bool, /// Who can change the max supply /// Even if set no one can ever change this under the base supply pub max_supply_change_rules: ChangeControlRules, @@ -71,46 +73,56 @@ impl fmt::Display for TokenConfigurationV0 { impl TokenConfigurationV0 { pub fn default_most_restrictive() -> Self { Self { - conventions: TokenConfigurationConventionV0 { localizations: Default::default(), decimals: 8 }, + conventions: TokenConfigurationConventionV0 { + localizations: Default::default(), + decimals: 8, + }, base_supply: 100000, max_supply: None, + keeps_history: true, max_supply_change_rules: ChangeControlRulesV0 { authorized_to_make_change: AuthorizedActionTakers::NoOne, authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne, changing_authorized_action_takers_to_no_one_allowed: false, changing_authorized_action_takers_to_contract_owner_allowed: false, - }.into(), + } + .into(), new_tokens_destination_identity: None, new_tokens_destination_identity_rules: ChangeControlRulesV0 { authorized_to_make_change: AuthorizedActionTakers::NoOne, authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne, changing_authorized_action_takers_to_no_one_allowed: false, changing_authorized_action_takers_to_contract_owner_allowed: false, - }.into(), + } + .into(), manual_minting_rules: ChangeControlRulesV0 { authorized_to_make_change: AuthorizedActionTakers::NoOne, authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne, changing_authorized_action_takers_to_no_one_allowed: false, changing_authorized_action_takers_to_contract_owner_allowed: false, - }.into(), + } + .into(), manual_burning_rules: ChangeControlRulesV0 { authorized_to_make_change: AuthorizedActionTakers::NoOne, authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne, changing_authorized_action_takers_to_no_one_allowed: false, changing_authorized_action_takers_to_contract_owner_allowed: false, - }.into(), + } + .into(), freeze_rules: ChangeControlRulesV0 { authorized_to_make_change: AuthorizedActionTakers::NoOne, authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne, changing_authorized_action_takers_to_no_one_allowed: false, changing_authorized_action_takers_to_contract_owner_allowed: false, - }.into(), + } + .into(), unfreeze_rules: ChangeControlRulesV0 { authorized_to_make_change: AuthorizedActionTakers::NoOne, authorized_to_change_authorized_action_takers: AuthorizedActionTakers::NoOne, changing_authorized_action_takers_to_no_one_allowed: false, changing_authorized_action_takers_to_contract_owner_allowed: false, - }.into(), + } + .into(), main_control_group: None, main_control_group_can_be_modified: AuthorizedActionTakers::NoOne, } diff --git a/packages/rs-dpp/src/data_contract/v1/accessors/mod.rs b/packages/rs-dpp/src/data_contract/v1/accessors/mod.rs index b84eefccf4f..07e0e597aa3 100644 --- a/packages/rs-dpp/src/data_contract/v1/accessors/mod.rs +++ b/packages/rs-dpp/src/data_contract/v1/accessors/mod.rs @@ -11,9 +11,9 @@ use crate::data_contract::accessors::v1::{DataContractV1Getters, DataContractV1S use crate::data_contract::associated_token::token_configuration::TokenConfiguration; use crate::data_contract::document_type::accessors::DocumentTypeV0Getters; use crate::data_contract::group::{Group, GroupName}; +use crate::util::hash::hash_double; use platform_value::Identifier; use std::collections::BTreeMap; -use crate::util::hash::hash_double; impl DataContractV0Getters for DataContractV1 { fn id(&self) -> Identifier { diff --git a/packages/rs-dpp/src/document/generate_document_id.rs b/packages/rs-dpp/src/document/generate_document_id.rs index b14fc599a44..96d4af68c17 100644 --- a/packages/rs-dpp/src/document/generate_document_id.rs +++ b/packages/rs-dpp/src/document/generate_document_id.rs @@ -1,4 +1,5 @@ use crate::document::Document; +use crate::prelude::IdentityNonce; use crate::{prelude::Identifier, util::hash::hash_double_to_vec}; impl Document { diff --git a/packages/rs-dpp/src/lib.rs b/packages/rs-dpp/src/lib.rs index 302a6d10047..de0c10f6c47 100644 --- a/packages/rs-dpp/src/lib.rs +++ b/packages/rs-dpp/src/lib.rs @@ -88,6 +88,15 @@ pub mod prelude { pub type Revision = u64; pub type IdentityNonce = u64; + pub type SenderKeyIndex = u32; + pub type RecipientKeyIndex = u32; + + /// The index of the user's key that is used to derive keys that will be used to encrypt the contact's user id in encToUserId and the private data. + pub type RootEncryptionKeyIndex = u32; + + /// The index at which to derive the root encryption key. + pub type DerivationEncryptionKeyIndex = u32; + /// UserFeeIncrease is the additional percentage of the processing fee. /// A 1 here means we pay 1% more in processing fees. A 100 means we pay 100% more. pub type UserFeeIncrease = u16; diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0/mod.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0/mod.rs index dfdb4d57269..dc07a538271 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0/mod.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0/mod.rs @@ -23,7 +23,16 @@ pub struct TokenBurnTransitionV0 { /// Document Base Transition #[cfg_attr(feature = "state-transition-serde-conversion", serde(flatten))] pub base: TokenBaseTransition, - + #[cfg_attr( + feature = "state-transition-serde-conversion", + serde(rename = "burnAmount") + )] /// How much should we burn pub burn_amount: u64, + /// The public note + #[cfg_attr( + feature = "state-transition-serde-conversion", + serde(rename = "publicNote") + )] + pub public_note: Option, } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0/v0_methods.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0/v0_methods.rs index 7f9f99fbfa4..dcf6d104a22 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0/v0_methods.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0/v0_methods.rs @@ -20,6 +20,15 @@ pub trait TokenBurnTransitionV0Methods: TokenBaseTransitionAccessors { fn burn_amount(&self) -> u64; fn set_burn_amount(&mut self, amount: u64); + + /// Returns the `public_note` field of the `TokenBurnTransitionV0`. + fn public_note(&self) -> Option<&String>; + + /// Returns the owned `public_note` field of the `TokenBurnTransitionV0`. + fn public_note_owned(self) -> Option; + + /// Sets the `public_note` field in the `TokenBurnTransitionV0`. + fn set_public_note(&mut self, public_note: Option); } impl TokenBurnTransitionV0Methods for TokenBurnTransitionV0 { @@ -30,4 +39,16 @@ impl TokenBurnTransitionV0Methods for TokenBurnTransitionV0 { fn set_burn_amount(&mut self, amount: u64) { self.burn_amount = amount; } + + fn public_note(&self) -> Option<&String> { + self.public_note.as_ref() + } + + fn public_note_owned(self) -> Option { + self.public_note + } + + fn set_public_note(&mut self, public_note: Option) { + self.public_note = public_note; + } } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0_methods.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0_methods.rs index a34139c10e6..4c83f78232f 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0_methods.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_burn_transition/v0_methods.rs @@ -35,4 +35,22 @@ impl TokenBurnTransitionV0Methods for TokenBurnTransition { TokenBurnTransition::V0(v0) => v0.set_burn_amount(burn_amount), } } + + fn public_note(&self) -> Option<&String> { + match self { + TokenBurnTransition::V0(v0) => v0.public_note(), + } + } + + fn public_note_owned(self) -> Option { + match self { + TokenBurnTransition::V0(v0) => v0.public_note_owned(), + } + } + + fn set_public_note(&mut self, public_note: Option) { + match self { + TokenBurnTransition::V0(v0) => v0.set_public_note(public_note), + } + } } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0/mod.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0/mod.rs index fe20c85bb72..2e4d17a6ebf 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0/mod.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0/mod.rs @@ -24,13 +24,22 @@ pub struct TokenIssuanceTransitionV0 { /// Document Base Transition #[cfg_attr(feature = "state-transition-serde-conversion", serde(flatten))] pub base: TokenBaseTransition, - + #[cfg_attr( + feature = "state-transition-serde-conversion", + serde(rename = "issuedToIdentityId") + )] /// Who should we issue the token to? If this is not set then we issue to the identity set in /// contract settings. If such an operation is allowed. pub issued_to_identity_id: Option, /// How much should we issue pub amount: u64, + /// The public note + #[cfg_attr( + feature = "state-transition-serde-conversion", + serde(rename = "publicNote") + )] + pub public_note: Option, } impl fmt::Display for TokenIssuanceTransitionV0 { diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0/v0_methods.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0/v0_methods.rs index f8c21f9b18e..5f24acc145b 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0/v0_methods.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0/v0_methods.rs @@ -1,3 +1,4 @@ +use platform_value::Identifier; use crate::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use crate::state_transition::batch_transition::token_base_transition::TokenBaseTransition; use crate::state_transition::batch_transition::token_issuance_transition::TokenIssuanceTransitionV0; @@ -20,6 +21,21 @@ pub trait TokenIssuanceTransitionV0Methods: TokenBaseTransitionAccessors { fn amount(&self) -> u64; fn set_amount(&mut self, amount: u64); + + /// Returns the `public_note` field of the `TokenIssuanceTransitionV0`. + fn public_note(&self) -> Option<&String>; + + /// Returns the owned `public_note` field of the `TokenIssuanceTransitionV0`. + fn public_note_owned(self) -> Option; + + /// Sets the value of the `public_note` field in the `TokenIssuanceTransitionV0`. + fn set_public_note(&mut self, public_note: Option); + + /// Returns the `issued_to_identity_id` field of the `TokenIssuanceTransitionV0`. + fn issued_to_identity_id(&self) -> Option; + + /// Sets the value of the `issued_to_identity_id` field in the `TokenIssuanceTransitionV0`. + fn set_issued_to_identity_id(&mut self, issued_to_identity_id: Option); } impl TokenIssuanceTransitionV0Methods for TokenIssuanceTransitionV0 { @@ -30,4 +46,23 @@ impl TokenIssuanceTransitionV0Methods for TokenIssuanceTransitionV0 { fn set_amount(&mut self, amount: u64) { self.amount = amount; } + + fn public_note(&self) -> Option<&String> { + self.public_note.as_ref() + } + + fn public_note_owned(self) -> Option { + self.public_note + } + + fn set_public_note(&mut self, public_note: Option) { + self.public_note = public_note; + } + + fn issued_to_identity_id(&self) -> Option { + self.issued_to_identity_id + } + fn set_issued_to_identity_id(&mut self, issued_to_identity_id: Option) { + self.issued_to_identity_id = issued_to_identity_id; + } } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0_methods.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0_methods.rs index fa3137f0222..71b228a35ae 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0_methods.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_issuance_transition/v0_methods.rs @@ -1,3 +1,4 @@ +use platform_value::Identifier; use crate::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use crate::state_transition::batch_transition::token_base_transition::TokenBaseTransition; use crate::state_transition::batch_transition::token_issuance_transition::TokenIssuanceTransition; @@ -35,4 +36,34 @@ impl TokenIssuanceTransitionV0Methods for TokenIssuanceTransition { TokenIssuanceTransition::V0(v0) => v0.set_amount(amount), } } + + fn public_note(&self) -> Option<&String> { + match self { + TokenIssuanceTransition::V0(v0) => v0.public_note(), + } + } + + fn public_note_owned(self) -> Option { + match self { + TokenIssuanceTransition::V0(v0) => v0.public_note_owned(), + } + } + + fn set_public_note(&mut self, public_note: Option) { + match self { + TokenIssuanceTransition::V0(v0) => v0.set_public_note(public_note), + } + } + + fn issued_to_identity_id(&self) -> Option { + match self { + TokenIssuanceTransition::V0(v0) => v0.issued_to_identity_id(), + } + } + + fn set_issued_to_identity_id(&mut self, issued_to_identity_id: Option) { + match self { + TokenIssuanceTransition::V0(v0) => v0.set_issued_to_identity_id(issued_to_identity_id), + } + } } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/mod.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/mod.rs index b2e140b8122..f3d3d00a52e 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/mod.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/mod.rs @@ -3,13 +3,15 @@ pub mod v0_methods; use bincode::{Decode, Encode}; use derive_more::Display; +pub use super::super::token_base_transition::IDENTIFIER_FIELDS; +use crate::prelude::{ + DerivationEncryptionKeyIndex, RecipientKeyIndex, RootEncryptionKeyIndex, SenderKeyIndex, +}; +use crate::state_transition::batch_transition::token_base_transition::TokenBaseTransition; use platform_value::Identifier; #[cfg(feature = "state-transition-serde-conversion")] use serde::{Deserialize, Serialize}; -pub use super::super::token_base_transition::IDENTIFIER_FIELDS; -use crate::state_transition::batch_transition::token_base_transition::TokenBaseTransition; - mod property_names { pub const AMOUNT: &str = "$amount"; pub const RECIPIENT_OWNER_ID: &str = "recipientOwnerId"; @@ -40,4 +42,26 @@ pub struct TokenTransferTransitionV0 { serde(rename = "recipientOwnerId") )] pub recipient_owner_id: Identifier, + /// The public note + #[cfg_attr( + feature = "state-transition-serde-conversion", + serde(rename = "publicNote") + )] + pub public_note: Option, + /// An optional shared encrypted note + #[cfg_attr( + feature = "state-transition-serde-conversion", + serde(rename = "sharedEncryptedNote") + )] + pub shared_encrypted_note: Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + /// An optional private encrypted note + #[cfg_attr( + feature = "state-transition-serde-conversion", + serde(rename = "privateEncryptedNote") + )] + pub private_encrypted_note: Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/v0_methods.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/v0_methods.rs index afa066cea39..22762c4bbda 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/v0_methods.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/v0_methods.rs @@ -1,5 +1,5 @@ use platform_value::Identifier; - +use crate::prelude::{DerivationEncryptionKeyIndex, RecipientKeyIndex, RootEncryptionKeyIndex, SenderKeyIndex}; use crate::state_transition::batch_transition::batched_transition::token_transfer_transition::TokenTransferTransitionV0; use crate::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use crate::state_transition::batch_transition::token_base_transition::TokenBaseTransition; @@ -19,20 +19,82 @@ impl TokenBaseTransitionAccessors for TokenTransferTransitionV0 { } pub trait TokenTransferTransitionV0Methods: TokenBaseTransitionAccessors { - /// Returns a reference to the `revision` field of the `DocumentReplaceTransitionV0`. + /// Returns the `amount` field of the `TokenTransferTransitionV0`. fn amount(&self) -> u64; - /// Sets the value of the `revision` field in the `DocumentReplaceTransitionV0`. + /// Sets the value of the `amount` field in the `TokenTransferTransitionV0`. fn set_amount(&mut self, amount: u64); - /// Returns the `recipient_owner_id` field of the `DocumentReplaceTransitionV0`. + /// Returns the `recipient_owner_id` field of the `TokenTransferTransitionV0`. fn recipient_owner_id(&self) -> Identifier; - /// Returns a reference to the `recipient_owner_id` field of the `DocumentReplaceTransitionV0`. + /// Returns a reference to the `recipient_owner_id` field of the `TokenTransferTransitionV0`. fn recipient_owner_id_ref(&self) -> &Identifier; - /// Sets the value of the `recipient_owner_id` field in the `DocumentReplaceTransitionV0`. + /// Sets the value of the `recipient_owner_id` field in the `TokenTransferTransitionV0`. fn set_recipient_owner_id(&mut self, recipient_owner_id: Identifier); + + /// Returns the `public_note` field of the `TokenTransferTransitionV0`. + fn public_note(&self) -> Option<&String>; + + /// Returns the owned `public_note` field of the `TokenTransferTransitionV0`. + fn public_note_owned(self) -> Option; + + /// Sets the value of the `public_note` field in the `TokenTransferTransitionV0`. + fn set_public_note(&mut self, public_note: Option); + + /// Returns the `shared_encrypted_note` field of the `TokenTransferTransitionV0`. + fn shared_encrypted_note(&self) -> Option<&(SenderKeyIndex, RecipientKeyIndex, Vec)>; + + /// Returns the owned `shared_encrypted_note` field of the `TokenTransferTransitionV0`. + fn shared_encrypted_note_owned(self) -> Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>; + + /// Sets the value of the `shared_encrypted_note` field in the `TokenTransferTransitionV0`. + fn set_shared_encrypted_note( + &mut self, + shared_encrypted_note: Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + ); + + /// Returns the `private_encrypted_note` field of the `TokenTransferTransitionV0`. + fn private_encrypted_note( + &self, + ) -> Option<&( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>; + + /// Returns the owned `private_encrypted_note` field of the `TokenTransferTransitionV0`. + fn private_encrypted_note_owned( + self, + ) -> Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>; + + /// Sets the value of the `private_encrypted_note` field in the `TokenTransferTransitionV0`. + fn set_private_encrypted_note( + &mut self, + private_encrypted_note: Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ); + + /// Returns all notes (public, shared, and private) as owned values in a tuple. + fn notes_owned( + self, + ) -> ( + Option, + Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ); } impl TokenTransferTransitionV0Methods for TokenTransferTransitionV0 { @@ -55,4 +117,79 @@ impl TokenTransferTransitionV0Methods for TokenTransferTransitionV0 { fn set_recipient_owner_id(&mut self, recipient_owner_id: Identifier) { self.recipient_owner_id = recipient_owner_id; } + fn public_note(&self) -> Option<&String> { + self.public_note.as_ref() + } + + fn public_note_owned(self) -> Option { + self.public_note + } + + fn set_public_note(&mut self, public_note: Option) { + self.public_note = public_note; + } + + fn shared_encrypted_note(&self) -> Option<&(SenderKeyIndex, RecipientKeyIndex, Vec)> { + self.shared_encrypted_note.as_ref() + } + + fn shared_encrypted_note_owned(self) -> Option<(SenderKeyIndex, RecipientKeyIndex, Vec)> { + self.shared_encrypted_note + } + + fn set_shared_encrypted_note( + &mut self, + shared_encrypted_note: Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + ) { + self.shared_encrypted_note = shared_encrypted_note; + } + + fn private_encrypted_note( + &self, + ) -> Option<&( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )> { + self.private_encrypted_note.as_ref() + } + + fn private_encrypted_note_owned( + self, + ) -> Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )> { + self.private_encrypted_note + } + + fn set_private_encrypted_note( + &mut self, + private_encrypted_note: Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ) { + self.private_encrypted_note = private_encrypted_note; + } + + fn notes_owned( + self, + ) -> ( + Option, + Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ) { + ( + self.public_note, + self.shared_encrypted_note, + self.private_encrypted_note, + ) + } } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0_methods.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0_methods.rs index 9e0a0617d80..c6423015997 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0_methods.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0_methods.rs @@ -1,4 +1,5 @@ use platform_value::Identifier; +use crate::prelude::{DerivationEncryptionKeyIndex, RecipientKeyIndex, RootEncryptionKeyIndex, SenderKeyIndex}; use crate::state_transition::batch_transition::batched_transition::token_transfer_transition::v0::v0_methods::TokenTransferTransitionV0Methods; use crate::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use crate::state_transition::batch_transition::TokenTransferTransition; @@ -54,4 +55,102 @@ impl TokenTransferTransitionV0Methods for TokenTransferTransition { TokenTransferTransition::V0(v0) => v0.recipient_owner_id = recipient_owner_id, } } + + // Methods for `public_note` + fn public_note(&self) -> Option<&String> { + match self { + TokenTransferTransition::V0(v0) => v0.public_note.as_ref(), + } + } + + fn public_note_owned(self) -> Option { + match self { + TokenTransferTransition::V0(v0) => v0.public_note, + } + } + + fn set_public_note(&mut self, public_note: Option) { + match self { + TokenTransferTransition::V0(v0) => v0.public_note = public_note, + } + } + + fn shared_encrypted_note(&self) -> Option<&(SenderKeyIndex, RecipientKeyIndex, Vec)> { + match self { + TokenTransferTransition::V0(v0) => v0.shared_encrypted_note.as_ref(), + } + } + + fn shared_encrypted_note_owned(self) -> Option<(SenderKeyIndex, RecipientKeyIndex, Vec)> { + match self { + TokenTransferTransition::V0(v0) => v0.shared_encrypted_note, + } + } + + fn set_shared_encrypted_note( + &mut self, + shared_encrypted_note: Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + ) { + match self { + TokenTransferTransition::V0(v0) => v0.shared_encrypted_note = shared_encrypted_note, + } + } + + fn private_encrypted_note( + &self, + ) -> Option<&( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )> { + match self { + TokenTransferTransition::V0(v0) => v0.private_encrypted_note.as_ref(), + } + } + + fn private_encrypted_note_owned( + self, + ) -> Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )> { + match self { + TokenTransferTransition::V0(v0) => v0.private_encrypted_note, + } + } + + fn set_private_encrypted_note( + &mut self, + private_encrypted_note: Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ) { + match self { + TokenTransferTransition::V0(v0) => v0.private_encrypted_note = private_encrypted_note, + } + } + + // Method to return all notes as owned values + fn notes_owned( + self, + ) -> ( + Option, + Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ) { + match self { + TokenTransferTransition::V0(v0) => ( + v0.public_note, + v0.shared_encrypted_note, + v0.private_encrypted_note, + ), + } + } } diff --git a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/value_conversion.rs b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/value_conversion.rs index a53a64ff534..e9d975ea47b 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/value_conversion.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/value_conversion.rs @@ -4,7 +4,9 @@ use platform_value::Value; use crate::ProtocolError; -use crate::state_transition::batch_transition::{BatchTransition, BatchTransitionV0, BatchTransitionV1}; +use crate::state_transition::batch_transition::{ + BatchTransition, BatchTransitionV0, BatchTransitionV1, +}; use crate::state_transition::state_transitions::batch_transition::fields::*; use crate::state_transition::StateTransitionValueConvert; diff --git a/packages/rs-dpp/src/tokens/mod.rs b/packages/rs-dpp/src/tokens/mod.rs index 1980cdf712f..f5325ea4371 100644 --- a/packages/rs-dpp/src/tokens/mod.rs +++ b/packages/rs-dpp/src/tokens/mod.rs @@ -1,2 +1,3 @@ pub mod allowed_currency; pub mod errors; +pub mod token_event; diff --git a/packages/rs-dpp/src/tokens/token_event.rs b/packages/rs-dpp/src/tokens/token_event.rs new file mode 100644 index 00000000000..8a3d3a6c0ff --- /dev/null +++ b/packages/rs-dpp/src/tokens/token_event.rs @@ -0,0 +1,26 @@ +use crate::balances::credits::TokenAmount; +use crate::prelude::{ + DerivationEncryptionKeyIndex, RecipientKeyIndex, RootEncryptionKeyIndex, SenderKeyIndex, +}; +use platform_value::Identifier; + +pub type TokenEventPublicNote = Option; +pub type TokenEventSharedEncryptedNote = Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>; +pub type TokenEventPersonalEncryptedNote = Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, +)>; + +#[derive(Debug, PartialEq, PartialOrd, Clone, Eq)] +pub enum TokenEvent { + Mint(TokenAmount, TokenEventPublicNote), + Burn(TokenAmount, TokenEventPublicNote), + Transfer( + Identifier, + TokenEventPublicNote, + TokenEventSharedEncryptedNote, + TokenEventPersonalEncryptedNote, + TokenAmount, + ), +} diff --git a/packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs index 8bf290565d1..46a0590c01c 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs @@ -111,7 +111,7 @@ impl Platform { None, &platform_version.drive, )?; - + let contract = load_system_data_contract(SystemDataContract::TokenHistory, platform_version)?; @@ -126,7 +126,6 @@ impl Platform { Ok(()) } - /// Initializes an empty sum tree for withdrawal transactions required for protocol version 4. /// /// This function is called during the transition to protocol version 4 to set up diff --git a/packages/rs-drive/src/cache/system_contracts.rs b/packages/rs-drive/src/cache/system_contracts.rs index c1a2785c3c4..7de44da36bd 100644 --- a/packages/rs-drive/src/cache/system_contracts.rs +++ b/packages/rs-drive/src/cache/system_contracts.rs @@ -15,6 +15,8 @@ pub struct SystemDataContracts { dashpay: ArcSwap, /// Masternode reward shares contract masternode_reward_shares: ArcSwap, + /// Token history contract + token_history: ArcSwap, } impl SystemDataContracts { @@ -39,6 +41,10 @@ impl SystemDataContracts { SystemDataContract::MasternodeRewards, platform_version, )?), + token_history: ArcSwap::from_pointee(load_system_data_contract( + SystemDataContract::TokenHistory, + platform_version, + )?), }) } @@ -47,6 +53,11 @@ impl SystemDataContracts { self.withdrawals.load() } + /// Returns token history contract + pub fn load_token_history(&self) -> Guard> { + self.token_history.load() + } + /// Returns DPNS contract pub fn load_dpns(&self) -> Guard> { self.dpns.load() diff --git a/packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs b/packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs index 37d4ebd9fc3..a413dc7ed28 100644 --- a/packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs +++ b/packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs @@ -9,17 +9,17 @@ use dpp::data_contract::config::v0::DataContractConfigGettersV0; use dpp::data_contract::DataContract; use dpp::fee::fee_result::FeeResult; -use dpp::serialization::PlatformSerializableWithPlatformVersion; +use crate::drive::balances::total_tokens_root_supply_path; +use crate::drive::tokens::{token_path, tokens_root_path, TOKEN_BALANCES_KEY}; use crate::error::contract::DataContractError; +use crate::util::grove_operations::BatchInsertTreeApplyType; +use crate::util::object_size_info::DriveKeyInfo; +use dpp::data_contract::accessors::v1::DataContractV1Getters; +use dpp::serialization::PlatformSerializableWithPlatformVersion; use dpp::version::PlatformVersion; use grovedb::batch::KeyInfoPath; use grovedb::{Element, EstimatedLayerInformation, TransactionArg}; use std::collections::HashMap; -use dpp::data_contract::accessors::v1::DataContractV1Getters; -use crate::drive::balances::total_tokens_root_supply_path; -use crate::drive::tokens::{TOKEN_BALANCES_KEY, token_path, tokens_root_path}; -use crate::util::grove_operations::BatchInsertTreeApplyType; -use crate::util::object_size_info::DriveKeyInfo; impl Drive { /// Insert a contract. @@ -152,10 +152,22 @@ impl Drive { >, platform_version: &PlatformVersion, ) -> Result, Error> { - let mut batch_operations: Vec = self.insert_contract_operations_v0(contract_element, contract, block_info, estimated_costs_only_with_layer_info, platform_version)?; - + let mut batch_operations: Vec = self + .insert_contract_operations_v0( + contract_element, + contract, + block_info, + estimated_costs_only_with_layer_info, + platform_version, + )?; + for token_pos in contract.tokens().keys() { - let token_id = contract.token_id(*token_pos).ok_or(Error::DataContract(DataContractError::CorruptedDataContract(format!("data contract has a token at position {}, but can not find it", token_pos))))?; + let token_id = contract.token_id(*token_pos).ok_or(Error::DataContract( + DataContractError::CorruptedDataContract(format!( + "data contract has a token at position {}, but can not find it", + token_pos + )), + ))?; self.batch_insert_empty_tree( tokens_root_path(), @@ -181,7 +193,7 @@ impl Drive { &platform_version.drive, )?; } - + Ok(batch_operations) } } diff --git a/packages/rs-drive/src/drive/contract/update/update_contract/v1/mod.rs b/packages/rs-drive/src/drive/contract/update/update_contract/v1/mod.rs index fadf485b670..460055f9036 100644 --- a/packages/rs-drive/src/drive/contract/update/update_contract/v1/mod.rs +++ b/packages/rs-drive/src/drive/contract/update/update_contract/v1/mod.rs @@ -16,14 +16,14 @@ use dpp::fee::fee_result::FeeResult; use dpp::data_contract::document_type::methods::DocumentTypeV0Methods; use dpp::serialization::PlatformSerializableWithPlatformVersion; +use crate::drive::tokens::{token_path, tokens_root_path, TOKEN_BALANCES_KEY}; +use crate::error::contract::DataContractError; +use dpp::data_contract::accessors::v1::DataContractV1Getters; use dpp::fee::default_costs::CachedEpochIndexFeeVersions; use dpp::version::PlatformVersion; use grovedb::batch::KeyInfoPath; use grovedb::{Element, EstimatedLayerInformation, TransactionArg}; use std::collections::{HashMap, HashSet}; -use dpp::data_contract::accessors::v1::DataContractV1Getters; -use crate::drive::tokens::{TOKEN_BALANCES_KEY, token_path, tokens_root_path}; -use crate::error::contract::DataContractError; impl Drive { /// Updates a data contract. @@ -213,12 +213,33 @@ impl Drive { transaction: TransactionArg, platform_version: &PlatformVersion, ) -> Result, Error> { - let mut batch_operations: Vec = self.update_contract_operations_v0(contract_element, contract, original_contract, block_info, estimated_costs_only_with_layer_info, transaction, platform_version)?; + let mut batch_operations: Vec = self + .update_contract_operations_v0( + contract_element, + contract, + original_contract, + block_info, + estimated_costs_only_with_layer_info, + transaction, + platform_version, + )?; for token_pos in contract.tokens().keys() { - let token_id = contract.token_id(*token_pos).ok_or(Error::DataContract(DataContractError::CorruptedDataContract(format!("data contract has a token at position {}, but can not find it", token_pos))))?; - - batch_operations.extend(self.create_token_trees_operations(token_id.to_buffer(), true, &mut None, estimated_costs_only_with_layer_info, transaction, platform_version)?); + let token_id = contract.token_id(*token_pos).ok_or(Error::DataContract( + DataContractError::CorruptedDataContract(format!( + "data contract has a token at position {}, but can not find it", + token_pos + )), + ))?; + + batch_operations.extend(self.create_token_trees_operations( + token_id.to_buffer(), + true, + &mut None, + estimated_costs_only_with_layer_info, + transaction, + platform_version, + )?); } Ok(batch_operations) } diff --git a/packages/rs-drive/src/drive/initialization/v0/mod.rs b/packages/rs-drive/src/drive/initialization/v0/mod.rs index 8736d42d25b..daa41b1c243 100644 --- a/packages/rs-drive/src/drive/initialization/v0/mod.rs +++ b/packages/rs-drive/src/drive/initialization/v0/mod.rs @@ -26,7 +26,8 @@ impl Drive { // On lower layers we can use batching - let batch = self.create_initial_state_structure_lower_layers_operations_0(platform_version)?; + let batch = + self.create_initial_state_structure_lower_layers_operations_0(platform_version)?; self.grove_apply_batch(batch, false, transaction, drive_version)?; @@ -206,7 +207,7 @@ impl Drive { // For the votes tree structure Drive::add_initial_vote_tree_main_structure_operations(&mut batch, platform_version)?; - + Ok(batch) } } diff --git a/packages/rs-drive/src/drive/initialization/v1/mod.rs b/packages/rs-drive/src/drive/initialization/v1/mod.rs index d0d16a7962e..80b893444ac 100644 --- a/packages/rs-drive/src/drive/initialization/v1/mod.rs +++ b/packages/rs-drive/src/drive/initialization/v1/mod.rs @@ -8,9 +8,12 @@ use crate::drive::Drive; use crate::error::Error; use crate::util::batch::grovedb_op_batch::GroveDbOpBatchV0Methods; +use crate::drive::identity::withdrawals::paths::{ + get_withdrawal_root_path_vec, WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY, + WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY, +}; use dpp::version::PlatformVersion; use grovedb::{Element, TransactionArg}; -use crate::drive::identity::withdrawals::paths::{get_withdrawal_root_path_vec, WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY, WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY}; impl Drive { /// Creates the initial state structure. @@ -24,8 +27,9 @@ impl Drive { // On lower layers we can use batching - let mut batch = self.create_initial_state_structure_lower_layers_operations_0(platform_version)?; - + let mut batch = + self.create_initial_state_structure_lower_layers_operations_0(platform_version)?; + self.initial_state_structure_lower_layers_add_operations_1(&mut batch, platform_version)?; self.grove_apply_batch(batch, false, transaction, drive_version)?; @@ -39,7 +43,6 @@ impl Drive { batch: &mut GroveDbOpBatch, _platform_version: &PlatformVersion, ) -> Result<(), Error> { - // In Misc batch.add_insert( misc_path_vec(), @@ -61,7 +64,7 @@ impl Drive { WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY.to_vec(), Element::empty_tree(), ); - + Ok(()) } } diff --git a/packages/rs-drive/src/drive/tokens/add_transaction_history/mod.rs b/packages/rs-drive/src/drive/tokens/add_transaction_history/mod.rs deleted file mode 100644 index e084dffc38f..00000000000 --- a/packages/rs-drive/src/drive/tokens/add_transaction_history/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod v0; diff --git a/packages/rs-drive/src/drive/tokens/add_transaction_history/v0/mod.rs b/packages/rs-drive/src/drive/tokens/add_transaction_history/v0/mod.rs deleted file mode 100644 index 8b137891791..00000000000 --- a/packages/rs-drive/src/drive/tokens/add_transaction_history/v0/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/rs-drive/src/drive/tokens/add_transaction_history_operations/mod.rs b/packages/rs-drive/src/drive/tokens/add_transaction_history_operations/mod.rs new file mode 100644 index 00000000000..c7682b7dcde --- /dev/null +++ b/packages/rs-drive/src/drive/tokens/add_transaction_history_operations/mod.rs @@ -0,0 +1,56 @@ +use crate::drive::Drive; +use crate::error::drive::DriveError; +use crate::error::Error; +use crate::fees::op::LowLevelDriveOperation; +use dpp::block::block_info::BlockInfo; +use dpp::fee::fee_result::FeeResult; +use dpp::identifier::Identifier; +use dpp::prelude::IdentityNonce; +use dpp::tokens::token_event::TokenEvent; +use grovedb::batch::KeyInfoPath; +use grovedb::{EstimatedLayerInformation, TransactionArg}; +use platform_version::version::PlatformVersion; +use std::collections::HashMap; + +mod v0; + +impl Drive { + /// Adds token transaction history + pub fn add_token_transaction_history_operations( + &self, + token_id: Identifier, + owner_id: Identifier, + owner_nonce: IdentityNonce, + event: TokenEvent, + block_info: &BlockInfo, + estimated_costs_only_with_layer_info: &mut Option< + HashMap, + >, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result, Error> { + match platform_version + .drive + .methods + .token + .update + .add_transaction_history_operations + { + 0 => self.add_token_transaction_history_operations_v0( + token_id, + owner_id, + owner_nonce, + event, + block_info, + estimated_costs_only_with_layer_info, + transaction, + platform_version, + ), + version => Err(Error::Drive(DriveError::UnknownVersionMismatch { + method: "add_token_transaction_history_operations".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive/src/drive/tokens/add_transaction_history_operations/v0/mod.rs b/packages/rs-drive/src/drive/tokens/add_transaction_history_operations/v0/mod.rs new file mode 100644 index 00000000000..3f5760b53db --- /dev/null +++ b/packages/rs-drive/src/drive/tokens/add_transaction_history_operations/v0/mod.rs @@ -0,0 +1,213 @@ +use crate::drive::Drive; +use crate::error::Error; +use crate::fees::op::LowLevelDriveOperation; +use crate::util::object_size_info::DocumentInfo::DocumentOwnedInfo; +use crate::util::object_size_info::{DocumentAndContractInfo, OwnedDocumentInfo}; +use dpp::block::block_info::BlockInfo; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::document::{Document, DocumentV0}; +use dpp::identifier::Identifier; +use dpp::prelude::IdentityNonce; +use dpp::tokens::token_event::TokenEvent; +use grovedb::batch::KeyInfoPath; +use grovedb::{EstimatedLayerInformation, TransactionArg}; +use platform_version::version::PlatformVersion; +use std::collections::{BTreeMap, HashMap}; + +impl Drive { + /// Adds token transaction history + pub(super) fn add_token_transaction_history_operations_v0( + &self, + token_id: Identifier, + owner_id: Identifier, + owner_nonce: IdentityNonce, + event: TokenEvent, + block_info: &BlockInfo, + estimated_costs_only_with_layer_info: &mut Option< + HashMap, + >, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result, Error> { + let operations; + + let contract = self.cache.system_data_contracts.load_token_history(); + + match event { + TokenEvent::Mint(mint_amount, public_note) => { + let document_type = contract.document_type_for_name("mint")?; + let document_id = Document::generate_document_id_v0( + &contract.id(), + &owner_id, + "mint", + owner_nonce.to_be_bytes().as_slice(), + ); + let mut properties = BTreeMap::from([ + ("tokenId".to_string(), token_id.into()), + ("amount".to_string(), mint_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: Some(block_info.core_height), + 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::Burn(burn_amount, public_note) => { + let document_type = contract.document_type_for_name("mint")?; + let document_id = Document::generate_document_id_v0( + &contract.id(), + &owner_id, + "burn", + owner_nonce.to_be_bytes().as_slice(), + ); + let mut properties = BTreeMap::from([ + ("tokenId".to_string(), token_id.into()), + ("amount".to_string(), burn_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: Some(block_info.core_height), + 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::Transfer( + to, + public_note, + token_event_shared_encrypted_note, + token_event_personal_encrypted_note, + amount, + ) => { + let document_type = contract.document_type_for_name("transfer")?; + let document_id = Document::generate_document_id_v0( + &contract.id(), + &owner_id, + "transfer", + owner_nonce.to_be_bytes().as_slice(), + ); + let mut properties = BTreeMap::from([ + ("tokenId".to_string(), token_id.into()), + ("amount".to_string(), amount.into()), + ("toIdentityId".to_string(), to.into()), + ]); + if let Some(note) = public_note { + properties.insert("publicNote".to_string(), note.into()); + } + if let Some((sender_key_index, recipient_key_index, note)) = + token_event_shared_encrypted_note + { + properties.insert("encryptedSharedNote".to_string(), note.into()); + properties.insert("senderKeyIndex".to_string(), sender_key_index.into()); + properties.insert("recipientKeyIndex".to_string(), recipient_key_index.into()); + } + + if let Some((root_encryption_key_index, derivation_encryption_key_index, note)) = + token_event_personal_encrypted_note + { + properties.insert("encryptedPersonalNote".to_string(), note.into()); + properties.insert( + "rootEncryptionKeyIndex".to_string(), + root_encryption_key_index.into(), + ); + properties.insert( + "derivationEncryptionKeyIndex".to_string(), + derivation_encryption_key_index.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: Some(block_info.core_height), + 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) + } +} diff --git a/packages/rs-drive/src/drive/tokens/balance/prove_identities_token_balances/v0/mod.rs b/packages/rs-drive/src/drive/tokens/balance/prove_identities_token_balances/v0/mod.rs index b81eea97b95..98d5e667bbc 100644 --- a/packages/rs-drive/src/drive/tokens/balance/prove_identities_token_balances/v0/mod.rs +++ b/packages/rs-drive/src/drive/tokens/balance/prove_identities_token_balances/v0/mod.rs @@ -40,23 +40,24 @@ impl Drive { } } - #[cfg(test)] mod tests { - use std::collections::BTreeMap; - use dpp::balances::credits::TokenAmount; use super::*; use crate::util::test_helpers::setup::setup_drive_with_initial_state_structure; + use dpp::balances::credits::TokenAmount; use dpp::block::block_info::BlockInfo; use dpp::data_contract::accessors::v1::DataContractV1Getters; + use dpp::data_contract::associated_token::token_configuration::v0::{ + TokenConfigurationConventionV0, TokenConfigurationV0, + }; use dpp::data_contract::associated_token::token_configuration::TokenConfiguration; - use dpp::data_contract::associated_token::token_configuration::v0::{TokenConfigurationConventionV0, TokenConfigurationV0}; - use dpp::data_contract::config::DataContractConfig; use dpp::data_contract::config::v0::DataContractConfigV0; + use dpp::data_contract::config::DataContractConfig; use dpp::data_contract::v1::DataContractV1; use dpp::identity::Identity; - - use dpp::identity::accessors::IdentityGettersV0; + use std::collections::BTreeMap; + + use dpp::identity::accessors::IdentityGettersV0; use dpp::prelude::DataContract; use dpp::version::PlatformVersion; @@ -89,7 +90,10 @@ mod tests { }), schema_defs: None, groups: Default::default(), - tokens: BTreeMap::from([(0, TokenConfiguration::V0(TokenConfigurationV0::default_most_restrictive()))]), + tokens: BTreeMap::from([( + 0, + TokenConfiguration::V0(TokenConfigurationV0::default_most_restrictive()), + )]), }); let token_id = contract.token_id(0).expect("expected token at position 0"); drive @@ -103,9 +107,28 @@ mod tests { ) .expect("expected to add an identity"); - drive.insert_contract(&contract, BlockInfo::default(), true, None, platform_version).expect("expected to insert contract"); - - drive.token_mint(token_id.to_buffer(), identity.id().to_buffer(), 10000, true, &BlockInfo::default(), true, None, platform_version).expect("expected to mint token"); + drive + .insert_contract( + &contract, + BlockInfo::default(), + true, + None, + platform_version, + ) + .expect("expected to insert contract"); + + drive + .token_mint( + token_id.to_buffer(), + identity.id().to_buffer(), + 10000, + true, + &BlockInfo::default(), + true, + None, + platform_version, + ) + .expect("expected to mint token"); let proof = drive .prove_identities_token_balances_v0( token_id.to_buffer(), @@ -115,7 +138,7 @@ mod tests { ) .expect("should not error when proving an identity"); - let proved_identity_balance: BTreeMap<[u8;32], Option> = + let proved_identity_balance: BTreeMap<[u8; 32], Option> = Drive::verify_token_balances_for_identity_ids( proof.as_slice(), token_id.to_buffer(), @@ -123,9 +146,13 @@ mod tests { false, platform_version, ) - .expect("expect that this be verified").1; + .expect("expect that this be verified") + .1; - assert_eq!(proved_identity_balance, BTreeMap::from([(identity_id, Some(10000))])); + assert_eq!( + proved_identity_balance, + BTreeMap::from([(identity_id, Some(10000))]) + ); } #[test] @@ -138,7 +165,7 @@ mod tests { .expect("expected a platform identity"); let identity_id = identity.id().to_buffer(); - + let contract = DataContract::V1(DataContractV1 { id: Default::default(), version: 0, @@ -157,7 +184,10 @@ mod tests { }), schema_defs: None, groups: Default::default(), - tokens: BTreeMap::from([(0, TokenConfiguration::V0(TokenConfigurationV0::default_most_restrictive()))]), + tokens: BTreeMap::from([( + 0, + TokenConfiguration::V0(TokenConfigurationV0::default_most_restrictive()), + )]), }); let token_id = contract.token_id(0).expect("expected token at position 0"); drive @@ -170,8 +200,16 @@ mod tests { platform_version, ) .expect("expected to add an identity"); - - drive.insert_contract(&contract, BlockInfo::default(), true, None, platform_version).expect("expected to insert contract"); + + drive + .insert_contract( + &contract, + BlockInfo::default(), + true, + None, + platform_version, + ) + .expect("expected to insert contract"); let proof = drive .prove_identities_token_balances_v0( token_id.to_buffer(), @@ -181,7 +219,7 @@ mod tests { ) .expect("should not error when proving an identity"); - let proved_identity_balance: BTreeMap<[u8;32], Option> = + let proved_identity_balance: BTreeMap<[u8; 32], Option> = Drive::verify_token_balances_for_identity_ids( proof.as_slice(), token_id.to_buffer(), @@ -189,62 +227,66 @@ mod tests { false, platform_version, ) - .expect("expect that this be verified").1; + .expect("expect that this be verified") + .1; - assert_eq!(proved_identity_balance, BTreeMap::from([(identity_id, None)])); + assert_eq!( + proved_identity_balance, + BTreeMap::from([(identity_id, None)]) + ); } - // #[test] - // fn should_prove_multiple_identity_single_token_balances() { - // let drive = setup_drive_with_initial_state_structure(None); - // let platform_version = PlatformVersion::latest(); - // let identities: BTreeMap<[u8; 32], Identity> = - // Identity::random_identities(10, 3, Some(14), platform_version) - // .expect("expected to get random identities") - // .into_iter() - // .map(|identity| (identity.id().to_buffer(), identity)) - // .collect(); - // - // let mut rng = StdRng::seed_from_u64(293); - // - // let token_id: [u8; 32] = rng.gen(); - // - // drive.add_new_token(token_id); - // - // for identity in identities.values() { - // drive - // .add_new_identity( - // identity.clone(), - // false, - // &BlockInfo::default(), - // true, - // None, - // platform_version, - // ) - // .expect("expected to add an identity"); - // } - // let identity_ids = identities.keys().copied().collect::>(); - // let identity_balances = identities - // .into_iter() - // .map(|(id, identity)| (id, Some(identity.balance()))) - // .collect::>>(); - // let proof = drive - // .prove_many_identity_token_balances( - // identity_ids.as_slice(), - // None, - // &platform_version.drive, - // ) - // .expect("should not error when proving an identity"); - // - // let (_, proved_identity_balances): ([u8; 32], BTreeMap<[u8; 32], Option>) = - // Drive::verify_identity_balances_for_identity_ids( - // proof.as_slice(), - // false, - // identity_ids.as_slice(), - // platform_version, - // ) - // .expect("expect that this be verified"); - // - // assert_eq!(proved_identity_balances, identity_balances); - // } -} \ No newline at end of file + // #[test] + // fn should_prove_multiple_identity_single_token_balances() { + // let drive = setup_drive_with_initial_state_structure(None); + // let platform_version = PlatformVersion::latest(); + // let identities: BTreeMap<[u8; 32], Identity> = + // Identity::random_identities(10, 3, Some(14), platform_version) + // .expect("expected to get random identities") + // .into_iter() + // .map(|identity| (identity.id().to_buffer(), identity)) + // .collect(); + // + // let mut rng = StdRng::seed_from_u64(293); + // + // let token_id: [u8; 32] = rng.gen(); + // + // drive.add_new_token(token_id); + // + // for identity in identities.values() { + // drive + // .add_new_identity( + // identity.clone(), + // false, + // &BlockInfo::default(), + // true, + // None, + // platform_version, + // ) + // .expect("expected to add an identity"); + // } + // let identity_ids = identities.keys().copied().collect::>(); + // let identity_balances = identities + // .into_iter() + // .map(|(id, identity)| (id, Some(identity.balance()))) + // .collect::>>(); + // let proof = drive + // .prove_many_identity_token_balances( + // identity_ids.as_slice(), + // None, + // &platform_version.drive, + // ) + // .expect("should not error when proving an identity"); + // + // let (_, proved_identity_balances): ([u8; 32], BTreeMap<[u8; 32], Option>) = + // Drive::verify_identity_balances_for_identity_ids( + // proof.as_slice(), + // false, + // identity_ids.as_slice(), + // platform_version, + // ) + // .expect("expect that this be verified"); + // + // assert_eq!(proved_identity_balances, identity_balances); + // } +} diff --git a/packages/rs-drive/src/drive/tokens/mod.rs b/packages/rs-drive/src/drive/tokens/mod.rs index 6b4a9f0b572..ea27741ade7 100644 --- a/packages/rs-drive/src/drive/tokens/mod.rs +++ b/packages/rs-drive/src/drive/tokens/mod.rs @@ -1,6 +1,6 @@ use crate::drive::RootTree; -mod add_transaction_history; +mod add_transaction_history_operations; pub mod balance; pub mod burn; pub mod estimated_costs; @@ -26,10 +26,7 @@ pub(crate) fn tokens_root_path_vec() -> Vec> { /// The path for the token tree #[cfg(any(feature = "server", feature = "verify"))] pub(crate) fn token_path(token_id: &[u8; 32]) -> [&[u8]; 2] { - [ - Into::<&[u8; 1]>::into(RootTree::Tokens), - token_id, - ] + [Into::<&[u8; 1]>::into(RootTree::Tokens), token_id] } /// The path for the token tree diff --git a/packages/rs-drive/src/drive/tokens/system/create_token_trees/v0/mod.rs b/packages/rs-drive/src/drive/tokens/system/create_token_trees/v0/mod.rs index 2a16720d3e0..c307cba91dc 100644 --- a/packages/rs-drive/src/drive/tokens/system/create_token_trees/v0/mod.rs +++ b/packages/rs-drive/src/drive/tokens/system/create_token_trees/v0/mod.rs @@ -1,4 +1,5 @@ -use crate::drive::tokens::{TOKEN_BALANCES_KEY, token_path, tokens_root_path}; +use crate::drive::balances::total_tokens_root_supply_path; +use crate::drive::tokens::{token_path, tokens_root_path, TOKEN_BALANCES_KEY}; use crate::drive::Drive; use crate::error::drive::DriveError; use crate::error::Error; @@ -11,7 +12,6 @@ use grovedb::batch::KeyInfoPath; use grovedb::{EstimatedLayerInformation, TransactionArg}; use platform_version::version::PlatformVersion; use std::collections::HashMap; -use crate::drive::balances::total_tokens_root_supply_path; impl Drive { /// Creates a new token root subtree at `TokenBalances` keyed by `token_id`. diff --git a/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_burn_transition.rs b/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_burn_transition.rs index 82e08b7b9d6..b1b41e6795f 100644 --- a/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_burn_transition.rs +++ b/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_burn_transition.rs @@ -1,5 +1,7 @@ use dpp::block::epoch::Epoch; +use dpp::data_contract::associated_token::token_configuration::accessors::v0::TokenConfigurationV0Getters; use dpp::identifier::Identifier; +use dpp::tokens::token_event::TokenEvent; use platform_version::version::PlatformVersion; use crate::error::drive::DriveError; use crate::error::Error; @@ -43,6 +45,16 @@ impl DriveHighLevelDocumentOperationConverter for TokenBurnTransitionAction { burn_amount: self.burn_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::Burn(self.burn_amount(), self.public_note_owned()), + })); + } + Ok(ops) } version => Err(Error::Drive(DriveError::UnknownVersionMismatch { diff --git a/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_issuance_transition.rs b/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_issuance_transition.rs index ec3a48d1323..0ffc9c77d36 100644 --- a/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_issuance_transition.rs +++ b/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_issuance_transition.rs @@ -1,5 +1,7 @@ use dpp::block::epoch::Epoch; +use dpp::data_contract::associated_token::token_configuration::accessors::v0::TokenConfigurationV0Getters; use dpp::identifier::Identifier; +use dpp::tokens::token_event::TokenEvent; use platform_version::version::PlatformVersion; use crate::error::drive::DriveError; use crate::error::Error; @@ -40,10 +42,20 @@ impl DriveHighLevelDocumentOperationConverter for TokenMintTransitionAction { ops.push(TokenOperation(TokenOperationType::TokenMint { token_id: self.token_id(), identity_balance_holder_id: owner_id, - mint_amount: self.issuance_amount(), + mint_amount: self.mint_amount(), allow_first_mint: false, })); + 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::Mint(self.mint_amount(), self.public_note_owned()), + })); + } + Ok(ops) } version => Err(Error::Drive(DriveError::UnknownVersionMismatch { diff --git a/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_transfer_transition.rs b/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_transfer_transition.rs index a00416e1799..61bd9db796b 100644 --- a/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_transfer_transition.rs +++ b/packages/rs-drive/src/state_transition_action/action_convert_to_operations/document/token_transfer_transition.rs @@ -1,11 +1,14 @@ use dpp::block::epoch::Epoch; +use dpp::data_contract::associated_token::token_configuration::accessors::v0::TokenConfigurationV0Getters; 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::document::DriveHighLevelDocumentOperationConverter; use crate::state_transition_action::document::documents_batch::document_transition::token_base_transition_action::TokenBaseTransitionActionAccessorsV0; -use crate::state_transition_action::document::documents_batch::document_transition::token_transfer_transition_action::{TokenTransferTransitionAction, TokenTransferTransitionActionAccessors}; +use crate::state_transition_action::document::documents_batch::document_transition::token_transfer_transition_action::TokenTransferTransitionAction; +use crate::state_transition_action::document::documents_batch::document_transition::token_transfer_transition_action::v0::TokenTransferTransitionActionAccessorsV0; use crate::util::batch::{DriveOperation, IdentityOperationType}; use crate::util::batch::drive_op_batch::TokenOperationType; use crate::util::batch::DriveOperation::{IdentityOperation, TokenOperation}; @@ -29,6 +32,12 @@ impl DriveHighLevelDocumentOperationConverter for TokenTransferTransitionAction let identity_contract_nonce = self.base().identity_contract_nonce(); + let token_id = self.token_id(); + + let recipient_id = self.recipient_id(); + + let amount = self.amount(); + let mut ops = vec![IdentityOperation( IdentityOperationType::UpdateIdentityContractNonce { identity_id: owner_id.into_buffer(), @@ -38,12 +47,30 @@ impl DriveHighLevelDocumentOperationConverter for TokenTransferTransitionAction )]; ops.push(TokenOperation(TokenOperationType::TokenTransfer { - token_id: self.token_id(), + token_id, sender_id: owner_id, - recipient_id: self.recipient_id(), - amount: self.amount(), + recipient_id, + amount, })); + let token_configuration = self.base().token_configuration()?; + if token_configuration.keeps_history() { + let (public_note, shared_encrypted_note, private_encrypted_note) = + self.notes_owned(); + ops.push(TokenOperation(TokenOperationType::TokenHistory { + token_id, + owner_id, + nonce: identity_contract_nonce, + event: TokenEvent::Transfer( + recipient_id, + public_note, + shared_encrypted_note, + private_encrypted_note, + amount, + ), + })); + } + Ok(ops) } version => Err(Error::Drive(DriveError::UnknownVersionMismatch { diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/mod.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/mod.rs index 0002aa0db2f..9c2f4c4fdeb 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/mod.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/mod.rs @@ -38,7 +38,8 @@ use crate::state_transition_action::system::bump_identity_data_contract_nonce_ac use crate::state_transition_action::document::documents_batch::document_transition::token_base_transition_action::{TokenBaseTransitionAction, TokenBaseTransitionActionAccessorsV0}; use crate::state_transition_action::document::documents_batch::document_transition::token_burn_transition_action::{TokenBurnTransitionAction, TokenBurnTransitionActionAccessorsV0}; use crate::state_transition_action::document::documents_batch::document_transition::token_mint_transition_action::{TokenMintTransitionAction, TokenMintTransitionActionAccessorsV0}; -use crate::state_transition_action::document::documents_batch::document_transition::token_transfer_transition_action::{TokenTransferTransitionAction, TokenTransferTransitionActionAccessors}; +use crate::state_transition_action::document::documents_batch::document_transition::token_transfer_transition_action::TokenTransferTransitionAction; +use crate::state_transition_action::document::documents_batch::document_transition::token_transfer_transition_action::v0::TokenTransferTransitionActionAccessorsV0; /// version pub const DOCUMENT_TRANSITION_ACTION_VERSION: u32 = 0; diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/mod.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/mod.rs index d99a0f88948..e93292f0522 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/mod.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/mod.rs @@ -22,64 +22,46 @@ pub enum TokenBurnTransitionAction { V0(TokenBurnTransitionActionV0), } -/// Accessors trait for TokenBurnTransitionAction for version 0 fields -pub trait TokenBurnTransitionActionAccessorsV0 { - /// Returns a reference to the base token transition action - fn base(&self) -> &TokenBaseTransitionAction; - - /// Returns the base token transition action - fn base_owned(self) -> TokenBaseTransitionAction; - - /// Returns the burn amount - fn burn_amount(&self) -> u64; - - /// Returns the token position in the contract - fn token_position(&self) -> u16 { - self.base().token_position() - } - - /// Returns the token ID - fn token_id(&self) -> Identifier { - self.base().token_id() - } - - /// Returns the data contract ID - fn data_contract_id(&self) -> Identifier { - self.base().data_contract_id() +impl TokenBurnTransitionActionAccessorsV0 for TokenBurnTransitionAction { + fn base(&self) -> &TokenBaseTransitionAction { + match self { + TokenBurnTransitionAction::V0(v0) => &v0.base, + } } - /// Returns a reference to the data contract fetch info - fn data_contract_fetch_info_ref(&self) -> &Arc { - self.base().data_contract_fetch_info_ref() + fn base_owned(self) -> TokenBaseTransitionAction { + match self { + TokenBurnTransitionAction::V0(v0) => v0.base, + } } - /// Returns the data contract fetch info - fn data_contract_fetch_info(&self) -> Arc { - self.base().data_contract_fetch_info() + fn burn_amount(&self) -> u64 { + match self { + TokenBurnTransitionAction::V0(v0) => v0.burn_amount, + } } - /// Returns the identity contract nonce - fn identity_contract_nonce(&self) -> IdentityNonce { - self.base().identity_contract_nonce() + fn set_burn_amount(&mut self, amount: u64) { + match self { + TokenBurnTransitionAction::V0(v0) => v0.burn_amount = amount, + } } -} -impl TokenBurnTransitionActionAccessorsV0 for TokenBurnTransitionAction { - fn base(&self) -> &TokenBaseTransitionAction { + fn public_note(&self) -> Option<&String> { match self { - TokenBurnTransitionAction::V0(v0) => &v0.base, + TokenBurnTransitionAction::V0(v0) => v0.public_note.as_ref(), } } - fn base_owned(self) -> TokenBaseTransitionAction { + fn public_note_owned(self) -> Option { match self { - TokenBurnTransitionAction::V0(v0) => v0.base, + TokenBurnTransitionAction::V0(v0) => v0.public_note, } } - fn burn_amount(&self) -> u64 { + fn set_public_note(&mut self, public_note: Option) { match self { - TokenBurnTransitionAction::V0(v0) => v0.burn_amount, + TokenBurnTransitionAction::V0(v0) => v0.public_note = public_note, } } } diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/v0/mod.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/v0/mod.rs index 7b63337dc96..84f239a832b 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/v0/mod.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/v0/mod.rs @@ -1,5 +1,10 @@ mod transformer; -use crate::state_transition_action::document::documents_batch::document_transition::token_base_transition_action::TokenBaseTransitionAction; + +use std::sync::Arc; +use dpp::identifier::Identifier; +use dpp::prelude::IdentityNonce; +use crate::drive::contract::DataContractFetchInfo; +use crate::state_transition_action::document::documents_batch::document_transition::token_base_transition_action::{TokenBaseTransitionAction, TokenBaseTransitionActionAccessorsV0}; /// Token burn transition action v0 #[derive(Debug, Clone)] @@ -8,6 +13,8 @@ pub struct TokenBurnTransitionActionV0 { pub base: TokenBaseTransitionAction, /// The amount of tokens to burn pub burn_amount: u64, + /// A public note + pub public_note: Option, } /// Accessors for `TokenBurnTransitionActionV0` @@ -23,6 +30,45 @@ pub trait TokenBurnTransitionActionAccessorsV0 { /// Sets the amount of tokens to burn fn set_burn_amount(&mut self, amount: u64); + + /// Returns a reference to the `public_note` field of the `TokenBurnTransitionActionV0` + fn public_note(&self) -> Option<&String>; + + /// Returns the owned `public_note` field of the `TokenBurnTransitionActionV0` + fn public_note_owned(self) -> Option; + + /// Sets the value of the `public_note` field in the `TokenBurnTransitionActionV0` + fn set_public_note(&mut self, public_note: Option); + + /// Returns the token position in the contract + fn token_position(&self) -> u16 { + self.base().token_position() + } + + /// Returns the token ID + fn token_id(&self) -> Identifier { + self.base().token_id() + } + + /// Returns the data contract ID + fn data_contract_id(&self) -> Identifier { + self.base().data_contract_id() + } + + /// Returns a reference to the data contract fetch info + fn data_contract_fetch_info_ref(&self) -> &Arc { + self.base().data_contract_fetch_info_ref() + } + + /// Returns the data contract fetch info + fn data_contract_fetch_info(&self) -> Arc { + self.base().data_contract_fetch_info() + } + + /// Returns the identity contract nonce + fn identity_contract_nonce(&self) -> IdentityNonce { + self.base().identity_contract_nonce() + } } impl TokenBurnTransitionActionAccessorsV0 for TokenBurnTransitionActionV0 { @@ -41,4 +87,16 @@ impl TokenBurnTransitionActionAccessorsV0 for TokenBurnTransitionActionV0 { fn set_burn_amount(&mut self, amount: u64) { self.burn_amount = amount; } + + fn public_note(&self) -> Option<&String> { + self.public_note.as_ref() + } + + fn public_note_owned(self) -> Option { + self.public_note + } + + fn set_public_note(&mut self, public_note: Option) { + self.public_note = public_note; + } } diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/v0/transformer.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/v0/transformer.rs index 96ac0ef533e..09bb907014b 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/v0/transformer.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_burn_transition_action/v0/transformer.rs @@ -23,7 +23,11 @@ impl TokenBurnTransitionActionV0 { value: TokenBurnTransitionV0, get_data_contract: impl Fn(Identifier) -> Result, ProtocolError>, ) -> Result { - let TokenBurnTransitionV0 { base, burn_amount } = value; + let TokenBurnTransitionV0 { + base, + burn_amount, + public_note, + } = value; let base_action = TokenBaseTransitionAction::try_from_base_transition_with_contract_lookup( base, @@ -33,6 +37,7 @@ impl TokenBurnTransitionActionV0 { Ok(TokenBurnTransitionActionV0 { base: base_action, burn_amount, + public_note, }) } @@ -50,7 +55,11 @@ impl TokenBurnTransitionActionV0 { value: &TokenBurnTransitionV0, get_data_contract: impl Fn(Identifier) -> Result, ProtocolError>, ) -> Result { - let TokenBurnTransitionV0 { base, burn_amount } = value; + let TokenBurnTransitionV0 { + base, + burn_amount, + public_note, + } = value; let base_action = TokenBaseTransitionAction::try_from_borrowed_base_transition_with_contract_lookup( @@ -61,6 +70,7 @@ impl TokenBurnTransitionActionV0 { Ok(TokenBurnTransitionActionV0 { base: base_action, burn_amount: *burn_amount, + public_note: public_note.clone(), }) } } diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/mod.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/mod.rs index 28868b09a7a..405337029c0 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/mod.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/mod.rs @@ -29,15 +29,15 @@ impl TokenMintTransitionActionAccessorsV0 for TokenMintTransitionAction { } } - fn issuance_amount(&self) -> u64 { + fn mint_amount(&self) -> u64 { match self { - TokenMintTransitionAction::V0(v0) => v0.issuance_amount, + TokenMintTransitionAction::V0(v0) => v0.mint_amount, } } - fn set_issuance_amount(&mut self, amount: u64) { + fn set_mint_amount(&mut self, amount: u64) { match self { - TokenMintTransitionAction::V0(v0) => v0.issuance_amount = amount, + TokenMintTransitionAction::V0(v0) => v0.mint_amount = amount, } } @@ -52,4 +52,22 @@ impl TokenMintTransitionActionAccessorsV0 for TokenMintTransitionAction { TokenMintTransitionAction::V0(v0) => v0.identity_balance_holder_id = id, } } + + fn public_note(&self) -> Option<&String> { + match self { + TokenMintTransitionAction::V0(v0) => v0.public_note.as_ref(), + } + } + + fn public_note_owned(self) -> Option { + match self { + TokenMintTransitionAction::V0(v0) => v0.public_note, + } + } + + fn set_public_note(&mut self, public_note: Option) { + match self { + TokenMintTransitionAction::V0(v0) => v0.public_note = public_note, + } + } } diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/v0/mod.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/v0/mod.rs index 54ccf11b25d..5d158482d68 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/v0/mod.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/v0/mod.rs @@ -11,9 +11,11 @@ pub struct TokenIssuanceTransitionActionV0 { /// Base token transition action pub base: TokenBaseTransitionAction, /// The amount of tokens to create - pub issuance_amount: u64, + pub mint_amount: u64, /// The identity to credit the token to pub identity_balance_holder_id: Identifier, + /// A public note + pub public_note: Option, } /// Accessors for `TokenIssuanceTransitionActionV0` @@ -25,10 +27,10 @@ pub trait TokenMintTransitionActionAccessorsV0 { fn base_owned(self) -> TokenBaseTransitionAction; /// Returns the amount of tokens to issuance - fn issuance_amount(&self) -> u64; + fn mint_amount(&self) -> u64; /// Sets the amount of tokens to issuance - fn set_issuance_amount(&mut self, amount: u64); + fn set_mint_amount(&mut self, amount: u64); /// Consumes self and returns the identity balance holder ID fn identity_balance_holder_id(&self) -> Identifier; @@ -60,6 +62,15 @@ pub trait TokenMintTransitionActionAccessorsV0 { fn data_contract_fetch_info(&self) -> Arc { self.base().data_contract_fetch_info() } + + /// Returns the public note (optional) + fn public_note(&self) -> Option<&String>; + + /// Returns the public note (owned) + fn public_note_owned(self) -> Option; + + /// Sets the public note + fn set_public_note(&mut self, public_note: Option); } impl TokenMintTransitionActionAccessorsV0 for TokenIssuanceTransitionActionV0 { @@ -71,12 +82,12 @@ impl TokenMintTransitionActionAccessorsV0 for TokenIssuanceTransitionActionV0 { self.base } - fn issuance_amount(&self) -> u64 { - self.issuance_amount + fn mint_amount(&self) -> u64 { + self.mint_amount } - fn set_issuance_amount(&mut self, amount: u64) { - self.issuance_amount = amount; + fn set_mint_amount(&mut self, amount: u64) { + self.mint_amount = amount; } fn identity_balance_holder_id(&self) -> Identifier { @@ -86,4 +97,16 @@ impl TokenMintTransitionActionAccessorsV0 for TokenIssuanceTransitionActionV0 { fn set_identity_balance_holder_id(&mut self, id: Identifier) { self.identity_balance_holder_id = id; } + + fn public_note(&self) -> Option<&String> { + self.public_note.as_ref() + } + + fn public_note_owned(self) -> Option { + self.public_note + } + + fn set_public_note(&mut self, public_note: Option) { + self.public_note = public_note; + } } diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/v0/transformer.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/v0/transformer.rs index fb563fe6ad9..bedc0d48c7c 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/v0/transformer.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_mint_transition_action/v0/transformer.rs @@ -30,6 +30,7 @@ impl TokenIssuanceTransitionActionV0 { base, issued_to_identity_id, amount, + public_note, } = value; let position = base.token_contract_position(); @@ -56,8 +57,9 @@ impl TokenIssuanceTransitionActionV0 { Ok(TokenIssuanceTransitionActionV0 { base: base_action, - issuance_amount: amount, + mint_amount: amount, identity_balance_holder_id, + public_note, }) } @@ -79,6 +81,7 @@ impl TokenIssuanceTransitionActionV0 { base, issued_to_identity_id, amount, + public_note, } = value; let base_action = @@ -104,8 +107,9 @@ impl TokenIssuanceTransitionActionV0 { Ok(TokenIssuanceTransitionActionV0 { base: base_action, - issuance_amount: *amount, + mint_amount: *amount, identity_balance_holder_id, + public_note: public_note.clone(), }) } } diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/mod.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/mod.rs index 060b7a408ae..6e0c82cf2cf 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/mod.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/mod.rs @@ -5,7 +5,7 @@ use crate::state_transition_action::document::documents_batch::document_transiti }; use crate::state_transition_action::document::documents_batch::document_transition::token_base_transition_action::{TokenBaseTransitionAction, TokenBaseTransitionActionAccessorsV0}; use dpp::identifier::Identifier; -use dpp::prelude::IdentityNonce; +use dpp::prelude::{DerivationEncryptionKeyIndex, IdentityNonce, RecipientKeyIndex, RootEncryptionKeyIndex, SenderKeyIndex}; use std::sync::Arc; use crate::drive::contract::DataContractFetchInfo; @@ -21,72 +21,124 @@ pub enum TokenTransferTransitionAction { V0(TokenTransferTransitionActionV0), } -/// Accessors trait for TokenTransferTransitionAction -pub trait TokenTransferTransitionActionAccessors { - /// Returns a reference to the base token transition action - fn base(&self) -> &TokenBaseTransitionAction; +impl TokenTransferTransitionActionAccessorsV0 for TokenTransferTransitionAction { + fn base(&self) -> &TokenBaseTransitionAction { + match self { + TokenTransferTransitionAction::V0(v0) => v0.base(), + } + } - /// Returns a reference to the base token transition action - fn base_owned(self) -> TokenBaseTransitionAction; + fn base_owned(self) -> TokenBaseTransitionAction { + match self { + TokenTransferTransitionAction::V0(v0) => v0.base_owned(), + } + } - /// Returns the amount of tokens to transfer - fn amount(&self) -> u64; + fn amount(&self) -> u64 { + match self { + TokenTransferTransitionAction::V0(v0) => v0.amount(), + } + } - /// Returns the recipient ID - fn recipient_id(&self) -> Identifier; + fn recipient_id(&self) -> Identifier { + match self { + TokenTransferTransitionAction::V0(v0) => v0.recipient_id(), + } + } - /// Returns the token position in the contract - fn token_position(&self) -> u16 { - self.base().token_position() + fn public_note(&self) -> Option<&String> { + match self { + TokenTransferTransitionAction::V0(v0) => v0.public_note(), + } } - /// Returns the token ID - fn token_id(&self) -> Identifier { - self.base().token_id() + fn public_note_owned(self) -> Option { + match self { + TokenTransferTransitionAction::V0(v0) => v0.public_note_owned(), + } } - /// Returns the data contract ID - fn data_contract_id(&self) -> Identifier { - self.base().data_contract_id() + fn set_public_note(&mut self, public_note: Option) { + match self { + TokenTransferTransitionAction::V0(v0) => v0.set_public_note(public_note), + } } - /// Returns a reference to the data contract fetch info - fn data_contract_fetch_info_ref(&self) -> &Arc { - self.base().data_contract_fetch_info_ref() + fn shared_encrypted_note(&self) -> Option<&(SenderKeyIndex, RecipientKeyIndex, Vec)> { + match self { + TokenTransferTransitionAction::V0(v0) => v0.shared_encrypted_note(), + } } - /// Returns the data contract fetch info - fn data_contract_fetch_info(&self) -> Arc { - self.base().data_contract_fetch_info() + fn shared_encrypted_note_owned(self) -> Option<(SenderKeyIndex, RecipientKeyIndex, Vec)> { + match self { + TokenTransferTransitionAction::V0(v0) => v0.shared_encrypted_note_owned(), + } } - /// Returns the identity contract nonce - fn identity_contract_nonce(&self) -> IdentityNonce { - self.base().identity_contract_nonce() + fn set_shared_encrypted_note( + &mut self, + shared_encrypted_note: Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + ) { + match self { + TokenTransferTransitionAction::V0(v0) => { + v0.set_shared_encrypted_note(shared_encrypted_note) + } + } } -} -impl TokenTransferTransitionActionAccessors for TokenTransferTransitionAction { - fn base(&self) -> &TokenBaseTransitionAction { + fn private_encrypted_note( + &self, + ) -> Option<&( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )> { match self { - TokenTransferTransitionAction::V0(v0) => v0.base(), + TokenTransferTransitionAction::V0(v0) => v0.private_encrypted_note(), } } - fn base_owned(self) -> TokenBaseTransitionAction { + + fn private_encrypted_note_owned( + self, + ) -> Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )> { match self { - TokenTransferTransitionAction::V0(v0) => v0.base_owned(), + TokenTransferTransitionAction::V0(v0) => v0.private_encrypted_note_owned(), } } - fn amount(&self) -> u64 { + fn set_private_encrypted_note( + &mut self, + private_encrypted_note: Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ) { match self { - TokenTransferTransitionAction::V0(v0) => v0.amount(), + TokenTransferTransitionAction::V0(v0) => { + v0.set_private_encrypted_note(private_encrypted_note) + } } } - fn recipient_id(&self) -> Identifier { + fn notes_owned( + self, + ) -> ( + Option, + Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ) { match self { - TokenTransferTransitionAction::V0(v0) => v0.recipient_id(), + TokenTransferTransitionAction::V0(v0) => v0.notes_owned(), } } } diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/v0/mod.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/v0/mod.rs index acebdbcf653..e1d318d219a 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/v0/mod.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/v0/mod.rs @@ -3,7 +3,10 @@ mod transformer; use std::sync::Arc; use dpp::identifier::Identifier; -use dpp::prelude::IdentityNonce; +use dpp::prelude::{ + DerivationEncryptionKeyIndex, IdentityNonce, RecipientKeyIndex, RootEncryptionKeyIndex, + SenderKeyIndex, +}; use crate::drive::contract::DataContractFetchInfo; use crate::state_transition_action::document::documents_batch::document_transition::token_base_transition_action::{ @@ -19,6 +22,16 @@ pub struct TokenTransferTransitionActionV0 { pub amount: u64, /// The recipient owner ID pub recipient_id: Identifier, + /// The public note + pub public_note: Option, + /// An optional shared encrypted note + pub shared_encrypted_note: Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + /// An optional private encrypted note + pub private_encrypted_note: Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, } /// Accessors for `TokenTransferTransitionActionV0` @@ -35,11 +48,16 @@ pub trait TokenTransferTransitionActionAccessorsV0 { /// Returns the recipient owner ID fn recipient_id(&self) -> Identifier; - /// Returns the token ID from the base action - fn token_id(&self) -> u16 { + /// Returns the token position in the contract + fn token_position(&self) -> u16 { self.base().token_position() } + /// Returns the token ID + fn token_id(&self) -> Identifier { + self.base().token_id() + } + /// Returns the data contract ID from the base action fn data_contract_id(&self) -> Identifier { self.base().data_contract_id() @@ -59,6 +77,68 @@ pub trait TokenTransferTransitionActionAccessorsV0 { fn identity_contract_nonce(&self) -> IdentityNonce { self.base().identity_contract_nonce() } + + /// Returns the public note, if present + fn public_note(&self) -> Option<&String>; + + /// Consumes the `TokenTransferTransitionActionV0` and returns the public note, if present + fn public_note_owned(self) -> Option; + + /// Sets the public note + fn set_public_note(&mut self, public_note: Option); + + /// Returns the shared encrypted note, if present + fn shared_encrypted_note(&self) -> Option<&(SenderKeyIndex, RecipientKeyIndex, Vec)>; + + /// Consumes the `TokenTransferTransitionActionV0` and returns the shared encrypted note, if present + fn shared_encrypted_note_owned(self) -> Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>; + + /// Sets the shared encrypted note + fn set_shared_encrypted_note( + &mut self, + shared_encrypted_note: Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + ); + + /// Returns the private encrypted note, if present + fn private_encrypted_note( + &self, + ) -> Option<&( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>; + + /// Consumes the `TokenTransferTransitionActionV0` and returns the private encrypted note, if present + fn private_encrypted_note_owned( + self, + ) -> Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>; + + /// Sets the private encrypted note + fn set_private_encrypted_note( + &mut self, + private_encrypted_note: Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ); + + /// All notes + fn notes_owned( + self, + ) -> ( + Option, + Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ); } impl TokenTransferTransitionActionAccessorsV0 for TokenTransferTransitionActionV0 { @@ -77,4 +157,80 @@ impl TokenTransferTransitionActionAccessorsV0 for TokenTransferTransitionActionV fn recipient_id(&self) -> Identifier { self.recipient_id } + + fn public_note(&self) -> Option<&String> { + self.public_note.as_ref() + } + + fn public_note_owned(self) -> Option { + self.public_note + } + + fn set_public_note(&mut self, public_note: Option) { + self.public_note = public_note; + } + + fn shared_encrypted_note(&self) -> Option<&(SenderKeyIndex, RecipientKeyIndex, Vec)> { + self.shared_encrypted_note.as_ref() + } + + fn shared_encrypted_note_owned(self) -> Option<(SenderKeyIndex, RecipientKeyIndex, Vec)> { + self.shared_encrypted_note + } + + fn set_shared_encrypted_note( + &mut self, + shared_encrypted_note: Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + ) { + self.shared_encrypted_note = shared_encrypted_note; + } + + fn private_encrypted_note( + &self, + ) -> Option<&( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )> { + self.private_encrypted_note.as_ref() + } + + fn private_encrypted_note_owned( + self, + ) -> Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )> { + self.private_encrypted_note + } + + fn set_private_encrypted_note( + &mut self, + private_encrypted_note: Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ) { + self.private_encrypted_note = private_encrypted_note; + } + + fn notes_owned( + self, + ) -> ( + Option, + Option<(SenderKeyIndex, RecipientKeyIndex, Vec)>, + Option<( + RootEncryptionKeyIndex, + DerivationEncryptionKeyIndex, + Vec, + )>, + ) { + ( + self.public_note, + self.shared_encrypted_note, + self.private_encrypted_note, + ) + } } diff --git a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/v0/transformer.rs b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/v0/transformer.rs index f543a19b219..dec31daefc3 100644 --- a/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/v0/transformer.rs +++ b/packages/rs-drive/src/state_transition_action/document/documents_batch/document_transition/token_transfer_transition_action/v0/transformer.rs @@ -18,6 +18,9 @@ impl TokenTransferTransitionActionV0 { base, amount, recipient_owner_id, + public_note, + shared_encrypted_note, + private_encrypted_note, } = value; let base_action = TokenBaseTransitionAction::try_from_base_transition_with_contract_lookup( @@ -29,6 +32,9 @@ impl TokenTransferTransitionActionV0 { base: base_action, amount, recipient_id: recipient_owner_id, + public_note, + shared_encrypted_note, + private_encrypted_note, }) } @@ -41,6 +47,9 @@ impl TokenTransferTransitionActionV0 { base, amount, recipient_owner_id, + public_note, + shared_encrypted_note, + private_encrypted_note, } = value; let base_action = @@ -53,6 +62,9 @@ impl TokenTransferTransitionActionV0 { base: base_action.into(), amount: *amount, recipient_id: *recipient_owner_id, + public_note: public_note.clone(), + shared_encrypted_note: shared_encrypted_note.clone(), + private_encrypted_note: private_encrypted_note.clone(), }) } } diff --git a/packages/rs-drive/src/util/batch/drive_op_batch/token.rs b/packages/rs-drive/src/util/batch/drive_op_batch/token.rs index 527db6f1693..51efa60fbca 100644 --- a/packages/rs-drive/src/util/batch/drive_op_batch/token.rs +++ b/packages/rs-drive/src/util/batch/drive_op_batch/token.rs @@ -5,6 +5,8 @@ use crate::util::batch::drive_op_batch::DriveLowLevelOperationConverter; use dpp::balances::credits::TokenAmount; use dpp::block::block_info::BlockInfo; use dpp::identifier::Identifier; +use dpp::prelude::IdentityNonce; +use dpp::tokens::token_event::TokenEvent; use grovedb::batch::KeyInfoPath; use grovedb::{EstimatedLayerInformation, TransactionArg}; use platform_version::version::PlatformVersion; @@ -44,6 +46,17 @@ pub enum TokenOperationType { /// The amount to transfer amount: TokenAmount, }, + /// Adds a document to a contract matching the desired info. + TokenHistory { + /// The token id + token_id: Identifier, + /// The identity making the event + owner_id: Identifier, + /// The nonce + nonce: IdentityNonce, + /// The token event + event: TokenEvent, + }, } impl DriveLowLevelOperationConverter for TokenOperationType { @@ -53,7 +66,7 @@ impl DriveLowLevelOperationConverter for TokenOperationType { estimated_costs_only_with_layer_info: &mut Option< HashMap, >, - _block_info: &BlockInfo, + block_info: &BlockInfo, transaction: TransactionArg, platform_version: &PlatformVersion, ) -> Result, Error> { @@ -115,6 +128,24 @@ impl DriveLowLevelOperationConverter for TokenOperationType { )?; Ok(batch_operations) } + TokenOperationType::TokenHistory { + token_id, + owner_id, + nonce, + event, + } => { + let batch_operations = drive.add_token_transaction_history_operations( + token_id, + owner_id, + nonce, + event, + block_info, + estimated_costs_only_with_layer_info, + transaction, + platform_version, + )?; + Ok(batch_operations) + } } } } diff --git a/packages/rs-drive/src/util/grove_operations/batch_insert_empty_sum_tree/mod.rs b/packages/rs-drive/src/util/grove_operations/batch_insert_empty_sum_tree/mod.rs index 113e8f40f10..2a2a033ff46 100644 --- a/packages/rs-drive/src/util/grove_operations/batch_insert_empty_sum_tree/mod.rs +++ b/packages/rs-drive/src/util/grove_operations/batch_insert_empty_sum_tree/mod.rs @@ -34,8 +34,14 @@ impl Drive { P: IntoIterator,

::IntoIter: ExactSizeIterator + DoubleEndedIterator + Clone, { - match drive_version.grove_methods.batch.batch_insert_empty_sum_tree { - 0 => self.batch_insert_empty_sum_tree_v0(path, key_info, storage_flags, drive_operations), + match drive_version + .grove_methods + .batch + .batch_insert_empty_sum_tree + { + 0 => { + self.batch_insert_empty_sum_tree_v0(path, key_info, storage_flags, drive_operations) + } version => Err(Error::Drive(DriveError::UnknownVersionMismatch { method: "batch_insert_empty_sum_tree".to_string(), known_versions: vec![0], diff --git a/packages/rs-drive/src/util/grove_operations/batch_insert_empty_sum_tree/v0/mod.rs b/packages/rs-drive/src/util/grove_operations/batch_insert_empty_sum_tree/v0/mod.rs index 7753b9f6729..fb76aa3f18c 100644 --- a/packages/rs-drive/src/util/grove_operations/batch_insert_empty_sum_tree/v0/mod.rs +++ b/packages/rs-drive/src/util/grove_operations/batch_insert_empty_sum_tree/v0/mod.rs @@ -30,11 +30,13 @@ impl Drive { Ok(()) } KeySize(key) => { - drive_operations.push(LowLevelDriveOperation::for_estimated_path_key_empty_sum_tree( - KeyInfoPath::from_known_path(path), - key, - storage_flags, - )); + drive_operations.push( + LowLevelDriveOperation::for_estimated_path_key_empty_sum_tree( + KeyInfoPath::from_known_path(path), + key, + storage_flags, + ), + ); Ok(()) } Key(key) => { diff --git a/packages/rs-drive/src/verify/mod.rs b/packages/rs-drive/src/verify/mod.rs index f0a4dc388ba..18474b4bbb7 100644 --- a/packages/rs-drive/src/verify/mod.rs +++ b/packages/rs-drive/src/verify/mod.rs @@ -12,8 +12,8 @@ pub mod system; /// Verifies that a state transition contents exist in the proof pub mod state_transition; -pub mod voting; mod tokens; +pub mod voting; /// Represents the root hash of the grovedb tree pub type RootHash = [u8; 32]; diff --git a/packages/rs-drive/src/verify/tokens/mod.rs b/packages/rs-drive/src/verify/tokens/mod.rs index 1a9a9421a46..7f169cda4e2 100644 --- a/packages/rs-drive/src/verify/tokens/mod.rs +++ b/packages/rs-drive/src/verify/tokens/mod.rs @@ -1 +1 @@ -mod verify_token_balances_for_identity_ids; \ No newline at end of file +mod verify_token_balances_for_identity_ids; diff --git a/packages/rs-drive/src/verify/tokens/verify_token_balances_for_identity_ids/mod.rs b/packages/rs-drive/src/verify/tokens/verify_token_balances_for_identity_ids/mod.rs index 4303bf196a3..078408d9924 100644 --- a/packages/rs-drive/src/verify/tokens/verify_token_balances_for_identity_ids/mod.rs +++ b/packages/rs-drive/src/verify/tokens/verify_token_balances_for_identity_ids/mod.rs @@ -1,8 +1,8 @@ mod v0; -use std::collections::BTreeMap; -use dpp::balances::credits::TokenAmount; use crate::drive::Drive; +use dpp::balances::credits::TokenAmount; +use std::collections::BTreeMap; use crate::error::drive::DriveError; @@ -16,7 +16,7 @@ impl Drive { /// Verifies the token balances for a set of identity IDs. /// /// This function checks the token balances of multiple identities by verifying the provided - /// proof against the specified token ID and identity IDs. It also supports verifying a subset + /// proof against the specified token ID and identity IDs. It also supports verifying a subset /// of a larger proof if necessary. /// /// # Parameters @@ -27,7 +27,7 @@ impl Drive { /// is being verified. /// - `identity_ids`: A slice of 32-byte arrays, each representing a unique identity ID. These /// are the identities whose token balances are being verified. - /// - `verify_subset_of_proof`: A boolean flag indicating whether the proof being verified is a + /// - `verify_subset_of_proof`: A boolean flag indicating whether the proof being verified is a /// subset of a larger proof. If `true`, the verification will consider only a part of the proof. /// - `platform_version`: The version of the platform against which the identity token balances are /// being verified. This ensures compatibility with the correct API version. @@ -52,7 +52,7 @@ impl Drive { I: From<[u8; 32]>, >( proof: &[u8], - token_id: [u8;32], + token_id: [u8; 32], identity_ids: &[[u8; 32]], verify_subset_of_proof: bool, platform_version: &PlatformVersion, diff --git a/packages/rs-drive/src/verify/tokens/verify_token_balances_for_identity_ids/v0/mod.rs b/packages/rs-drive/src/verify/tokens/verify_token_balances_for_identity_ids/v0/mod.rs index c6e152e6413..be941cc5a58 100644 --- a/packages/rs-drive/src/verify/tokens/verify_token_balances_for_identity_ids/v0/mod.rs +++ b/packages/rs-drive/src/verify/tokens/verify_token_balances_for_identity_ids/v0/mod.rs @@ -5,9 +5,9 @@ use crate::error::Error; use crate::verify::RootHash; -use grovedb::GroveDb; use dpp::balances::credits::TokenAmount; use dpp::fee::Credits; +use grovedb::GroveDb; use platform_version::version::PlatformVersion; impl Drive { @@ -16,7 +16,7 @@ impl Drive { I: From<[u8; 32]>, >( proof: &[u8], - token_id: [u8;32], + token_id: [u8; 32], identity_ids: &[[u8; 32]], verify_subset_of_proof: bool, platform_version: &PlatformVersion, diff --git a/packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/mod.rs b/packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/mod.rs index 8f47a00183c..1daea28aeb3 100644 --- a/packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/mod.rs +++ b/packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/mod.rs @@ -31,4 +31,5 @@ pub struct DriveTokenUpdateMethodVersions { pub remove_from_token_total_supply: FeatureVersion, pub remove_from_identity_token_balance: FeatureVersion, pub add_to_identity_token_balance: FeatureVersion, + pub add_transaction_history_operations: FeatureVersion, } diff --git a/packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/v1.rs b/packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/v1.rs index f021ede2b3b..c2afcae91e9 100644 --- a/packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/v1.rs +++ b/packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/v1.rs @@ -21,5 +21,6 @@ pub const DRIVE_TOKEN_METHOD_VERSIONS_V1: DriveTokenMethodVersions = DriveTokenM remove_from_token_total_supply: 0, remove_from_identity_token_balance: 0, add_to_identity_token_balance: 0, + add_transaction_history_operations: 0, }, }; diff --git a/packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/v1.rs b/packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/v1.rs index 9604882fe69..d012f3e6acf 100644 --- a/packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/v1.rs +++ b/packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/v1.rs @@ -1,4 +1,9 @@ -use crate::version::drive_versions::drive_verify_method_versions::{DriveVerifyContractMethodVersions, DriveVerifyDocumentMethodVersions, DriveVerifyIdentityMethodVersions, DriveVerifyMethodVersions, DriveVerifySingleDocumentMethodVersions, DriveVerifyStateTransitionMethodVersions, DriveVerifySystemMethodVersions, DriveVerifyTokenMethodVersions, DriveVerifyVoteMethodVersions}; +use crate::version::drive_versions::drive_verify_method_versions::{ + DriveVerifyContractMethodVersions, DriveVerifyDocumentMethodVersions, + DriveVerifyIdentityMethodVersions, DriveVerifyMethodVersions, + DriveVerifySingleDocumentMethodVersions, DriveVerifyStateTransitionMethodVersions, + DriveVerifySystemMethodVersions, DriveVerifyTokenMethodVersions, DriveVerifyVoteMethodVersions, +}; pub const DRIVE_VERIFY_METHOD_VERSIONS_V1: DriveVerifyMethodVersions = DriveVerifyMethodVersions { contract: DriveVerifyContractMethodVersions { diff --git a/packages/rs-platform-version/src/version/mod.rs b/packages/rs-platform-version/src/version/mod.rs index f060faae78c..b0ae65471cb 100644 --- a/packages/rs-platform-version/src/version/mod.rs +++ b/packages/rs-platform-version/src/version/mod.rs @@ -1,6 +1,6 @@ mod protocol_version; -pub use protocol_version::*; use crate::version::v8::PROTOCOL_VERSION_8; +pub use protocol_version::*; mod consensus_versions; pub mod dpp_versions; diff --git a/packages/token-history-contract/schema/v1/token-history-contract-documents.json b/packages/token-history-contract/schema/v1/token-history-contract-documents.json index 1f71eb10ee5..a364d38776f 100644 --- a/packages/token-history-contract/schema/v1/token-history-contract-documents.json +++ b/packages/token-history-contract/schema/v1/token-history-contract-documents.json @@ -134,7 +134,7 @@ "note": { "type": "string", "maxLength": 2048, - "description": "An optional explanation of why this burn took place", + "description": "An optional explanation of why this mint took place", "position": 2 } }, @@ -226,6 +226,52 @@ "maxItems": 32, "description": "The identity or the group Id", "position": 2 + }, + "encryptedPersonalNote": { + "type": "array", + "byteArray": true, + "minItems": 32, + "maxItems": 2048, + "description": "An optional encrypted explanation of why this transfer took place only meant for the sender", + "position": 3 + }, + "encryptedSharedNote": { + "type": "array", + "byteArray": true, + "minItems": 32, + "maxItems": 2048, + "description": "An optional encrypted explanation of why this transfer took place shared between the sender and the receiver", + "position": 4 + }, + "publicNote": { + "type": "string", + "maxLength": 2048, + "description": "An optional public explanation of why this transfer took place", + "position": 5 + }, + "senderKeyIndex": { + "type": "integer", + "minimum": 0, + "description": "Used with the encrypted shared note", + "position": 6 + }, + "recipientKeyIndex": { + "type": "integer", + "minimum": 0, + "description": "Used with the encrypted shared note", + "position": 7 + }, + "rootEncryptionKeyIndex": { + "type": "integer", + "minimum": 0, + "description": "Used with the encrypted private note", + "position": 8 + }, + "derivationEncryptionKeyIndex": { + "type": "integer", + "minimum": 0, + "description": "Used with the encrypted private note", + "position": 9 } }, "required": [ diff --git a/packages/wasm-dpp/src/document/state_transition/batch_transition/batched_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/batch_transition/batched_transition/mod.rs index c7c58b54719..d83ae4d4735 100644 --- a/packages/wasm-dpp/src/document/state_transition/batch_transition/batched_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/batch_transition/batched_transition/mod.rs @@ -1,5 +1,5 @@ -use wasm_bindgen::prelude::wasm_bindgen; use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; +use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name=BatchedTransition)] #[derive(Debug, Clone)] diff --git a/packages/wasm-dpp/src/document/state_transition/batch_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/batch_transition/mod.rs index f0fc312bcbc..30396e17fc9 100644 --- a/packages/wasm-dpp/src/document/state_transition/batch_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/batch_transition/mod.rs @@ -31,12 +31,12 @@ use dpp::ed25519_dalek::ed25519::signature::SignerMut; use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; -use dpp::state_transition::StateTransitionIdentitySigned; use crate::batch_transition::batched_transition::BatchedTransitionWasm; +use dpp::state_transition::StateTransitionIdentitySigned; +mod batched_transition; pub mod document_transition; mod token_transition; -mod batched_transition; // pub mod validation; #[derive(Clone, Debug)] diff --git a/packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mod.rs b/packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mod.rs index 67b4b4bd885..7b10fb55c14 100644 --- a/packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mod.rs +++ b/packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mod.rs @@ -1,5 +1,5 @@ -use wasm_bindgen::prelude::wasm_bindgen; use dpp::state_transition::batch_transition::batched_transition::token_transition::TokenTransition; +use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name=TokenTransition)] #[derive(Debug, Clone)] diff --git a/packages/wasm-dpp/src/errors/consensus/consensus_error.rs b/packages/wasm-dpp/src/errors/consensus/consensus_error.rs index 85bbbc4e6b2..496ab2fc6f3 100644 --- a/packages/wasm-dpp/src/errors/consensus/consensus_error.rs +++ b/packages/wasm-dpp/src/errors/consensus/consensus_error.rs @@ -572,11 +572,7 @@ fn from_basic_error(basic_error: &BasicError) -> JsValue { .into() } BasicError::DataContractTokenConfigurationUpdateError(e) => { - generic_consensus_error!( - DataContractTokenConfigurationUpdateError, - e - ) - .into() + generic_consensus_error!(DataContractTokenConfigurationUpdateError, e).into() } } } diff --git a/packages/wasm-dpp/src/state_transition/state_transition_factory.rs b/packages/wasm-dpp/src/state_transition/state_transition_factory.rs index d57903a8dcb..2ba1a0e025c 100644 --- a/packages/wasm-dpp/src/state_transition/state_transition_factory.rs +++ b/packages/wasm-dpp/src/state_transition/state_transition_factory.rs @@ -1,5 +1,5 @@ -use crate::data_contract::{DataContractCreateTransitionWasm, DataContractUpdateTransitionWasm}; use crate::batch_transition::BatchTransitionWasm; +use crate::data_contract::{DataContractCreateTransitionWasm, DataContractUpdateTransitionWasm}; use crate::errors::from_dpp_err; use crate::identity::state_transition::{ IdentityCreateTransitionWasm, IdentityCreditTransferTransitionWasm,