Skip to content

Commit

Permalink
work on group actions
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Dec 30, 2024
1 parent e23bcda commit 4135031
Show file tree
Hide file tree
Showing 89 changed files with 1,890 additions and 251 deletions.
16 changes: 9 additions & 7 deletions packages/rs-dpp/src/data_contract/accessors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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, TokenContractPosition, EMPTY_GROUPS, EMPTY_TOKENS};
use crate::data_contract::{
DocumentName, GroupContractPosition, TokenContractPosition, EMPTY_GROUPS, EMPTY_TOKENS,
};
use crate::metadata::Metadata;
use crate::prelude::DataContract;

Expand All @@ -10,7 +12,7 @@ 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 crate::data_contract::group::Group;
use std::collections::BTreeMap;

pub mod v0;
Expand Down Expand Up @@ -187,7 +189,7 @@ 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> {
fn groups(&self) -> &BTreeMap<GroupContractPosition, Group> {
match self {
DataContract::V0(_) => &EMPTY_GROUPS,
DataContract::V1(v1) => &v1.groups,
Expand All @@ -196,7 +198,7 @@ impl DataContractV1Getters for DataContract {

/// 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>> {
fn groups_mut(&mut self) -> Option<&mut BTreeMap<GroupContractPosition, Group>> {
match self {
DataContract::V0(_) => None,
DataContract::V1(v1) => Some(&mut v1.groups),
Expand Down Expand Up @@ -230,7 +232,7 @@ impl DataContractV1Getters for DataContract {

impl DataContractV1Setters for DataContract {
/// Sets the groups map for the data contract.
fn set_groups(&mut self, groups: BTreeMap<GroupName, Group>) {
fn set_groups(&mut self, groups: BTreeMap<GroupContractPosition, Group>) {
match self {
DataContract::V0(_) => {}
DataContract::V1(v1) => {
Expand All @@ -250,11 +252,11 @@ impl DataContractV1Setters for DataContract {
}

/// Adds or updates a single group in the groups map.
fn add_group(&mut self, name: GroupName, group: Group) {
fn add_group(&mut self, position: GroupContractPosition, group: Group) {
match self {
DataContract::V0(_) => {}
DataContract::V1(v1) => {
v1.groups.insert(name, group);
v1.groups.insert(position, group);
}
}
}
Expand Down
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,16 +1,16 @@
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::TokenContractPosition;
use crate::data_contract::group::Group;
use crate::data_contract::{GroupContractPosition, TokenContractPosition};
use platform_value::Identifier;
use std::collections::BTreeMap;

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

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

/// Returns a reference to the tokens map.
fn tokens(&self) -> &BTreeMap<TokenContractPosition, TokenConfiguration>;
Expand All @@ -24,13 +24,13 @@ pub trait DataContractV1Getters: DataContractV0Getters {

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

/// Sets the tokens map for the data contract.
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);
fn add_group(&mut self, pos: GroupContractPosition, group: Group);

/// Adds or updates a single token configuration in the tokens map.
fn add_token(&mut self, pos: TokenContractPosition, token: TokenConfiguration);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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 Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::data_contract::associated_token::token_configuration::v0::TokenConfigurationV0;
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use bincode::{Decode, Encode};
use derive_more::From;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::data_contract::change_control_rules::authorized_action_takers::Author
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 bincode::{Decode, Encode};
use platform_value::Identifier;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::data_contract::group::accessors::v0::GroupV0Getters;
use crate::data_contract::group::{Group, GroupMemberPower};
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use crate::multi_identity_events::ActionTaker;
use bincode::{Decode, Encode};
use platform_value::Identifier;
use serde::{Deserialize, Serialize};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::consensus::basic::data_contract::UnknownDocumentCreationRestrictionModeError;
use crate::consensus::basic::BasicError;
use crate::consensus::ConsensusError;
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use crate::ProtocolError;
use bincode::{Decode, Encode};
use std::fmt;
use std::fmt::{Display, Formatter};

Expand Down
20 changes: 16 additions & 4 deletions packages/rs-dpp/src/data_contract/group/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
use crate::data_contract::group::accessors::v0::{GroupV0Getters, GroupV0Setters};
use crate::data_contract::group::v0::GroupV0;
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use crate::errors::ProtocolError;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use platform_value::Identifier;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

pub mod accessors;
mod v0;

pub type GroupName = String;
pub type RequiredSigners = u8;

pub type GroupMemberPower = u32;
pub type GroupRequiredPower = u32;
#[derive(Serialize, Deserialize, Decode, Encode, Debug, Clone, PartialEq, Eq)]
#[derive(
Serialize,
Deserialize,
Decode,
Encode,
PlatformSerialize,
PlatformDeserialize,
Debug,
Clone,
PartialEq,
Eq,
)]
#[platform_serialize(unversioned)]
pub enum Group {
V0(GroupV0),
}
Expand Down
18 changes: 16 additions & 2 deletions packages/rs-dpp/src/data_contract/group/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
use crate::data_contract::group::accessors::v0::{GroupV0Getters, GroupV0Setters};
use crate::data_contract::group::{GroupMemberPower, GroupRequiredPower};
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use crate::ProtocolError;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use platform_value::Identifier;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

#[derive(Serialize, Deserialize, Decode, Encode, Debug, Clone, PartialEq, Eq)]
#[derive(
Serialize,
Deserialize,
Decode,
Encode,
PlatformSerialize,
PlatformDeserialize,
Debug,
Clone,
PartialEq,
Eq,
)]
#[platform_serialize(unversioned)]
pub struct GroupV0 {
pub members: BTreeMap<Identifier, GroupMemberPower>,
pub required_power: GroupRequiredPower,
Expand Down
7 changes: 4 additions & 3 deletions packages/rs-dpp/src/data_contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod accessors;
pub mod associated_token;
pub mod change_control_rules;
pub mod config;
mod group;
pub mod group;
pub mod storage_requirements;

use crate::data_contract::serialized_version::{
Expand All @@ -51,7 +51,7 @@ use crate::ProtocolError;
use crate::ProtocolError::{PlatformDeserializationError, PlatformSerializationError};

use crate::data_contract::associated_token::token_configuration::TokenConfiguration;
use crate::data_contract::group::{Group, GroupName};
use crate::data_contract::group::Group;
use crate::data_contract::v0::DataContractV0;
use crate::data_contract::v1::DataContractV1;
use platform_version::TryIntoPlatformVersioned;
Expand All @@ -62,13 +62,14 @@ type JsonSchema = JsonValue;
type DefinitionName = String;
pub type DocumentName = String;
pub type TokenName = String;
pub type GroupContractPosition = u16;
pub type TokenContractPosition = u16;
type PropertyPath = String;

pub const INITIAL_DATA_CONTRACT_VERSION: u32 = 1;

// Define static empty BTreeMaps
static EMPTY_GROUPS: Lazy<BTreeMap<GroupName, Group>> = Lazy::new(|| BTreeMap::new());
static EMPTY_GROUPS: Lazy<BTreeMap<GroupContractPosition, Group>> = Lazy::new(|| BTreeMap::new());
static EMPTY_TOKENS: Lazy<BTreeMap<TokenContractPosition, TokenConfiguration>> =
Lazy::new(|| BTreeMap::new());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::data_contract::document_type::accessors::DocumentTypeV0Getters;
use crate::data_contract::v0::DataContractV0;
use crate::data_contract::v1::DataContractV1;
use crate::data_contract::{DataContract, DefinitionName, DocumentName};
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use bincode::{Decode, Encode};
use platform_value::{Identifier, Value};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
Expand Down
10 changes: 6 additions & 4 deletions packages/rs-dpp/src/data_contract/serialized_version/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use crate::data_contract::config::DataContractConfig;
use crate::data_contract::document_type::accessors::DocumentTypeV0Getters;

use crate::data_contract::associated_token::token_configuration::TokenConfiguration;
use crate::data_contract::group::{Group, GroupName};
use crate::data_contract::group::Group;
use crate::data_contract::v0::DataContractV0;
use crate::data_contract::v1::DataContractV1;
use crate::data_contract::{DataContract, DefinitionName, DocumentName, TokenContractPosition};
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use crate::data_contract::{
DataContract, DefinitionName, DocumentName, GroupContractPosition, TokenContractPosition,
};
use bincode::{Decode, Encode};
use platform_value::{Identifier, Value};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -35,7 +37,7 @@ pub struct DataContractInSerializationFormatV1 {
pub document_schemas: BTreeMap<DocumentName, Value>,

/// Groups that allow for specific multiparty actions on the contract
pub groups: BTreeMap<GroupName, Group>,
pub groups: BTreeMap<GroupContractPosition, Group>,

/// The tokens on the contract.
pub tokens: BTreeMap<TokenContractPosition, TokenConfiguration>,
Expand Down
14 changes: 7 additions & 7 deletions packages/rs-dpp/src/data_contract/v1/accessors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::data_contract::document_type::{DocumentType, DocumentTypeRef};
use crate::data_contract::errors::DataContractError;

use crate::data_contract::v1::DataContractV1;
use crate::data_contract::{DocumentName, TokenContractPosition};
use crate::data_contract::{DocumentName, GroupContractPosition, TokenContractPosition};
use crate::metadata::Metadata;

use crate::data_contract::accessors::v1::{DataContractV1Getters, DataContractV1Setters};
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::data_contract::group::Group;
use crate::util::hash::hash_double;
use platform_value::Identifier;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -144,11 +144,11 @@ impl DataContractV0Setters for DataContractV1 {
}

impl DataContractV1Getters for DataContractV1 {
fn groups(&self) -> &BTreeMap<GroupName, Group> {
fn groups(&self) -> &BTreeMap<GroupContractPosition, Group> {
&self.groups
}

fn groups_mut(&mut self) -> Option<&mut BTreeMap<GroupName, Group>> {
fn groups_mut(&mut self) -> Option<&mut BTreeMap<GroupContractPosition, Group>> {
Some(&mut self.groups)
}

Expand All @@ -172,16 +172,16 @@ impl DataContractV1Getters for DataContractV1 {
}

impl DataContractV1Setters for DataContractV1 {
fn set_groups(&mut self, groups: BTreeMap<GroupName, Group>) {
fn set_groups(&mut self, groups: BTreeMap<GroupContractPosition, Group>) {
self.groups = groups;
}

fn set_tokens(&mut self, tokens: BTreeMap<TokenContractPosition, TokenConfiguration>) {
self.tokens = tokens;
}

fn add_group(&mut self, name: GroupName, group: Group) {
self.groups.insert(name, group);
fn add_group(&mut self, group_position: GroupContractPosition, group: Group) {
self.groups.insert(group_position, group);
}

fn add_token(&mut self, name: TokenContractPosition, token: TokenConfiguration) {
Expand Down
10 changes: 6 additions & 4 deletions packages/rs-dpp/src/data_contract/v1/data_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use platform_value::Value;
use crate::data_contract::associated_token::token_configuration::TokenConfiguration;
use crate::data_contract::config::DataContractConfig;
use crate::data_contract::document_type::DocumentType;
use crate::data_contract::group::{Group, GroupName};
use crate::data_contract::{DefinitionName, DocumentName, TokenContractPosition};
use crate::data_contract::group::Group;
use crate::data_contract::{
DefinitionName, DocumentName, GroupContractPosition, TokenContractPosition,
};
use crate::metadata::Metadata;

/// `DataContractV1` represents a data contract in a decentralized platform.
Expand All @@ -24,7 +26,7 @@ use crate::metadata::Metadata;
/// In `DataContractV1`, two significant features were introduced to enhance contract governance
/// and support token-related operations:
///
/// 1. **Groups** (`groups: BTreeMap<GroupName, Group>`)
/// 1. **Groups** (`groups: BTreeMap<GroupContractPosition, Group>`)
/// - Groups allow for specific multiparty actions on the contract. Each group is defined with a
/// set of members (`Identifier`) and their corresponding member power (`u32`).
/// - Groups facilitate fine-grained access control and decision-making processes by enabling
Expand Down Expand Up @@ -66,7 +68,7 @@ pub struct DataContractV1 {
pub schema_defs: Option<BTreeMap<DefinitionName, Value>>,

/// Groups that allow for specific multiparty actions on the contract
pub groups: BTreeMap<GroupName, Group>,
pub groups: BTreeMap<GroupContractPosition, Group>,

/// The tokens on the contract.
pub tokens: BTreeMap<TokenContractPosition, TokenConfiguration>,
Expand Down
1 change: 0 additions & 1 deletion packages/rs-dpp/src/document/generate_document_id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::document::Document;
use crate::prelude::IdentityNonce;
use crate::{prelude::Identifier, util::hash::hash_double_to_vec};

impl Document {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::consensus::state::data_trigger::data_trigger_invalid_result_error::Da
use crate::consensus::state::state_error::StateError;
use crate::consensus::ConsensusError;
use crate::errors::ProtocolError;
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use thiserror::Error;

Expand Down
12 changes: 12 additions & 0 deletions packages/rs-dpp/src/group/action_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::tokens::token_event::TokenEvent;
use crate::ProtocolError;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};

#[derive(
Debug, PartialEq, PartialOrd, Clone, Eq, Encode, Decode, PlatformDeserialize, PlatformSerialize,
)]
#[platform_serialize(unversioned)] //versioned directly, no need to use platform_version
pub enum GroupActionEvent {
TokenEvent(TokenEvent),
}
14 changes: 14 additions & 0 deletions packages/rs-dpp/src/group/group_action/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod v0;

use crate::group::group_action::v0::GroupActionV0;
use crate::ProtocolError;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};

#[derive(
Debug, PartialEq, PartialOrd, Clone, Eq, Encode, Decode, PlatformDeserialize, PlatformSerialize,
)]
#[platform_serialize(unversioned)] //versioned directly, no need to use platform_version
pub enum GroupAction {
V0(GroupActionV0),
}
Loading

0 comments on commit 4135031

Please sign in to comment.