From 012b05ad4797a93ab7d82f5db972ff3aaf962c03 Mon Sep 17 00:00:00 2001 From: sirius Date: Mon, 25 Mar 2024 14:16:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20func=20getDatasetPr?= =?UTF-8?q?oofRootHash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (update datasetProof contract) add function getDatasetProofRootHash ✅ Closes: #354 --- src/v0.8/interfaces/module/IDatasetsProof.sol | 9 +++++++++ src/v0.8/module/dataset/DatasetsProof.sol | 14 ++++++++++++++ .../dataset/library/proof/DatasetProofLIB.sol | 17 +++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/v0.8/interfaces/module/IDatasetsProof.sol b/src/v0.8/interfaces/module/IDatasetsProof.sol index ee6b37fe..3d1b1ff5 100644 --- a/src/v0.8/interfaces/module/IDatasetsProof.sol +++ b/src/v0.8/interfaces/module/IDatasetsProof.sol @@ -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, diff --git a/src/v0.8/module/dataset/DatasetsProof.sol b/src/v0.8/module/dataset/DatasetsProof.sol index d5de7c4b..cd787217 100644 --- a/src/v0.8/module/dataset/DatasetsProof.sol +++ b/src/v0.8/module/dataset/DatasetsProof.sol @@ -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, diff --git a/src/v0.8/module/dataset/library/proof/DatasetProofLIB.sol b/src/v0.8/module/dataset/library/proof/DatasetProofLIB.sol index acf97d83..7efa97a7 100644 --- a/src/v0.8/module/dataset/library/proof/DatasetProofLIB.sol +++ b/src/v0.8/module/dataset/library/proof/DatasetProofLIB.sol @@ -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.