Skip to content

Commit c6360de

Browse files
cleanup
1 parent bffd610 commit c6360de

File tree

5 files changed

+25
-32
lines changed
  • packages/rs-dpp/src
    • data_contract/document_type/class_methods
    • state_transition

5 files changed

+25
-32
lines changed

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 & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,14 @@ impl DocumentTypeV0 {
6161
// TODO: Split into multiple functions
6262
#[allow(unused_variables)]
6363
#[allow(clippy::too_many_arguments)]
64-
#[allow(clippy::ptr_arg)]
65-
#[allow(clippy::unnecessary_operation)]
6664
pub(super) fn try_from_schema(
6765
data_contract_id: Identifier,
6866
name: &str,
6967
schema: Value,
7068
schema_defs: Option<&BTreeMap<String, Value>>,
7169
data_contact_config: &DataContractConfig,
7270
full_validation: bool, // we don't need to validate if loaded from state
73-
validation_operations: &mut Vec<ProtocolValidationOperation>,
71+
validation_operations: &mut impl Extend<ProtocolValidationOperation>,
7472
platform_version: &PlatformVersion,
7573
) -> Result<Self, ProtocolError> {
7674
// Create a full root JSON Schema from shorten contract document type schema
@@ -84,9 +82,7 @@ impl DocumentTypeV0 {
8482
if full_validation {
8583
// TODO we are silently dropping this error when we shouldn't be
8684
// but returning this error causes tests to fail; investigate more.
87-
ProtocolError::CorruptedCodeExecution(
88-
"validation is not enabled but is being called on try_from_schema".to_string(),
89-
);
85+
"validation is not enabled but is being called on try_from_schema".to_string();
9086
}
9187

9288
#[cfg(feature = "validation")]
@@ -114,18 +110,18 @@ impl DocumentTypeV0 {
114110

115111
let schema_size = result.into_data()?.size;
116112

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

121117
return Err(ProtocolError::ConsensusError(Box::new(error)));
122118
}
123119

124120
let schema_size = result.into_data()?.size;
125121

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

130126
// Make sure JSON Schema is compilable
131127
let root_json_schema = root_schema.try_to_validating_json().map_err(|e| {
@@ -202,11 +198,11 @@ impl DocumentTypeV0 {
202198

203199
#[cfg(feature = "validation")]
204200
if full_validation {
205-
validation_operations.push(
201+
validation_operations.extend(std::iter::once(
206202
ProtocolValidationOperation::DocumentTypeSchemaPropertyValidation(
207203
property_values.values().len() as u64,
208204
),
209-
);
205+
));
210206

211207
// We should validate that the positions are continuous
212208
for (pos, value) in property_values.values().enumerate() {
@@ -304,12 +300,12 @@ impl DocumentTypeV0 {
304300

305301
#[cfg(feature = "validation")]
306302
if full_validation {
307-
validation_operations.push(
303+
validation_operations.extend(std::iter::once(
308304
ProtocolValidationOperation::DocumentTypeSchemaIndexValidation(
309305
index.properties.len() as u64,
310306
index.unique,
311307
),
312-
);
308+
));
313309

314310
// Unique indices produces significant load on the system during state validation
315311
// 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: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ impl DocumentTypeV1 {
7777
// TODO: Split into multiple functions
7878
#[allow(unused_variables)]
7979
#[allow(clippy::too_many_arguments)]
80-
#[allow(clippy::ptr_arg)]
81-
#[allow(clippy::unnecessary_operation)]
8280
pub(super) fn try_from_schema(
8381
data_contract_id: Identifier,
8482
name: &str,
@@ -87,7 +85,7 @@ impl DocumentTypeV1 {
8785
token_configurations: &BTreeMap<TokenContractPosition, TokenConfiguration>,
8886
data_contact_config: &DataContractConfig,
8987
full_validation: bool, // we don't need to validate if loaded from state
90-
validation_operations: &mut Vec<ProtocolValidationOperation>,
88+
validation_operations: &mut impl Extend<ProtocolValidationOperation>,
9189
platform_version: &PlatformVersion,
9290
) -> Result<Self, ProtocolError> {
9391
// Create a full root JSON Schema from shorten contract document type schema
@@ -101,9 +99,7 @@ impl DocumentTypeV1 {
10199
if full_validation {
102100
// TODO we are silently dropping this error when we shouldn't be
103101
// but returning this error causes tests to fail; investigate more.
104-
ProtocolError::CorruptedCodeExecution(
105-
"validation is not enabled but is being called on try_from_schema".to_string(),
106-
);
102+
"validation is not enabled but is being called on try_from_schema".to_string();
107103
}
108104

109105
#[cfg(feature = "validation")]
@@ -131,18 +127,18 @@ impl DocumentTypeV1 {
131127

132128
let schema_size = result.into_data()?.size;
133129

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

138134
return Err(ProtocolError::ConsensusError(Box::new(error)));
139135
}
140136

141137
let schema_size = result.into_data()?.size;
142138

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

147143
// Make sure JSON Schema is compilable
148144
let root_json_schema = root_schema.try_to_validating_json().map_err(|e| {
@@ -321,12 +317,12 @@ impl DocumentTypeV1 {
321317

322318
#[cfg(feature = "validation")]
323319
if full_validation {
324-
validation_operations.push(
320+
validation_operations.extend(std::iter::once(
325321
ProtocolValidationOperation::DocumentTypeSchemaIndexValidation(
326322
index.properties.len() as u64,
327323
index.unique,
328324
),
329-
);
325+
));
330326

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

packages/rs-dpp/src/state_transition/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,10 @@ pub struct StateTransitionSigningOptions {
293293
}
294294

295295
impl StateTransition {
296+
#[allow(unused_variables)]
296297
pub fn deserialize_from_bytes_in_version(
297298
bytes: &[u8],
298-
_platform_version: &PlatformVersion,
299+
platform_version: &PlatformVersion,
299300
) -> Result<Self, ProtocolError> {
300301
let state_transition = StateTransition::deserialize_from_bytes(bytes)?;
301302
#[cfg(all(feature = "state-transitions", feature = "validation"))]
@@ -304,16 +305,16 @@ impl StateTransition {
304305

305306
// Tests are done with very high protocol ranges, while we could put this behind a feature,
306307
// that would probably be overkill.
307-
if active_version_range.contains(&_platform_version.protocol_version)
308-
|| _platform_version.protocol_version > 268435456
308+
if active_version_range.contains(&platform_version.protocol_version)
309+
|| platform_version.protocol_version > 268435456
309310
{
310311
Ok(state_transition)
311312
} else {
312313
Err(ProtocolError::StateTransitionError(
313314
StateTransitionIsNotActiveError {
314315
state_transition_type: state_transition.name(),
315316
active_version_range,
316-
current_protocol_version: _platform_version.protocol_version,
317+
current_protocol_version: platform_version.protocol_version,
317318
},
318319
))
319320
}

0 commit comments

Comments
 (0)