dpp/data_contract/methods/registration_cost/mod.rs
1mod v1;
2
3use crate::data_contract::serialized_version::DataContractInSerializationFormat;
4use crate::data_contract::DataContract;
5use crate::ProtocolError;
6use platform_version::version::PlatformVersion;
7
8impl DataContract {
9 /// Returns the registration cost of the data contract based on the current platform version
10 /// and the number of associated search keywords.
11 ///
12 /// This method dispatches to a version-specific implementation based on the
13 /// platform version configuration. If the version is unrecognized, it returns a version mismatch error.
14 ///
15 /// # Arguments
16 /// - `platform_version`: A reference to the platform version, used to determine which
17 /// registration cost algorithm to apply.
18 ///
19 /// # Returns
20 /// - `Ok(u64)`: The total registration cost in credits for this contract.
21 /// - `Err(ProtocolError)`: If the platform version is unrecognized or if the fee computation overflows.
22 ///
23 /// # Version Behavior
24 /// - Version 0: Always returns `0` (used before protocol version 9, ie before 2.0, where registration cost was not charged).
25 /// - Version 1: Uses a detailed cost model based on document types, indexes, tokens, and keyword count.
26 pub fn registration_cost(
27 &self,
28 platform_version: &PlatformVersion,
29 ) -> Result<u64, ProtocolError> {
30 match platform_version
31 .dpp
32 .contract_versions
33 .methods
34 .registration_cost
35 {
36 0 => Ok(0), // Before 2.0 it's just 0 (There was some validation cost)
37 1 => Ok(self.registration_cost_v1(platform_version)),
38 version => Err(ProtocolError::UnknownVersionMismatch {
39 method: "DataContract::registration_cost".to_string(),
40 known_versions: vec![0, 1],
41 received: version,
42 }),
43 }
44 }
45}
46
47impl DataContractInSerializationFormat {
48 /// Returns the registration cost of the data contract based on the current platform version
49 /// and the number of associated search keywords.
50 ///
51 /// This method dispatches to a version-specific implementation based on the
52 /// platform version configuration. If the version is unrecognized, it returns a version mismatch error.
53 ///
54 /// # Arguments
55 /// - `platform_version`: A reference to the platform version, used to determine which
56 /// registration cost algorithm to apply.
57 ///
58 /// # Returns
59 /// - `Ok(u64)`: The total registration cost in credits for this contract.
60 /// - `Err(ProtocolError)`: If the platform version is unrecognized or if the fee computation overflows.
61 ///
62 /// # Version Behavior
63 /// - Version 0: Always returns `0` (used before protocol version 9, ie before 2.0, where registration cost was not charged).
64 /// - Version 1: Uses a detailed cost model based on document types, indexes, tokens, and keyword count.
65 pub fn registration_cost(
66 &self,
67 platform_version: &PlatformVersion,
68 ) -> Result<u64, ProtocolError> {
69 match platform_version
70 .dpp
71 .contract_versions
72 .methods
73 .registration_cost
74 {
75 0 => Ok(0), // Before 2.0 it's just 0 (There was some validation cost)
76 1 => Ok(self.registration_cost_v1(platform_version)),
77 version => Err(ProtocolError::UnknownVersionMismatch {
78 method: "DataContract::registration_cost".to_string(),
79 known_versions: vec![0, 1],
80 received: version,
81 }),
82 }
83 }
84}