Skip to content

Commit

Permalink
a lot more work
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Dec 28, 2024
1 parent 40316c0 commit e23bcda
Show file tree
Hide file tree
Showing 65 changed files with 1,526 additions and 270 deletions.
1 change: 0 additions & 1 deletion packages/data-contracts/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,3 @@ impl From<token_history_contract::Error> for Error {
}
}
}

2 changes: 1 addition & 1 deletion packages/data-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-dpp/src/data_contract/accessors/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,7 +17,7 @@ pub trait DataContractV1Getters: DataContractV0Getters {

/// Returns a mutable reference to the tokens map.
fn tokens_mut(&mut self) -> Option<&mut BTreeMap<TokenContractPosition, TokenConfiguration>>;

/// Returns the token id at a certain position
fn token_id(&self, position: TokenContractPosition) -> Option<Identifier>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> {
match self {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<u64>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> {
self.max_supply
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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};
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")]
Expand All @@ -33,6 +33,8 @@ pub struct TokenConfigurationV0 {
pub base_supply: u64,
/// The maximum supply the token can ever have
pub max_supply: Option<u64>,
/// 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,
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-dpp/src/data_contract/v1/accessors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/rs-dpp/src/document/generate_document_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::document::Document;
use crate::prelude::IdentityNonce;
use crate::{prelude::Identifier, util::hash::hash_double_to_vec};

impl Document {
Expand Down
9 changes: 9 additions & 0 deletions packages/rs-dpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>;

/// Sets the `public_note` field in the `TokenBurnTransitionV0`.
fn set_public_note(&mut self, public_note: Option<String>);
}

impl TokenBurnTransitionV0Methods for TokenBurnTransitionV0 {
Expand All @@ -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<String> {
self.public_note
}

fn set_public_note(&mut self, public_note: Option<String>) {
self.public_note = public_note;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
match self {
TokenBurnTransition::V0(v0) => v0.public_note_owned(),
}
}

fn set_public_note(&mut self, public_note: Option<String>) {
match self {
TokenBurnTransition::V0(v0) => v0.set_public_note(public_note),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Identifier>,

/// 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<String>,
}

impl fmt::Display for TokenIssuanceTransitionV0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String>;

/// Sets the value of the `public_note` field in the `TokenIssuanceTransitionV0`.
fn set_public_note(&mut self, public_note: Option<String>);

/// Returns the `issued_to_identity_id` field of the `TokenIssuanceTransitionV0`.
fn issued_to_identity_id(&self) -> Option<Identifier>;

/// 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<Identifier>);
}

impl TokenIssuanceTransitionV0Methods for TokenIssuanceTransitionV0 {
Expand All @@ -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<String> {
self.public_note
}

fn set_public_note(&mut self, public_note: Option<String>) {
self.public_note = public_note;
}

fn issued_to_identity_id(&self) -> Option<Identifier> {
self.issued_to_identity_id
}
fn set_issued_to_identity_id(&mut self, issued_to_identity_id: Option<Identifier>) {
self.issued_to_identity_id = issued_to_identity_id;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String> {
match self {
TokenIssuanceTransition::V0(v0) => v0.public_note_owned(),
}
}

fn set_public_note(&mut self, public_note: Option<String>) {
match self {
TokenIssuanceTransition::V0(v0) => v0.set_public_note(public_note),
}
}

fn issued_to_identity_id(&self) -> Option<Identifier> {
match self {
TokenIssuanceTransition::V0(v0) => v0.issued_to_identity_id(),
}
}

fn set_issued_to_identity_id(&mut self, issued_to_identity_id: Option<Identifier>) {
match self {
TokenIssuanceTransition::V0(v0) => v0.set_issued_to_identity_id(issued_to_identity_id),
}
}
}
Loading

0 comments on commit e23bcda

Please sign in to comment.