-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: abstract common contracts and clean up (#78)
* chore: abstract common contracts * chore: cleanup initialisers and constructors (#79) * fix: vulnerability in abstraction * fix: base relay recipient versioning
- Loading branch information
Showing
16 changed files
with
154 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pragma solidity ^0.6.10; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"; | ||
|
||
contract BaseDocumentStore is Initializable { | ||
string public name; | ||
string public version; | ||
|
||
/// A mapping of the document hash to the block number that was issued | ||
mapping(bytes32 => uint256) public documentIssued; | ||
/// A mapping of the hash of the claim being revoked to the revocation block number | ||
mapping(bytes32 => uint256) public documentRevoked; | ||
|
||
event DocumentIssued(bytes32 indexed document); | ||
event DocumentRevoked(bytes32 indexed document); | ||
|
||
function initialize(string memory _name) public initializer { | ||
version = "2.3.0"; | ||
name = _name; | ||
} | ||
|
||
function _issue(bytes32 document) internal onlyNotIssued(document) { | ||
documentIssued[document] = block.number; | ||
emit DocumentIssued(document); | ||
} | ||
|
||
function _bulkIssue(bytes32[] memory documents) internal { | ||
for (uint256 i = 0; i < documents.length; i++) { | ||
_issue(documents[i]); | ||
} | ||
} | ||
|
||
function getIssuedBlock(bytes32 document) public view onlyIssued(document) returns (uint256) { | ||
return documentIssued[document]; | ||
} | ||
|
||
function isIssued(bytes32 document) public view returns (bool) { | ||
return (documentIssued[document] != 0); | ||
} | ||
|
||
function isIssuedBefore(bytes32 document, uint256 blockNumber) public view returns (bool) { | ||
return documentIssued[document] != 0 && documentIssued[document] <= blockNumber; | ||
} | ||
|
||
function _revoke(bytes32 document) internal onlyNotRevoked(document) returns (bool) { | ||
documentRevoked[document] = block.number; | ||
emit DocumentRevoked(document); | ||
} | ||
|
||
function _bulkRevoke(bytes32[] memory documents) internal { | ||
for (uint256 i = 0; i < documents.length; i++) { | ||
_revoke(documents[i]); | ||
} | ||
} | ||
|
||
function isRevoked(bytes32 document) public view returns (bool) { | ||
return documentRevoked[document] != 0; | ||
} | ||
|
||
function isRevokedBefore(bytes32 document, uint256 blockNumber) public view returns (bool) { | ||
return documentRevoked[document] <= blockNumber && documentRevoked[document] != 0; | ||
} | ||
|
||
modifier onlyIssued(bytes32 document) { | ||
require(isIssued(document), "Error: Only issued document hashes can be revoked"); | ||
_; | ||
} | ||
|
||
modifier onlyNotIssued(bytes32 document) { | ||
require(!isIssued(document), "Error: Only hashes that have not been issued can be issued"); | ||
_; | ||
} | ||
|
||
modifier onlyNotRevoked(bytes32 claim) { | ||
require(!isRevoked(claim), "Error: Hash has been revoked previously"); | ||
_; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.