Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Dec 15, 2024
1 parent f886d8d commit dc8e575
Show file tree
Hide file tree
Showing 46 changed files with 1,013 additions and 162 deletions.
84 changes: 83 additions & 1 deletion packages/rs-dpp/src/data_contract/accessors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters};
use crate::data_contract::config::DataContractConfig;
use crate::data_contract::document_type::{DocumentType, DocumentTypeRef};
use crate::data_contract::DocumentName;
use crate::data_contract::{DocumentName, TokenContractPosition, EMPTY_GROUPS, EMPTY_TOKENS};
use crate::metadata::Metadata;
use crate::prelude::DataContract;

use platform_value::Identifier;

use crate::data_contract::accessors::v1::{DataContractV1Getters, DataContractV1Setters};
use crate::data_contract::associated_token::token_configuration::TokenConfiguration;
use crate::data_contract::errors::DataContractError;
use crate::data_contract::group::{Group, GroupName};
use std::collections::BTreeMap;

pub mod v0;
Expand Down Expand Up @@ -180,3 +183,82 @@ impl DataContractV0Setters for DataContract {
}
}
}

/// Implementing DataContractV1Getters for DataContract
impl DataContractV1Getters for DataContract {
/// Returns a reference to the groups map.
fn groups(&self) -> &BTreeMap<GroupName, Group> {
match self {
DataContract::V0(_) => &EMPTY_GROUPS,
DataContract::V1(v1) => &v1.groups,
}
}

/// Returns a mutable reference to the groups map.
/// Returns `None` for V0 since it doesn't have groups.
fn groups_mut(&mut self) -> Option<&mut BTreeMap<GroupName, Group>> {
match self {
DataContract::V0(_) => None,
DataContract::V1(v1) => Some(&mut v1.groups),
}
}

/// Returns a reference to the tokens map.
fn tokens(&self) -> &BTreeMap<TokenContractPosition, TokenConfiguration> {
match self {
DataContract::V0(_) => &EMPTY_TOKENS,
DataContract::V1(v1) => &v1.tokens,
}
}

/// Returns a mutable reference to the tokens map.
/// Returns `None` for V0 since it doesn't have tokens.
fn tokens_mut(&mut self) -> Option<&mut BTreeMap<TokenContractPosition, TokenConfiguration>> {
match self {
DataContract::V0(_) => None,
DataContract::V1(v1) => Some(&mut v1.tokens),
}
}
}

impl DataContractV1Setters for DataContract {
/// Sets the groups map for the data contract.
fn set_groups(&mut self, groups: BTreeMap<GroupName, Group>) {
match self {
DataContract::V0(_) => {}
DataContract::V1(v1) => {
v1.groups = groups;
}
}
}

/// Sets the tokens map for the data contract.
fn set_tokens(&mut self, tokens: BTreeMap<TokenContractPosition, TokenConfiguration>) {
match self {
DataContract::V0(_) => {}
DataContract::V1(v1) => {
v1.tokens = tokens;
}
}
}

/// Adds or updates a single group in the groups map.
fn add_group(&mut self, name: GroupName, group: Group) {
match self {
DataContract::V0(_) => {}
DataContract::V1(v1) => {
v1.groups.insert(name, group);
}
}
}

/// Adds or updates a single token configuration in the tokens map.
fn add_token(&mut self, id: TokenContractPosition, token: TokenConfiguration) {
match self {
DataContract::V0(_) => {}
DataContract::V1(v1) => {
v1.tokens.insert(id, token);
}
}
}
}
12 changes: 6 additions & 6 deletions packages/rs-dpp/src/data_contract/accessors/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
use crate::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters};
use crate::data_contract::associated_token::token_configuration::TokenConfiguration;
use crate::data_contract::group::{Group, GroupName};
use crate::data_contract::TokenName;
use crate::data_contract::TokenContractPosition;
use std::collections::BTreeMap;

