Skip to content

Commit

Permalink
compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Dec 27, 2024
1 parent b30ba05 commit 40316c0
Show file tree
Hide file tree
Showing 82 changed files with 1,550 additions and 279 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ members = [
"packages/simple-signer",
"packages/rs-json-schema-compatibility-validator",
"packages/check-features",
"packages/wallet-utils-contract"
"packages/wallet-utils-contract",
"packages/token-history-contract"
]
[workspace.package]

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"packages/masternode-reward-shares-contract",
"packages/dash-spv",
"packages/wasm-dpp",
"packages/withdrawals-contract"
"packages/withdrawals-contract",
"packages/token-history-contract"
],
"resolutions": {
"elliptic": "6.5.7",
Expand Down
1 change: 1 addition & 0 deletions packages/data-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dashpay-contract = { path = "../dashpay-contract" }
feature-flags-contract = { path = "../feature-flags-contract" }
platform-value = { path = "../rs-platform-value" }
wallet-utils-contract = { path = "../wallet-utils-contract" }
token-history-contract = { path = "../token-history-contract" }
18 changes: 18 additions & 0 deletions packages/data-contracts/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,21 @@ impl From<wallet_utils_contract::Error> for Error {
}
}
}

impl From<token_history_contract::Error> for Error {
fn from(e: token_history_contract::Error) -> Self {
match e {
token_history_contract::Error::UnknownVersionMismatch {
method,
known_versions,
received,
} => Error::UnknownVersionMismatch {
method,
known_versions,
received,
},
token_history_contract::Error::InvalidSchemaJson(e) => Error::InvalidSchemaJson(e),
}
}
}

10 changes: 10 additions & 0 deletions packages/data-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use platform_value::Identifier;
use platform_version::version::PlatformVersion;
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 All @@ -21,6 +22,7 @@ pub enum SystemDataContract {
DPNS = 3,
Dashpay = 4,
WalletUtils = 5,
TokenHistory = 6,
}

pub struct DataContractSource {
Expand All @@ -40,6 +42,7 @@ impl SystemDataContract {
SystemDataContract::DPNS => dpns_contract::ID_BYTES,
SystemDataContract::Dashpay => dashpay_contract::ID_BYTES,
SystemDataContract::WalletUtils => wallet_utils_contract::ID_BYTES,
SystemDataContract::TokenHistory => token_history_contract::ID_BYTES,
};
Identifier::new(bytes)
}
Expand Down Expand Up @@ -92,6 +95,13 @@ impl SystemDataContract {
definitions: wallet_utils_contract::load_definitions(platform_version)?,
document_schemas: wallet_utils_contract::load_documents_schemas(platform_version)?,
},
SystemDataContract::TokenHistory => DataContractSource {
id_bytes: token_history_contract::ID_BYTES,
owner_id_bytes: token_history_contract::OWNER_ID_BYTES,
version: platform_version.system_data_contracts.wallet as u32,
definitions: token_history_contract::load_definitions(platform_version)?,
document_schemas: token_history_contract::load_documents_schemas(platform_version)?,
},
};

Ok(data)
Expand Down
7 changes: 7 additions & 0 deletions packages/rs-dpp/src/data_contract/accessors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ impl DataContractV1Getters for DataContract {
DataContract::V1(v1) => Some(&mut v1.tokens),
}
}

fn token_id(&self, position: TokenContractPosition) -> Option<Identifier> {
match self {
DataContract::V0(_) => None,
DataContract::V1(v1) => v1.token_id(position),
}
}
}

impl DataContractV1Setters for DataContract {
Expand Down
4 changes: 4 additions & 0 deletions packages/rs-dpp/src/data_contract/accessors/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::data_contract::associated_token::token_configuration::TokenConfigurat
use crate::data_contract::group::{Group, GroupName};
use crate::data_contract::TokenContractPosition;
use std::collections::BTreeMap;
use platform_value::Identifier;

pub trait DataContractV1Getters: DataContractV0Getters {
/// Returns a reference to the groups map.
Expand All @@ -16,6 +17,9 @@ 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>;
}

pub trait DataContractV1Setters: DataContractV0Setters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt;

pub mod accessors;
mod methods;
mod v0;
pub mod v0;

#[derive(Serialize, Deserialize, Encode, Decode, Debug, Clone, PartialEq, Eq, From)]
#[serde(tag = "$format_version")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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 Down Expand Up @@ -66,3 +67,52 @@ impl fmt::Display for TokenConfigurationV0 {
)
}
}

impl TokenConfigurationV0 {
pub fn default_most_restrictive() -> Self {
Self {
conventions: TokenConfigurationConventionV0 { localizations: Default::default(), decimals: 8 },
base_supply: 100000,
max_supply: None,
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(),
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(),
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(),
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(),
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(),
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(),
main_control_group: None,
main_control_group_can_be_modified: AuthorizedActionTakers::NoOne,
}
}
}
5 changes: 3 additions & 2 deletions packages/rs-dpp/src/data_contract/change_control_rules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
pub mod authorized_action_takers;
mod v0;
pub mod v0;

