-
Notifications
You must be signed in to change notification settings - Fork 12
/
SpecDataHolder.sol
143 lines (124 loc) · 3.68 KB
/
SpecDataHolder.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
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
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.16;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "./interfaces/ISpecDataHolder.sol";
import { Raft } from "./Raft.sol";
contract SpecDataHolder is
UUPSUpgradeable,
OwnableUpgradeable,
ISpecDataHolder
{
mapping(string => uint256) private _specToRaft;
mapping(uint256 => uint256) private _badgeToRaft;
address private badgesAddress;
address private raftAddress;
modifier onlyAuthorized() {
require(
msg.sender == badgesAddress || msg.sender == owner(),
"onlyAuthorized: unauthorized"
);
_;
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(address _raftAddress, address _nextOwner)
public
initializer
{
__Ownable_init();
raftAddress = _raftAddress;
transferOwnership(_nextOwner);
__UUPSUpgradeable_init();
}
function getBadgesAddress() external view returns (address) {
return badgesAddress;
}
function setBadgesAddress(address _badgesAddress) external virtual onlyOwner {
badgesAddress = _badgesAddress;
}
function getRaftAddress() external view returns (address) {
return raftAddress;
}
function setRaftAddress(address _raftAddress) external virtual onlyOwner {
raftAddress = _raftAddress;
}
function getRaftByBadgeId(uint256 _badgeTokenId)
external
view
virtual
returns (uint256)
{
return _badgeToRaft[_badgeTokenId];
}
function setBadgeToRaft(uint256 _badgeTokenId, uint256 _raftTokenId)
external
virtual
onlyAuthorized
{
_badgeToRaft[_badgeTokenId] = _raftTokenId;
}
function setBadgesToRafts(
uint256[] calldata _badgeTokenId,
uint256[] calldata _raftTokenId
) external virtual onlyAuthorized {
require(
_badgeTokenId.length == _raftTokenId.length,
"setBadgesToRafts: arrays must be the same length"
);
for (uint256 i = 0; i < _badgeTokenId.length; i++) {
_badgeToRaft[_badgeTokenId[i]] = _raftTokenId[i];
}
}
function setSpecToRaft(string calldata _specUri, uint256 _raftTokenId)
external
virtual
onlyAuthorized
{
_specToRaft[_specUri] = _raftTokenId;
}
function setSpecsToRafts(
string[] calldata _specUri,
uint256[] calldata _raftTokenId
) external virtual onlyAuthorized {
require(
_specUri.length == _raftTokenId.length,
"setSpecsToRafts: arrays must be the same length"
);
for (uint256 i = 0; i < _specUri.length; i++) {
_specToRaft[_specUri[i]] = _raftTokenId[i];
}
}
function getRaftTokenId(string calldata _specUri)
external
view
returns (uint256)
{
return _specToRaft[_specUri];
}
function isSpecRegistered(string calldata _specUri)
external
view
returns (bool)
{
return _specToRaft[_specUri] != 0;
}
function isAuthorizedAdmin(uint256 _raftTokenId, address _admin)
external
view
returns (bool)
{
Raft raft = Raft(raftAddress);
address raftOwner = raft.ownerOf(_raftTokenId);
return raftOwner == _admin || raft.isAdminActive(_raftTokenId, _admin);
}
// The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
// Not implementing this function because it is used to check who is authorized
// to update the contract, we're using onlyOwnerfor this purpose.
function _authorizeUpgrade(address) internal override onlyOwner {}
}