Skip to content

Commit

Permalink
chore: apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Oct 4, 2024
1 parent edd06de commit ccf93c3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/rs-drive-proof-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mocks = [
"dep:platform-serialization-derive",
"dep:platform-serialization",
"dpp/document-serde-conversion",
"indexmap/serde",
]

[dependencies]
Expand Down
6 changes: 5 additions & 1 deletion packages/rs-drive-proof-verifier/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,11 @@ impl FromProof<platform::GetDataContractHistoryRequest> 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(),
))
}
}

Expand Down
14 changes: 7 additions & 7 deletions packages/rs-drive-proof-verifier/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ pub type RetrievedObjects<K, O> = IndexMap<K, Option<O>>;
///
/// * `K`: The type of the keys in the map.
/// * `I`: The type of the integer in the map.
pub type RetrievedIntegerValue<K, I> = BTreeMap<K, I>;
pub type RetrievedIntegerValue<K, I> = IndexMap<K, I>;

/// History of a data contract.
///
/// Contains a map of data contract revisions to data contracts.
pub type DataContractHistory = BTreeMap<u64, DataContract>;
pub type DataContractHistory = IndexMap<u64, DataContract>;
/// Multiple data contracts.
///
/// Mapping between data contract IDs and data contracts.
Expand Down Expand Up @@ -114,14 +114,14 @@ impl Contenders {
&self,
document_type: &DocumentType,
platform_version: &PlatformVersion,
) -> Result<BTreeMap<Identifier, Contender>, crate::Error> {
) -> Result<IndexMap<Identifier, Contender>, crate::Error> {
self.contenders
.iter()
.map(|(id, v)| {
let contender = v.try_to_contender(document_type.as_ref(), platform_version)?;
Ok((*id, contender))
})
.collect::<Result<BTreeMap<Identifier, Contender>, dpp::ProtocolError>>()
.collect::<Result<IndexMap<Identifier, Contender>, dpp::ProtocolError>>()
.map_err(Into::into)
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ impl FromIterator<(u64, Vec<VotePoll>)> 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<VotePoll> = acc.entry(timestamp).or_default();
entry.extend(vote_poll);
acc
Expand Down Expand Up @@ -586,7 +586,7 @@ impl FromIterator<(ProTxHash, Option<ProposerBlockCountByRange>)> for ProposerBl
let identifier = Identifier::from(pro_tx_hash.to_byte_array()); // Adjust this conversion logic as needed
(identifier, block_count)
})
.collect::<BTreeMap<Identifier, u64>>();
.collect::<IndexMap<Identifier, u64>>();

ProposerBlockCounts(map)
}
Expand All @@ -604,7 +604,7 @@ impl FromIterator<(ProTxHash, Option<ProposerBlockCountById>)> for ProposerBlock
let identifier = Identifier::from(pro_tx_hash.to_byte_array()); // Adjust this conversion logic as needed
(identifier, block_count)
})
.collect::<BTreeMap<Identifier, u64>>();
.collect::<IndexMap<Identifier, u64>>();

ProposerBlockCounts(map)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-proof-verifier/src/unproved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl FromUnproved<platform::GetCurrentQuorumsInfoRequest> 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()
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk/src/mock/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<K: Hash + Eq + MockResponse, V: MockResponse> MockResponse for IndexMap<K,
Self: Sized,
{
let (data, _): (IndexMap<Vec<u8>, Vec<u8>>, _) =
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)))
Expand All @@ -134,7 +134,7 @@ impl<K: Hash + Eq + MockResponse, V: MockResponse> MockResponse for IndexMap<K,
.map(|(k, v)| (k.mock_serialize(sdk), v.mock_serialize(sdk)))
.collect();

bincode::serde::encode_to_vec(data, BINCODE_CONFIG).expect("encode BTreeMap")
bincode::serde::encode_to_vec(data, BINCODE_CONFIG).expect("encode IndexMap")
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/rs-sdk/tests/fetch/data_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ async fn test_data_contract_history_read() {
let result = DataContractHistory::fetch(&sdk, LimitQuery::from((id, 10))).await;

assert!(matches!(result, Ok(Some(_))), "result: {:?}", result);
let (_, contract) = result.unwrap().unwrap().pop_first().unwrap();
let (_, contract) = result
.expect("request should succeed")
.expect("data contract should exist")
.into_iter()
.next()
.expect("data contract");
assert_eq!(contract.id(), id);
}

0 comments on commit ccf93c3

Please sign in to comment.