-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathExtraInformationModule.sol
More file actions
161 lines (141 loc) · 5.78 KB
/
ExtraInformationModule.sol
File metadata and controls
161 lines (141 loc) · 5.78 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
/* ==== Openzeppelin === */
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
/* ==== Tokenization === */
import {IERC1643CMTAT, IERC1643} from "../../../interfaces/tokenization/draft-IERC1643CMTAT.sol";
import {ICMTATBase} from "../../../interfaces/tokenization/ICMTAT.sol";
/**
* @title ExtraInformation module.
* @dev
*
* Add supplementary information on-chain (terms, tokenId, generic information)
*/
abstract contract ExtraInformationModule is Initializable, ICMTATBase {
bytes32 public constant EXTRA_INFORMATION_ROLE = keccak256("EXTRA_INFORMATION_ROLE");
/* ============ ERC-7201 ============ */
// keccak256(abi.encode(uint256(keccak256("CMTAT.storage.ExtraInformationModule")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ExtraInformationModuleStorageLocation = 0xd2d5d34c4a4dea00599692d3257c0aebc5e0359176118cd2364ab9b008c2d100;
/* ==== ERC-7201 State Variables === */
struct ExtraInformationModuleStorage {
string _tokenId;
CMTATTerms _terms;
string _information;
}
/* ============ Modifier ============ */
modifier onlyExtraInfoManager() {
_authorizeExtraInfoManagement();
_;
}
/* ============ Initializer Function ============ */
/**
* @dev Sets the values for {tokenId}, {terms_} and {information}.
*
*/
function __ExtraInformationModule_init_unchained(
string memory tokenId_,
IERC1643CMTAT.DocumentInfo memory terms_,
string memory information_
) internal virtual onlyInitializing {
ExtraInformationModuleStorage storage $ = _getExtraInformationModuleStorage();
// tokenId
_setTokenId($, tokenId_);
// Terms
_setTerms($, terms_);
// Information
_setInformation($, information_);
}
/*//////////////////////////////////////////////////////////////
PUBLIC/EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/* ============ Restricted Functions ============ */
/**
* @dev the tokenId will be changed even if the new value is the same as the current one
* @custom:access-control
* - the caller must have the `EXTRA_INFORMATION_ROLE`.
*/
function setTokenId(
string calldata tokenId_
) public virtual override(ICMTATBase) onlyExtraInfoManager {
ExtraInformationModuleStorage storage $ = _getExtraInformationModuleStorage();
_setTokenId($, tokenId_);
}
/**
* @inheritdoc ICMTATBase
* @dev The terms will be changed even if the new value is the same as the current one
* @custom:access-control
* - the caller must have the `EXTRA_INFORMATION_ROLE`.
*/
function setTerms(IERC1643CMTAT.DocumentInfo calldata terms_) public virtual override(ICMTATBase) onlyExtraInfoManager{
_setTerms(terms_);
}
/**
* @inheritdoc ICMTATBase
* @dev The information will be changed even if the new value is the same as the current one
* @custom:access-control
* - the caller must have the `EXTRA_INFORMATION_ROLE`.
*/
function setInformation(
string calldata information_
) public virtual onlyExtraInfoManager {
ExtraInformationModuleStorage storage $ = _getExtraInformationModuleStorage();
_setInformation($, information_);
}
/* ============ View functions ============ */
/**
* @inheritdoc ICMTATBase
*/
function tokenId() public view virtual override(ICMTATBase) returns (string memory tokenId_) {
ExtraInformationModuleStorage storage $ = _getExtraInformationModuleStorage();
return $._tokenId;
}
/**
* @inheritdoc ICMTATBase
*/
function terms() public view virtual override(ICMTATBase) returns (CMTATTerms memory terms_) {
ExtraInformationModuleStorage storage $ = _getExtraInformationModuleStorage();
return $._terms;
}
/**
* @inheritdoc ICMTATBase
*/
function information() public view virtual override(ICMTATBase) returns (string memory information_) {
ExtraInformationModuleStorage storage $ = _getExtraInformationModuleStorage();
return $._information;
}
/*//////////////////////////////////////////////////////////////
INTERNAL/PRIVATE FUNCTIONS
//////////////////////////////////////////////////////////////*/
function _setTerms(IERC1643CMTAT.DocumentInfo memory terms_) internal{
ExtraInformationModuleStorage storage $ = _getExtraInformationModuleStorage();
_setTerms($, terms_);
}
function _setTokenId(
ExtraInformationModuleStorage storage $, string memory tokenId_
) internal virtual {
$._tokenId = tokenId_;
emit TokenId(tokenId_, tokenId_);
}
function _setTerms(ExtraInformationModuleStorage storage $, IERC1643CMTAT.DocumentInfo memory terms_) internal virtual {
// Terms/Document name
$._terms.name = terms_.name;
// Document
$._terms.doc.documentHash = terms_.documentHash;
$._terms.doc.uri = terms_.uri;
$._terms.doc.lastModified = block.timestamp;
// Event
emit Terms($._terms);
}
function _setInformation(ExtraInformationModuleStorage storage $, string memory information_) internal virtual {
$._information = information_;
emit Information(information_);
}
/* ============ Access Control ============ */
function _authorizeExtraInfoManagement() internal virtual;
/* ============ ERC-7201 ============ */
function _getExtraInformationModuleStorage() private pure returns (ExtraInformationModuleStorage storage $) {
assembly {
$.slot := ExtraInformationModuleStorageLocation
}
}
}