use crate::data_contract::change_control_rules::v0::ChangeControlRulesV0;
use crate::data_contract::group::Group;
use crate::multi_identity_events::ActionTaker;
use bincode::{Decode, Encode};
use derive_more::From;
use platform_value::Identifier;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Decode, Encode, Debug, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Decode, Encode, Debug, Clone, PartialEq, Eq, From)]
pub enum ChangeControlRules {
V0(ChangeControlRulesV0),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Decode, Encode, Debug, Clone, PartialEq, Eq)]
pub struct ChangeControlRulesV0 {
/// This is who is authorized to make such a change
authorized_to_make_change: AuthorizedActionTakers,
pub authorized_to_make_change: AuthorizedActionTakers,
/// This is who is authorized to make such a change to the people authorized to make a change
authorized_to_change_authorized_action_takers: AuthorizedActionTakers,
pub authorized_to_change_authorized_action_takers: AuthorizedActionTakers,
/// Are we allowed to change to None in the future
changing_authorized_action_takers_to_no_one_allowed: bool,
pub changing_authorized_action_takers_to_no_one_allowed: bool,
/// Are we allowed to change to None in the future
changing_authorized_action_takers_to_contract_owner_allowed: bool,
pub changing_authorized_action_takers_to_contract_owner_allowed: bool,
}

impl ChangeControlRulesV0 {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-dpp/src/data_contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod serialized_version;
pub use methods::*;
pub mod accessors;
pub mod associated_token;
mod change_control_rules;
pub mod change_control_rules;
pub mod config;
mod group;
pub mod storage_requirements;
Expand Down
11 changes: 11 additions & 0 deletions packages/rs-dpp/src/data_contract/v1/accessors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::data_contract::document_type::accessors::DocumentTypeV0Getters;
use crate::data_contract::group::{Group, GroupName};
use platform_value::Identifier;
use std::collections::BTreeMap;
use crate::util::hash::hash_double;

impl DataContractV0Getters for DataContractV1 {
fn id(&self) -> Identifier {
Expand Down Expand Up @@ -158,6 +159,16 @@ impl DataContractV1Getters for DataContractV1 {
fn tokens_mut(&mut self) -> Option<&mut BTreeMap<TokenContractPosition, TokenConfiguration>> {
Some(&mut self.tokens)
}

/// Returns the token id if a token exists at that position
fn token_id(&self, position: TokenContractPosition) -> Option<Identifier> {
self.tokens.get(&position).map(|_| {
let mut bytes = b"dash_token".to_vec();
bytes.extend_from_slice(self.id().as_bytes());
bytes.extend_from_slice(&position.to_be_bytes());
hash_double(bytes).into()
})
}
}

impl DataContractV1Setters for DataContractV1 {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-dpp/src/data_contract/v1/methods/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod test {
use super::*;
use crate::data_contract::config::DataContractConfig;
use crate::data_contract::serialized_version::v0::DataContractInSerializationFormatV0;
use crate::data_contract::v0::DataContractV1;
use crate::data_contract::v1::DataContractV1;
use platform_value::{platform_value, Identifier};

#[test]
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-dpp/src/state_transition/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod tests {
};
use crate::state_transition::batch_transition::batched_transition::document_transition_action_type::DocumentTransitionActionType;
use crate::state_transition::batch_transition::{
BatchTransition, BatchTransitionV0,
BatchTransition, BatchTransitionV1,
};
use crate::state_transition::identity_create_transition::v0::IdentityCreateTransitionV0;
use crate::state_transition::identity_create_transition::IdentityCreateTransition;
Expand Down Expand Up @@ -342,7 +342,7 @@ mod tests {
[(DocumentTransitionActionType::Create, documents)],
&mut nonces,
);
let documents_batch_transition: BatchTransition = BatchTransitionV0 {
let documents_batch_transition: BatchTransition = BatchTransitionV1 {
owner_id: data_contract.owner_id(),
transitions,
..Default::default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ impl<'a> StateTransitionJsonConvert<'a> for BatchTransition {
);
Ok(value)
}
BatchTransition::V1(transition) => {
let mut value = transition.to_json(options)?;
let map_value = value.as_object_mut().expect("expected an object");
map_value.insert(
STATE_TRANSITION_PROTOCOL_VERSION.to_string(),
JsonValue::Number(Number::from(1)),
);
Ok(value)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::state_transition::batch_transition::BatchTransitionV0;
use crate::state_transition::batch_transition::BatchTransitionV1;
use crate::state_transition::StateTransitionValueConvert;

impl<'a> StateTransitionValueConvert<'a> for BatchTransitionV0 {}
impl<'a> StateTransitionValueConvert<'a> for BatchTransitionV1 {}
Loading

0 comments on commit 40316c0

Please sign in to comment.