Skip to content

Commit

Permalink
chore: create wallet contract
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Nov 22, 2024
1 parent 91a8303 commit 19fbb51
Show file tree
Hide file tree
Showing 8 changed files with 574 additions and 287 deletions.
785 changes: 498 additions & 287 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ rust-version = "1.80"
tower-service = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }
tower-layer = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }
tower = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }

1 change: 1 addition & 0 deletions packages/data-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ dpns-contract = { path = "../dpns-contract" }
dashpay-contract = { path = "../dashpay-contract" }
feature-flags-contract = { path = "../feature-flags-contract" }
platform-value = { path = "../rs-platform-value" }
wallet-contract = { path = "../wallet-contract" }
17 changes: 17 additions & 0 deletions packages/data-contracts/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ impl From<feature_flags_contract::Error> for Error {
}
}
}

impl From<wallet_contract::Error> for Error {
fn from(e: wallet_contract::Error) -> Self {
match e {
wallet_contract::Error::UnknownVersionMismatch {
method,
known_versions,
received,
} => Error::UnknownVersionMismatch {
method,
known_versions,
received,
},
wallet_contract::Error::InvalidSchemaJson(e) => Error::InvalidSchemaJson(e),
}
}
}
9 changes: 9 additions & 0 deletions packages/data-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum SystemDataContract {
FeatureFlags = 2,
DPNS = 3,
Dashpay = 4,
Wallet = 5,
}

pub struct DataContractSource {
Expand All @@ -37,6 +38,7 @@ impl SystemDataContract {
SystemDataContract::FeatureFlags => feature_flags_contract::ID_BYTES,
SystemDataContract::DPNS => dpns_contract::ID_BYTES,
SystemDataContract::Dashpay => dashpay_contract::ID_BYTES,
SystemDataContract::Wallet => wallet_contract::ID_BYTES,
};
Identifier::new(bytes)
}
Expand Down Expand Up @@ -82,6 +84,13 @@ impl SystemDataContract {
definitions: dashpay_contract::load_definitions(platform_version)?,
document_schemas: dashpay_contract::load_documents_schemas(platform_version)?,
},
SystemDataContract::Wallet => DataContractSource {
id_bytes: wallet_contract::ID_BYTES,
owner_id_bytes: wallet_contract::OWNER_ID_BYTES,
version: platform_version.system_data_contracts.wallet as u32,
definitions: wallet_contract::load_definitions(platform_version)?,
document_schemas: wallet_contract::load_documents_schemas(platform_version)?,
},
};

Ok(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::platform_state::PlatformState;
use dpp::block::block_info::BlockInfo;
use dpp::dashcore::hashes::Hash;
use dpp::data_contracts::SystemDataContract;
use dpp::system_data_contracts::load_system_data_contract;
use dpp::version::PlatformVersion;
use dpp::version::ProtocolVersion;
use drive::drive::identity::key::fetch::{
Expand Down Expand Up @@ -52,6 +54,50 @@ impl<C> Platform<C> {
)?;
}

if previous_protocol_version < 6 && platform_version.protocol_version >= 6 {
self.transition_to_version_6(
platform_state,
block_info,
transaction,
platform_version,
)?;
}

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
/// an empty sum tree at the specified path if it does not already exist.
///
/// # Parameters
///
/// * `transaction`: A reference to the transaction context in which the changes should be applied.
/// * `platform_version`: The current platform version containing the updated protocol version and relevant configuration details.
///
/// # Returns
///
/// * `Ok(())`: If the transition to version 4 was successful.
/// * `Err(Error)`: If there was an issue creating or updating the necessary data structures.
fn transition_to_version_6(
&self,
_platform_state: &PlatformState,
block_info: &BlockInfo,
transaction: &Transaction,
platform_version: &PlatformVersion,
) -> Result<(), Error> {
// We are adding the withdrawal transactions sum amount tree
let contract = load_system_data_contract(SystemDataContract::Wallet, platform_version)?;

self.drive.insert_contract(
&contract,
block_info.clone(),
true,
Some(transaction),
platform_version,
)?;

Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub struct SystemDataContractVersions {
pub dashpay: FeatureVersion,
pub masternode_reward_shares: FeatureVersion,
pub feature_flags: FeatureVersion,
pub wallet: FeatureVersion,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub const SYSTEM_DATA_CONTRACT_VERSIONS_V1: SystemDataContractVersions =
dashpay: 1,
masternode_reward_shares: 1,
feature_flags: 1,
wallet: 1,
};

0 comments on commit 19fbb51

Please sign in to comment.