Skip to content

Commit 19fbb51

Browse files
committed
chore: create wallet contract
1 parent 91a8303 commit 19fbb51

File tree

8 files changed

+574
-287
lines changed

8 files changed

+574
-287
lines changed

Cargo.lock

Lines changed: 498 additions & 287 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ rust-version = "1.80"
3838
tower-service = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }
3939
tower-layer = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }
4040
tower = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }
41+

packages/data-contracts/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ dpns-contract = { path = "../dpns-contract" }
1616
dashpay-contract = { path = "../dashpay-contract" }
1717
feature-flags-contract = { path = "../feature-flags-contract" }
1818
platform-value = { path = "../rs-platform-value" }
19+
wallet-contract = { path = "../wallet-contract" }

packages/data-contracts/src/error.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,20 @@ impl From<feature_flags_contract::Error> for Error {
102102
}
103103
}
104104
}
105+
106+
impl From<wallet_contract::Error> for Error {
107+
fn from(e: wallet_contract::Error) -> Self {
108+
match e {
109+
wallet_contract::Error::UnknownVersionMismatch {
110+
method,
111+
known_versions,
112+
received,
113+
} => Error::UnknownVersionMismatch {
114+
method,
115+
known_versions,
116+
received,
117+
},
118+
wallet_contract::Error::InvalidSchemaJson(e) => Error::InvalidSchemaJson(e),
119+
}
120+
}
121+
}

packages/data-contracts/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub enum SystemDataContract {
1919
FeatureFlags = 2,
2020
DPNS = 3,
2121
Dashpay = 4,
22+
Wallet = 5,
2223
}
2324

2425
pub struct DataContractSource {
@@ -37,6 +38,7 @@ impl SystemDataContract {
3738
SystemDataContract::FeatureFlags => feature_flags_contract::ID_BYTES,
3839
SystemDataContract::DPNS => dpns_contract::ID_BYTES,
3940
SystemDataContract::Dashpay => dashpay_contract::ID_BYTES,
41+
SystemDataContract::Wallet => wallet_contract::ID_BYTES,
4042
};
4143
Identifier::new(bytes)
4244
}
@@ -82,6 +84,13 @@ impl SystemDataContract {
8284
definitions: dashpay_contract::load_definitions(platform_version)?,
8385
document_schemas: dashpay_contract::load_documents_schemas(platform_version)?,
8486
},
87+
SystemDataContract::Wallet => DataContractSource {
88+
id_bytes: wallet_contract::ID_BYTES,
89+
owner_id_bytes: wallet_contract::OWNER_ID_BYTES,
90+
version: platform_version.system_data_contracts.wallet as u32,
91+
definitions: wallet_contract::load_definitions(platform_version)?,
92+
document_schemas: wallet_contract::load_documents_schemas(platform_version)?,
93+
},
8594
};
8695

8796
Ok(data)

packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
44
use crate::platform_types::platform_state::PlatformState;
55
use dpp::block::block_info::BlockInfo;
66
use dpp::dashcore::hashes::Hash;
7+
use dpp::data_contracts::SystemDataContract;
8+
use dpp::system_data_contracts::load_system_data_contract;
79
use dpp::version::PlatformVersion;
810
use dpp::version::ProtocolVersion;
911
use drive::drive::identity::key::fetch::{
@@ -52,6 +54,50 @@ impl<C> Platform<C> {
5254
)?;
5355
}
5456

57+
if previous_protocol_version < 6 && platform_version.protocol_version >= 6 {
58+
self.transition_to_version_6(
59+
platform_state,
60+
block_info,
61+
transaction,
62+
platform_version,
63+
)?;
64+
}
65+
66+
Ok(())
67+
}
68+
69+
/// Initializes an empty sum tree for withdrawal transactions required for protocol version 4.
70+
///
71+
/// This function is called during the transition to protocol version 4 to set up
72+
/// an empty sum tree at the specified path if it does not already exist.
73+
///
74+
/// # Parameters
75+
///
76+
/// * `transaction`: A reference to the transaction context in which the changes should be applied.
77+
/// * `platform_version`: The current platform version containing the updated protocol version and relevant configuration details.
78+
///
79+
/// # Returns
80+
///
81+
/// * `Ok(())`: If the transition to version 4 was successful.
82+
/// * `Err(Error)`: If there was an issue creating or updating the necessary data structures.
83+
fn transition_to_version_6(
84+
&self,
85+
_platform_state: &PlatformState,
86+
block_info: &BlockInfo,
87+
transaction: &Transaction,
88+
platform_version: &PlatformVersion,
89+
) -> Result<(), Error> {
90+
// We are adding the withdrawal transactions sum amount tree
91+
let contract = load_system_data_contract(SystemDataContract::Wallet, platform_version)?;
92+
93+
self.drive.insert_contract(
94+
&contract,
95+
block_info.clone(),
96+
true,
97+
Some(transaction),
98+
platform_version,
99+
)?;
100+
55101
Ok(())
56102
}
57103

packages/rs-platform-version/src/version/system_data_contract_versions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ pub struct SystemDataContractVersions {
99
pub dashpay: FeatureVersion,
1010
pub masternode_reward_shares: FeatureVersion,
1111
pub feature_flags: FeatureVersion,
12+
pub wallet: FeatureVersion,
1213
}

packages/rs-platform-version/src/version/system_data_contract_versions/v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ pub const SYSTEM_DATA_CONTRACT_VERSIONS_V1: SystemDataContractVersions =
77
dashpay: 1,
88
masternode_reward_shares: 1,
99
feature_flags: 1,
10+
wallet: 1,
1011
};

0 commit comments

Comments
 (0)