Skip to content

Commit b521d53

Browse files
chore: clean dpp clippy (#2764)
1 parent 3af1aaf commit b521d53

File tree

37 files changed

+108
-106
lines changed

37 files changed

+108
-106
lines changed

packages/rs-dapi-client/src/dump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<T: TransportRequest> DumpData<T> {
105105
// Return request type (T) name without module prefix
106106
fn request_type() -> String {
107107
let req_type = std::any::type_name::<T>();
108-
req_type.split(':').last().unwrap_or(req_type).to_string()
108+
req_type.rsplit(':').next().unwrap_or(req_type).to_string()
109109
}
110110
/// Generate unique filename for this dump.
111111
///

packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ pub enum DistributionFunction {
119119
/// - `step_count`: The number of periods between each step.
120120
/// - `decrease_per_interval_numerator` and `decrease_per_interval_denominator`: Define the reduction factor per step.
121121
/// - `start_decreasing_offset`: Optional start period offset (e.g., start block or time). If not provided, the contract creation start is used.
122-
/// If this is provided before this number we give out the distribution start amount every interval.
122+
/// If this is provided before this number we give out the distribution start amount every interval.
123123
/// - `max_interval_count`: The maximum amount of intervals there can be. Can be up to 1024.
124-
/// !!!Very important!!! -> This will default to 128 is default if not set.
125-
/// This means that after 128 cycles we will be distributing trailing_distribution_interval_amount per interval.
124+
/// !!!Very important!!! -> This will default to 128 is default if not set.
125+
/// This means that after 128 cycles we will be distributing trailing_distribution_interval_amount per interval.
126126
/// - `distribution_start_amount`: The initial token emission.
127127
/// - `trailing_distribution_interval_amount`: The token emission after all decreasing intervals.
128128
/// - `min_value`: Optional minimum emission value.
@@ -524,6 +524,7 @@ pub enum DistributionFunction {
524524
/// f(x) = 10000 * ln(5000 / x)
525525
/// ```
526526
/// - Values: a = 10000 n = 5000 m = 1 o = 0 b = 0 d = 0
527+
/// ```text
527528
/// y
528529
/// ↑
529530
/// 10000 |*
@@ -538,6 +539,7 @@ pub enum DistributionFunction {
538539
/// 1000 | *
539540
/// 0 +-------------------*----------→ x
540541
/// 0 2000 4000 6000 8000
542+
/// ```
541543
///
542544
/// - The emission **starts high** and **gradually decreases**, ensuring early adopters receive
543545
/// more tokens while later participants still get rewards.

packages/rs-dpp/src/data_contract/document_type/class_methods/create_document_types_from_document_schemas/v0/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl DocumentType {
1818
token_configurations: &BTreeMap<TokenContractPosition, TokenConfiguration>,
1919
data_contact_config: &DataContractConfig,
2020
full_validation: bool,
21-
validation_operations: &mut Vec<ProtocolValidationOperation>,
21+
validation_operations: &mut impl Extend<ProtocolValidationOperation>,
2222
platform_version: &PlatformVersion,
2323
) -> Result<BTreeMap<String, DocumentType>, ProtocolError> {
2424
let mut contract_document_types: BTreeMap<String, DocumentType> = BTreeMap::new();

packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl DocumentType {
4646
token_configurations: &BTreeMap<TokenContractPosition, TokenConfiguration>,
4747
data_contact_config: &DataContractConfig,
4848
full_validation: bool,
49-
validation_operations: &mut Vec<ProtocolValidationOperation>,
49+
validation_operations: &mut impl Extend<ProtocolValidationOperation>,
5050
platform_version: &PlatformVersion,
5151
) -> Result<Self, ProtocolError> {
5252
match platform_version

packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v0/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl DocumentTypeV0 {
6868
schema_defs: Option<&BTreeMap<String, Value>>,
6969
data_contact_config: &DataContractConfig,
7070
full_validation: bool, // we don't need to validate if loaded from state
71-
validation_operations: &mut Vec<ProtocolValidationOperation>,
71+
validation_operations: &mut impl Extend<ProtocolValidationOperation>,
7272
platform_version: &PlatformVersion,
7373
) -> Result<Self, ProtocolError> {
7474
// Create a full root JSON Schema from shorten contract document type schema
@@ -82,9 +82,7 @@ impl DocumentTypeV0 {
8282
if full_validation {
8383
// TODO we are silently dropping this error when we shouldn't be
8484
// but returning this error causes tests to fail; investigate more.
85-
ProtocolError::CorruptedCodeExecution(
86-
"validation is not enabled but is being called on try_from_schema".to_string(),
87-
);
85+
"validation is not enabled but is being called on try_from_schema".to_string();
8886
}
8987

9088
#[cfg(feature = "validation")]
@@ -112,18 +110,18 @@ impl DocumentTypeV0 {
112110

113111
let schema_size = result.into_data()?.size;
114112

115-
validation_operations.push(
113+
validation_operations.extend(std::iter::once(
116114
ProtocolValidationOperation::DocumentTypeSchemaValidationForSize(schema_size),
117-
);
115+
));
118116

119117
return Err(ProtocolError::ConsensusError(Box::new(error)));
120118
}
121119

122120
let schema_size = result.into_data()?.size;
123121

124-
validation_operations.push(
122+
validation_operations.extend(std::iter::once(
125123
ProtocolValidationOperation::DocumentTypeSchemaValidationForSize(schema_size),
126-
);
124+
));
127125

128126
// Make sure JSON Schema is compilable
129127
let root_json_schema = root_schema.try_to_validating_json().map_err(|e| {
@@ -200,11 +198,11 @@ impl DocumentTypeV0 {
200198

201199
#[cfg(feature = "validation")]
202200
if full_validation {
203-
validation_operations.push(
201+
validation_operations.extend(std::iter::once(
204202
ProtocolValidationOperation::DocumentTypeSchemaPropertyValidation(
205203
property_values.values().len() as u64,
206204
),
207-
);
205+
));
208206

209207
// We should validate that the positions are continuous
210208
for (pos, value) in property_values.values().enumerate() {
@@ -302,12 +300,12 @@ impl DocumentTypeV0 {
302300

303301
#[cfg(feature = "validation")]
304302
if full_validation {
305-
validation_operations.push(
303+
validation_operations.extend(std::iter::once(
306304
ProtocolValidationOperation::DocumentTypeSchemaIndexValidation(
307305
index.properties.len() as u64,
308306
index.unique,
309307
),
310-
);
308+
));
311309

312310
// Unique indices produces significant load on the system during state validation
313311
// so we need to limit their number to prevent of spikes and DoS attacks

packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v1/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl DocumentTypeV1 {
8585
token_configurations: &BTreeMap<TokenContractPosition, TokenConfiguration>,
8686
data_contact_config: &DataContractConfig,
8787
full_validation: bool, // we don't need to validate if loaded from state
88-
validation_operations: &mut Vec<ProtocolValidationOperation>,
88+
validation_operations: &mut impl Extend<ProtocolValidationOperation>,
8989
platform_version: &PlatformVersion,
9090
) -> Result<Self, ProtocolError> {
9191
// Create a full root JSON Schema from shorten contract document type schema
@@ -99,9 +99,7 @@ impl DocumentTypeV1 {
9999
if full_validation {
100100
// TODO we are silently dropping this error when we shouldn't be
101101
// but returning this error causes tests to fail; investigate more.
102-
ProtocolError::CorruptedCodeExecution(
103-
"validation is not enabled but is being called on try_from_schema".to_string(),
104-
);
102+
"validation is not enabled but is being called on try_from_schema".to_string();
105103
}
106104

107105
#[cfg(feature = "validation")]
@@ -129,18 +127,18 @@ impl DocumentTypeV1 {
129127

130128
let schema_size = result.into_data()?.size;
131129

132-
validation_operations.push(
130+
validation_operations.extend(std::iter::once(
133131
ProtocolValidationOperation::DocumentTypeSchemaValidationForSize(schema_size),
134-
);
132+
));
135133

136134
return Err(ProtocolError::ConsensusError(Box::new(error)));
137135
}
138136

139137
let schema_size = result.into_data()?.size;
140138

141-
validation_operations.push(
139+
validation_operations.extend(std::iter::once(
142140
ProtocolValidationOperation::DocumentTypeSchemaValidationForSize(schema_size),
143-
);
141+
));
144142

145143
// Make sure JSON Schema is compilable
146144
let root_json_schema = root_schema.try_to_validating_json().map_err(|e| {
@@ -217,11 +215,11 @@ impl DocumentTypeV1 {
217215

218216
#[cfg(feature = "validation")]
219217
if full_validation {
220-
validation_operations.push(
218+
validation_operations.extend(std::iter::once(
221219
ProtocolValidationOperation::DocumentTypeSchemaPropertyValidation(
222220
property_values.values().len() as u64,
223221
),
224-
);
222+
));
225223

226224
// We should validate that the positions are continuous
227225
for (pos, value) in property_values.values().enumerate() {
@@ -319,12 +317,12 @@ impl DocumentTypeV1 {
319317

320318
#[cfg(feature = "validation")]
321319
if full_validation {
322-
validation_operations.push(
320+
validation_operations.extend(std::iter::once(
323321
ProtocolValidationOperation::DocumentTypeSchemaIndexValidation(
324322
index.properties.len() as u64,
325323
index.unique,
326324
),
327-
);
325+
));
328326

329327
// Unique indices produces significant load on the system during state validation
330328
// so we need to limit their number to prevent of spikes and DoS attacks

packages/rs-dpp/src/data_contract/document_type/methods/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ pub trait DocumentTypeV0Methods: DocumentTypeV0Getters + DocumentTypeV0MethodsVe
212212
/// - `id`: An identifier for the document. Unique within the context of the document's type.
213213
/// - `owner_id`: The identifier of the entity that will own this document.
214214
/// - `block_height`: The block height at which this document is considered to have been created.
215-
/// While this value is recorded in the document, it is ignored when the document is broadcasted
216-
/// to the network. This is because the actual block height at the time of broadcast may differ.
217-
/// This parameter is included to fulfill schema requirements that specify a block height; you may
218-
/// use the current block height, a placeholder value of 0, or any other value as necessary.
215+
/// While this value is recorded in the document, it is ignored when the document is broadcasted
216+
/// to the network. This is because the actual block height at the time of broadcast may differ.
217+
/// This parameter is included to fulfill schema requirements that specify a block height; you may
218+
/// use the current block height, a placeholder value of 0, or any other value as necessary.
219219
/// - `core_block_height`: Similar to `block_height`, this represents the core network's block height
220-
/// at the document's creation time. It is handled the same way as `block_height` regarding broadcast
221-
/// and schema requirements.
220+
/// at the document's creation time. It is handled the same way as `block_height` regarding broadcast
221+
/// and schema requirements.
222222
/// - `properties`: A collection of properties for the document, structured as a `BTreeMap<String, Value>`.
223-
/// These must be pre-validated to match the document's schema definitions.
223+
/// These must be pre-validated to match the document's schema definitions.
224224
/// - `platform_version`: A reference to the current version of the platform for which the document is created.
225225
///
226226
/// # Returns:

packages/rs-dpp/src/data_contract/document_type/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub enum DocumentTypeMutRef<'a> {
8888
V1(&'a mut DocumentTypeV1),
8989
}
9090

91+
#[allow(clippy::large_enum_variant)]
9192
#[derive(Debug, Clone, PartialEq, From)]
9293
pub enum DocumentType {
9394
V0(DocumentTypeV0),

packages/rs-dpp/src/data_contract/document_type/property/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl DocumentPropertyType {
306306
let min_size = self.min_size()?;
307307
let max_size = self.max_size()?;
308308
if platform_version.protocol_version > 8 {
309-
Some(((min_size as u32 + max_size as u32 + 1) / 2) as u16)
309+
Some(((min_size as u32 + max_size as u32).div_ceil(2)) as u16)
310310
} else {
311311
Some(min_size.wrapping_add(max_size).wrapping_add(1) / 2)
312312
}
@@ -342,7 +342,9 @@ impl DocumentPropertyType {
342342
return Ok(None);
343343
};
344344
if platform_version.protocol_version > 8 {
345-
Ok(Some(((min_size as u32 + max_size as u32 + 1) / 2) as u16))
345+
Ok(Some(
346+
((min_size as u32 + max_size as u32).div_ceil(2)) as u16,
347+
))
346348
} else {
347349
Ok(Some(min_size.wrapping_add(max_size).wrapping_add(1) / 2))
348350
}

packages/rs-dpp/src/data_contract/extra/drive_api_tests.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ mod test {
4040
&[("$ownerId", "asc"), ("$updatedAt", "asc")],
4141
),
4242
],
43-
..Default::default()
4443
},
4544
ExpectedDocumentsData {
4645
document_name: "contactInfo",
@@ -49,7 +48,6 @@ mod test {
4948
("index1", true, &[("$ownerId", "asc")]),
5049
("index2", false, &[("$ownerId", "asc"), ("lastName", "asc")]),
5150
],
52-
..Default::default()
5351
},
5452
ExpectedDocumentsData {
5553
document_name: "contactRequest",
@@ -150,25 +148,25 @@ mod test {
150148
assert!(!contract.config().readonly()); // the contract shouldn't be readonly
151149
assert!(!contract.config.documents_keep_history_contract_default());
152150
assert_eq!(contract.document_types.len(), 3);
153-
assert!(contract.document_types.get("profile").is_some());
151+
assert!(contract.document_types.contains_key("profile"));
154152
assert!(contract
155153
.document_types
156154
.get("profile")
157155
.unwrap()
158156
.documents_mutable());
159-
assert!(contract.document_types.get("contactInfo").is_some());
157+
assert!(contract.document_types.contains_key("contactInfo"));
160158
assert!(contract
161159
.document_types
162160
.get("contactInfo")
163161
.unwrap()
164162
.documents_mutable());
165-
assert!(contract.document_types.get("contactRequest").is_some());
163+
assert!(contract.document_types.contains_key("contactRequest"));
166164
assert!(!contract
167165
.document_types
168166
.get("contactRequest")
169167
.unwrap()
170168
.documents_mutable());
171-
assert!(contract.document_types.get("non_existent_key").is_none());
169+
assert!(!contract.document_types.contains_key("non_existent_key"));
172170

173171
let contact_info_indices = &contract
174172
.document_types

0 commit comments

Comments
 (0)