pub trait DataContractV1Getters: DataContractV0Getters {
/// Returns a reference to the groups map.
fn groups(&self) -> &BTreeMap<GroupName, Group>;

/// Returns a mutable reference to the groups map.
fn groups_mut(&mut self) -> &mut BTreeMap<GroupName, Group>;
fn groups_mut(&mut self) -> Option<&mut BTreeMap<GroupName, Group>>;

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

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

pub trait DataContractV1Setters: DataContractV0Setters {
/// Sets the groups map for the data contract.
fn set_groups(&mut self, groups: BTreeMap<GroupName, Group>);

/// Sets the tokens map for the data contract.
fn set_tokens(&mut self, tokens: BTreeMap<TokenName, TokenConfiguration>);
fn set_tokens(&mut self, tokens: BTreeMap<TokenContractPosition, TokenConfiguration>);

/// Adds or updates a single group in the groups map.
fn add_group(&mut self, name: GroupName, group: Group);

/// Adds or updates a single token configuration in the tokens map.
fn add_token(&mut self, name: TokenName, token: TokenConfiguration);
fn add_token(&mut self, pos: TokenContractPosition, token: TokenConfiguration);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
pub mod v0;

use crate::data_contract::associated_token::token_configuration::accessors::v0::{
TokenConfigurationV0Getters, TokenConfigurationV0Setters,
};
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;
use platform_value::Identifier;
use std::collections::BTreeSet;

/// Implementing TokenConfigurationV0Getters for TokenConfiguration
impl TokenConfigurationV0Getters for TokenConfiguration {
/// Returns a reference to the conventions.
fn conventions(&self) -> &TokenConfigurationConventionV0 {
match self {
TokenConfiguration::V0(v0) => v0.conventions(),
}
}

/// Returns a mutable reference to the conventions.
fn conventions_mut(&mut self) -> &mut TokenConfigurationConventionV0 {
match self {
TokenConfiguration::V0(v0) => v0.conventions_mut(),
}
}

/// Returns the base supply.
fn base_supply(&self) -> u64 {
match self {
TokenConfiguration::V0(v0) => v0.base_supply(),
}
}

/// Returns the maximum supply.
fn max_supply(&self) -> Option<u64> {
match self {
TokenConfiguration::V0(v0) => v0.max_supply(),
}
}

/// Returns the max supply change rules.
fn max_supply_change_rules(&self) -> &ChangeControlRules {
match self {
TokenConfiguration::V0(v0) => v0.max_supply_change_rules(),
}
}

/// Returns the new tokens destination identity.
fn new_tokens_destination_identity(&self) -> Option<Identifier> {
match self {
TokenConfiguration::V0(v0) => v0.new_tokens_destination_identity(),
}
}

/// Returns the new tokens destination identity rules.
fn new_tokens_destination_identity_rules(&self) -> &ChangeControlRules {
match self {
TokenConfiguration::V0(v0) => v0.new_tokens_destination_identity_rules(),
}
}

/// Returns the manual minting rules.
fn manual_minting_rules(&self) -> &ChangeControlRules {
match self {
TokenConfiguration::V0(v0) => v0.manual_minting_rules(),
}
}

/// Returns the manual burning rules.
fn manual_burning_rules(&self) -> &ChangeControlRules {
match self {
TokenConfiguration::V0(v0) => v0.manual_burning_rules(),
}
}

/// Returns the freeze rules.
fn freeze_rules(&self) -> &ChangeControlRules {
match self {
TokenConfiguration::V0(v0) => v0.freeze_rules(),
}
}

/// Returns the unfreeze rules.
fn unfreeze_rules(&self) -> &ChangeControlRules {
match self {
TokenConfiguration::V0(v0) => v0.unfreeze_rules(),
}
}

/// Returns the main control group.
fn main_control_group(&self) -> Option<&(BTreeSet<Identifier>, RequiredSigners)> {
match self {
TokenConfiguration::V0(v0) => v0.main_control_group(),
}
}

/// Returns the main control group can be modified.
fn main_control_group_can_be_modified(&self) -> &AuthorizedActionTakers {
match self {
TokenConfiguration::V0(v0) => v0.main_control_group_can_be_modified(),
}
}
}

/// Implementing TokenConfigurationV0Setters for TokenConfiguration
impl TokenConfigurationV0Setters for TokenConfiguration {
/// Sets the conventions.
fn set_conventions(&mut self, conventions: TokenConfigurationConventionV0) {
match self {
TokenConfiguration::V0(v0) => v0.set_conventions(conventions),
}
}

/// Sets the base supply.
fn set_base_supply(&mut self, base_supply: u64) {
match self {
TokenConfiguration::V0(v0) => v0.set_base_supply(base_supply),
}
}

/// Sets the maximum supply.
fn set_max_supply(&mut self, max_supply: Option<u64>) {
match self {
TokenConfiguration::V0(v0) => v0.set_max_supply(max_supply),
}
}

/// Sets the max supply change rules.
fn set_max_supply_change_rules(&mut self, rules: ChangeControlRules) {
match self {
TokenConfiguration::V0(v0) => v0.set_max_supply_change_rules(rules),
}
}

/// Sets the new tokens destination identity.
fn set_new_tokens_destination_identity(&mut self, id: Option<Identifier>) {
match self {
TokenConfiguration::V0(v0) => v0.set_new_tokens_destination_identity(id),
}
}

/// Sets the new tokens destination identity rules.
fn set_new_tokens_destination_identity_rules(&mut self, rules: ChangeControlRules) {
match self {
TokenConfiguration::V0(v0) => v0.set_new_tokens_destination_identity_rules(rules),
}
}

/// Sets the manual minting rules.
fn set_manual_minting_rules(&mut self, rules: ChangeControlRules) {
match self {
TokenConfiguration::V0(v0) => v0.set_manual_minting_rules(rules),
}
}

/// Sets the manual burning rules.
fn set_manual_burning_rules(&mut self, rules: ChangeControlRules) {
match self {
TokenConfiguration::V0(v0) => v0.set_manual_burning_rules(rules),
}
}

/// Sets the freeze rules.
fn set_freeze_rules(&mut self, rules: ChangeControlRules) {
match self {
TokenConfiguration::V0(v0) => v0.set_freeze_rules(rules),
}
}

/// Sets the unfreeze rules.
fn set_unfreeze_rules(&mut self, rules: ChangeControlRules) {
match self {
TokenConfiguration::V0(v0) => v0.set_unfreeze_rules(rules),
}
}

/// Sets the main control group.
fn set_main_control_group(&mut self, group: Option<(BTreeSet<Identifier>, RequiredSigners)>) {
match self {
TokenConfiguration::V0(v0) => v0.set_main_control_group(group),
}
}

/// Sets the main control group can be modified.
fn set_main_control_group_can_be_modified(&mut self, action_takers: AuthorizedActionTakers) {
match self {
TokenConfiguration::V0(v0) => v0.set_main_control_group_can_be_modified(action_takers),
}
}
}
Loading

0 comments on commit dc8e575

Please sign in to comment.