Skip to content

Commit

Permalink
feat: support batched document in issued check
Browse files Browse the repository at this point in the history
BREAKING CHANGE: New changes for Document Store v4

(cherry picked from commit 9305fa5051df86840ecfcdc11078270cbd755a08)
  • Loading branch information
superical committed Mar 4, 2024
1 parent a030049 commit 44d9eae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contracts/BaseDocumentStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract BaseDocumentStore is Initializable {
* @param document The hash of the document to check
* @return A boolean indicating whether the document has been issued
*/
function isIssued(bytes32 document) public view returns (bool) {
function _isIssued(bytes32 document) internal view returns (bool) {
return (documentIssued[document] != 0);
}

Expand Down
31 changes: 27 additions & 4 deletions contracts/DocumentStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

import "./BaseDocumentStore.sol";
import "./base/DocumentStoreAccessControl.sol";
Expand All @@ -13,6 +14,8 @@ import "./base/DocumentStoreAccessControl.sol";
* @notice A contract for storing and revoking documents with access control
*/
contract DocumentStore is BaseDocumentStore, DocumentStoreAccessControl {
using MerkleProof for bytes32[];

/**
* @notice Initialises the contract with a name and owner
* @param _name The name of the contract
Expand All @@ -36,16 +39,16 @@ contract DocumentStore is BaseDocumentStore, DocumentStoreAccessControl {
* @notice Issues a document
* @param document The hash of the document to issue
*/
function issue(bytes32 document) public onlyRole(ISSUER_ROLE) onlyNotIssued(document) {
BaseDocumentStore._issue(document);
function issue(bytes32 documentRoot) public onlyRole(ISSUER_ROLE) onlyNotIssued(document) {
BaseDocumentStore._issue(documentRoot);
}

/**
* @notice Issues multiple documents
* @param documents The hashes of the documents to issue
*/
function bulkIssue(bytes32[] memory documents) public onlyRole(ISSUER_ROLE) {
BaseDocumentStore._bulkIssue(documents);
function bulkIssue(bytes32[] memory documentRoots) public onlyRole(ISSUER_ROLE) {
BaseDocumentStore._bulkIssue(documentRoots);
}

/**
Expand All @@ -64,4 +67,24 @@ contract DocumentStore is BaseDocumentStore, DocumentStoreAccessControl {
function bulkRevoke(bytes32[] memory documents) public onlyRole(REVOKER_ROLE) {
return BaseDocumentStore._bulkRevoke(documents);
}

function isIssued(
bytes32 documentRoot,
bytes32 document,
bytes32[] memory proof
) public view returns (bool) {
require(document != 0x0 && documentRoot != 0x0, "Invalid document");
if (documentRoot == document && proof.length == 0) {
return _isIssued(document) && !isRevoked(document);
}
return
_isIssued(documentRoot) &&
!isRevoked(documentRoot) &&
!isRevoked(document) &&
proof.verify(documentRoot, document);
}

function isIssued(bytes32 documentRoot) public view returns (bool) {
return isIssued(documentRoot, documentRoot, new bytes32[](0));
}
}

0 comments on commit 44d9eae

Please sign in to comment.