-
Notifications
You must be signed in to change notification settings - Fork 22
/
DocumentModule.sol
101 lines (86 loc) · 3.46 KB
/
DocumentModule.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
import "../../security/AuthorizationModule.sol";
import "../../../libraries/Errors.sol";
import "../../../interfaces/engine/draft-IERC1643.sol";
/**
* @title Document module
* @dev
*
* Retrieve documents from a documentEngine
*/
abstract contract DocumentModule is AuthorizationModule, IERC1643 {
/* ============ Events ============ */
/**
* @dev Emitted when a rule engine is set.
*/
event DocumentEngine(IERC1643 indexed newDocumentEngine);
/* ============ ERC-7201 ============ */
bytes32 public constant DOCUMENT_ROLE = keccak256("DOCUMENT_ROLE");
// keccak256(abi.encode(uint256(keccak256("CMTAT.storage.DocumentModule")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant DocumentModuleStorageLocation = 0x5edcb2767f407e647b6a4171ef53e8015a3eff0bb2b6e7765b1a26332bc43000;
/* ==== ERC-7201 State Variables === */
struct DocumentModuleStorage {
IERC1643 _documentEngine;
}
/* ============ Initializer Function ============ */
/**
* @dev
*
* - The grant to the admin role is done by AccessControlDefaultAdminRules
* - The control of the zero address is done by AccessControlDefaultAdminRules
*
*/
function __DocumentModule_init_unchained(IERC1643 documentEngine_)
internal onlyInitializing {
if (address(documentEngine_) != address (0)) {
DocumentModuleStorage storage $ = _getDocumentModuleStorage();
$._documentEngine = documentEngine_;
emit DocumentEngine(documentEngine_);
}
}
/*//////////////////////////////////////////////////////////////
PUBLIC/EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
function documentEngine() public view virtual returns (IERC1643) {
DocumentModuleStorage storage $ = _getDocumentModuleStorage();
return $._documentEngine;
}
/*
* @notice set an authorizationEngine if not already set
*
*/
function setDocumentEngine(
IERC1643 documentEngine_
) external onlyRole(DOCUMENT_ROLE) {
DocumentModuleStorage storage $ = _getDocumentModuleStorage();
if ($._documentEngine == documentEngine_){
revert Errors.CMTAT_DocumentModule_SameValue();
}
$._documentEngine = documentEngine_;
emit DocumentEngine(documentEngine_);
}
function getDocument(bytes32 _name) public view returns (string memory, bytes32, uint256){
DocumentModuleStorage storage $ = _getDocumentModuleStorage();
if(address($._documentEngine) != address(0)){
return $._documentEngine.getDocument( _name);
} else{
return ("",0x0, 0);
}
}
function getAllDocuments() public view returns (bytes32[] memory documents){
DocumentModuleStorage storage $ = _getDocumentModuleStorage();
if(address($._documentEngine) != address(0)){
documents = $._documentEngine.getAllDocuments();
}
}
/*//////////////////////////////////////////////////////////////
INTERNAL/PRIVATE FUNCTIONS
//////////////////////////////////////////////////////////////*/
/* ============ ERC-7201 ============ */
function _getDocumentModuleStorage() private pure returns (DocumentModuleStorage storage $) {
assembly {
$.slot := DocumentModuleStorageLocation
}
}
}