Skip to content

Commit

Permalink
fix: πŸ› add func getDatasetProofRootHash
Browse files Browse the repository at this point in the history
(update datasetProof contract) add function getDatasetProofRootHash

βœ… Closes: #354
  • Loading branch information
siriusyim authored and lovel8 committed Mar 25, 2024
1 parent 8b54075 commit 012b05a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/v0.8/interfaces/module/IDatasetsProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ interface IDatasetsProof {
uint64 _datasetId
) external view returns (uint64);

/// @notice Retrieves the Merkle root hash of the dataset for the specified dataset ID and data type.
/// @param _datasetId The ID of the dataset for which to retrieve the Merkle root hash.
/// @param _dataType The type of data for which to retrieve the Merkle root hash.
/// @return rootHash The Merkle root hash of the dataset.
function getDatasetProofRootHash(
uint64 _datasetId,
DatasetType.DataType _dataType
) external view returns (bytes32 rootHash);

///@notice Check if a dataset has a car id
function isDatasetContainsCar(
uint64 _datasetId,
Expand Down
14 changes: 14 additions & 0 deletions src/v0.8/module/dataset/DatasetsProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,20 @@ contract DatasetsProof is
return datasetProof.completedHeight;
}

/// @notice Retrieves the Merkle root hash of the dataset for the specified dataset ID and data type.
/// @param _datasetId The ID of the dataset for which to retrieve the Merkle root hash.
/// @param _dataType The type of data for which to retrieve the Merkle root hash.
/// @return rootHash The Merkle root hash of the dataset.
function getDatasetProofRootHash(
uint64 _datasetId,
DatasetType.DataType _dataType
) external view onlyNotZero(_datasetId) returns (bytes32 rootHash) {
DatasetType.DatasetProof storage datasetProof = datasetProofs[
_datasetId
];
rootHash = datasetProof.getDatasetRootHash(_dataType);
}

///@notice Check if a dataset proof all completed
function isDatasetProofallCompleted(
uint64 _datasetId,
Expand Down
17 changes: 17 additions & 0 deletions src/v0.8/module/dataset/library/proof/DatasetProofLIB.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ library DatasetProofLIB {
return self.proofSubmitter;
}

/// @notice Retrieves the root hash of the dataset proof for the specified data type.
/// @param self The storage reference to the dataset proof.
/// @param _dataType The type of data for which to retrieve the root hash.
/// @return The root hash of the dataset proof.
function getDatasetRootHash(
DatasetType.DatasetProof storage self,
DatasetType.DataType _dataType
) internal view returns (bytes32) {
DatasetType.Proof storage proof;
if (_dataType == DatasetType.DataType.Source) {
proof = self.sourceProof;
} else {
proof = self.mappingFilesProof;
}
return proof.rootHash;
}

/// @notice Check if a dataset has submitter
/// @param self The dataset from which to retrieve the source dataset proof.
/// @param submitter The address being compared.
Expand Down

0 comments on commit 012b05a

Please sign in to comment.