From ccf93c3184a594b3a6c8fccb235d21f041d46b5f Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:07:53 +0200 Subject: [PATCH] chore: apply feedback --- packages/rs-drive-proof-verifier/Cargo.toml | 1 + packages/rs-drive-proof-verifier/src/proof.rs | 6 +++++- packages/rs-drive-proof-verifier/src/types.rs | 14 +++++++------- packages/rs-drive-proof-verifier/src/unproved.rs | 2 +- packages/rs-sdk/src/mock/requests.rs | 4 ++-- packages/rs-sdk/tests/fetch/data_contract.rs | 7 ++++++- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/rs-drive-proof-verifier/Cargo.toml b/packages/rs-drive-proof-verifier/Cargo.toml index 12bf33398f..1c68ebcc12 100644 --- a/packages/rs-drive-proof-verifier/Cargo.toml +++ b/packages/rs-drive-proof-verifier/Cargo.toml @@ -15,6 +15,7 @@ mocks = [ "dep:platform-serialization-derive", "dep:platform-serialization", "dpp/document-serde-conversion", + "indexmap/serde", ] [dependencies] diff --git a/packages/rs-drive-proof-verifier/src/proof.rs b/packages/rs-drive-proof-verifier/src/proof.rs index d63346fa08..6ad4b93f2b 100644 --- a/packages/rs-drive-proof-verifier/src/proof.rs +++ b/packages/rs-drive-proof-verifier/src/proof.rs @@ -904,7 +904,11 @@ impl FromProof for DataContractHistory verify_tenderdash_proof(proof, mtd, &root_hash, provider)?; - Ok((maybe_history, mtd.clone(), proof.clone())) + Ok(( + maybe_history.map(IndexMap::from_iter), + mtd.clone(), + proof.clone(), + )) } } diff --git a/packages/rs-drive-proof-verifier/src/types.rs b/packages/rs-drive-proof-verifier/src/types.rs index 743034d3f7..1aebc86445 100644 --- a/packages/rs-drive-proof-verifier/src/types.rs +++ b/packages/rs-drive-proof-verifier/src/types.rs @@ -75,12 +75,12 @@ pub type RetrievedObjects = IndexMap>; /// /// * `K`: The type of the keys in the map. /// * `I`: The type of the integer in the map. -pub type RetrievedIntegerValue = BTreeMap; +pub type RetrievedIntegerValue = IndexMap; /// History of a data contract. /// /// Contains a map of data contract revisions to data contracts. -pub type DataContractHistory = BTreeMap; +pub type DataContractHistory = IndexMap; /// Multiple data contracts. /// /// Mapping between data contract IDs and data contracts. @@ -114,14 +114,14 @@ impl Contenders { &self, document_type: &DocumentType, platform_version: &PlatformVersion, - ) -> Result, crate::Error> { + ) -> Result, crate::Error> { self.contenders .iter() .map(|(id, v)| { let contender = v.try_to_contender(document_type.as_ref(), platform_version)?; Ok((*id, contender)) }) - .collect::, dpp::ProtocolError>>() + .collect::, dpp::ProtocolError>>() .map_err(Into::into) } } @@ -450,7 +450,7 @@ impl FromIterator<(u64, Vec)> for VotePollsGroupedByTimestamp { // collect all vote polls for the same timestamp into a single vector let data = iter .into_iter() - .fold(BTreeMap::new(), |mut acc, (timestamp, vote_poll)| { + .fold(IndexMap::new(), |mut acc, (timestamp, vote_poll)| { let entry: &mut Vec = acc.entry(timestamp).or_default(); entry.extend(vote_poll); acc @@ -586,7 +586,7 @@ impl FromIterator<(ProTxHash, Option)> for ProposerBl let identifier = Identifier::from(pro_tx_hash.to_byte_array()); // Adjust this conversion logic as needed (identifier, block_count) }) - .collect::>(); + .collect::>(); ProposerBlockCounts(map) } @@ -604,7 +604,7 @@ impl FromIterator<(ProTxHash, Option)> for ProposerBlock let identifier = Identifier::from(pro_tx_hash.to_byte_array()); // Adjust this conversion logic as needed (identifier, block_count) }) - .collect::>(); + .collect::>(); ProposerBlockCounts(map) } diff --git a/packages/rs-drive-proof-verifier/src/unproved.rs b/packages/rs-drive-proof-verifier/src/unproved.rs index bc2f2e9e51..cc7c63c83e 100644 --- a/packages/rs-drive-proof-verifier/src/unproved.rs +++ b/packages/rs-drive-proof-verifier/src/unproved.rs @@ -218,7 +218,7 @@ impl FromUnproved for CurrentQuorumsInfo let mut quorum_hash = [0u8; 32]; quorum_hash.copy_from_slice(&vs.quorum_hash); - // Parse ValidatorV0 members into a BTreeMap + // Parse ValidatorV0 members let members = vs .members .into_iter() diff --git a/packages/rs-sdk/src/mock/requests.rs b/packages/rs-sdk/src/mock/requests.rs index c6e84f37dd..605e5e9621 100644 --- a/packages/rs-sdk/src/mock/requests.rs +++ b/packages/rs-sdk/src/mock/requests.rs @@ -121,7 +121,7 @@ impl MockResponse for IndexMap, Vec>, _) = - bincode::serde::decode_from_slice(buf, BINCODE_CONFIG).expect("decode BTreeMap"); + bincode::serde::decode_from_slice(buf, BINCODE_CONFIG).expect("decode IndexMap"); data.into_iter() .map(|(k, v)| (K::mock_deserialize(sdk, &k), V::mock_deserialize(sdk, &v))) @@ -134,7 +134,7 @@ impl MockResponse for IndexMap