forked from JessicaChg/semanticSBT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FollowRegister.sol
65 lines (46 loc) · 2.49 KB
/
FollowRegister.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
import "@openzeppelin/contracts/utils/Strings.sol";
import "../core/SemanticSBTUpgradeable.sol";
import "../interfaces/social/IFollowRegister.sol";
import "../interfaces/social/IFollow.sol";
import {FollowRegisterLogic} from "../libraries/FollowRegisterLogic.sol";
contract FollowRegister is IFollowRegister, SemanticSBTUpgradeable {
using Strings for uint256;
using Strings for address;
uint256 constant FOLLOW_CONTRACT_PREDICATE_INDEX = 1;
uint256 constant SOUL_CLASS_INDEX = 1;
uint256 constant CONTRACT_CLASS_INDEX = 2;
mapping(address => address) _ownedFollowContract;
address public followImpl;
address public verifyContract;
function setFollowImpl(address _followImpl) external onlyMinter {
followImpl = _followImpl;
}
function setFollowVerifyContract(address _verifyContract) external onlyMinter {
verifyContract = _verifyContract;
}
function ownedFollowContract(address owner) external view returns (address){
return _ownedFollowContract[owner];
}
function deployFollowContract(address to) external returns (uint256){
require(_ownedFollowContract[to] == address(0), "FollowRegister:Already deployed!");
require(msg.sender == to || _minters[msg.sender], "FollowRegister:Permission Denied");
uint256 tokenId = _addEmptyToken(to, 0);
address followContractAddress = FollowRegisterLogic.createFollow(followImpl, verifyContract, to, address(this));
_ownedFollowContract[to] = followContractAddress;
uint256 contractIndex = SemanticSBTLogicUpgradeable.addSubject(followContractAddress.toHexString(), _classNames[CONTRACT_CLASS_INDEX], _subjects, _subjectIndex, _classIndex);
SubjectPO[] memory subjectPOList = generateSubjectPOList(contractIndex);
_mint(tokenId, to, new IntPO[](0), new StringPO[](0), new AddressPO[](0), subjectPOList, new BlankNodePO[](0));
return tokenId;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(SemanticSBTUpgradeable) returns (bool) {
return interfaceId == type(IFollowRegister).interfaceId ||
super.supportsInterface(interfaceId);
}
function generateSubjectPOList(uint256 contractIndex) internal pure returns (SubjectPO[] memory) {
SubjectPO[] memory subjectPOList = new SubjectPO[](1);
subjectPOList[0] = SubjectPO(FOLLOW_CONTRACT_PREDICATE_INDEX, contractIndex);
return subjectPOList;
}
}