Skip to content

Commit

Permalink
Added node id to the list of nodes in curated paranet
Browse files Browse the repository at this point in the history
  • Loading branch information
u-hubar committed Sep 26, 2024
1 parent 48cf151 commit de5edfd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions contracts/v2/paranets/Paranet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
revert ParanetErrors.ParanetCuratedNodeHasAlreadyBeenAdded(paranetId, identityIds[i]);
}

pr.addCuratedNode(paranetId, identityIds[i]);
pr.addCuratedNode(paranetId, identityIds[i], ps.getNodeId(identityIds[i]));

emit ParanetCuratedNodeAdded(paranetKAStorageContract, paranetKATokenId, identityIds[i]);

Expand Down Expand Up @@ -410,7 +410,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
paranetNodeJoinRequests.length - 1,
ParanetStructs.RequestStatus.APPROVED
);
pr.addCuratedNode(paranetId, identityId);
pr.addCuratedNode(paranetId, identityId, profileStorage.getNodeId(identityId));

emit ParanetCuratedNodeJoinRequestAccepted(paranetKAStorageContract, paranetKATokenId, identityId);
emit ParanetCuratedNodeAdded(paranetKAStorageContract, paranetKATokenId, identityId);
Expand Down
11 changes: 6 additions & 5 deletions contracts/v2/storage/paranets/ParanetsRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,23 @@ contract ParanetsRegistry is Named, Versioned, HubDependentV2 {
return paranets[paranetId].paranetNodeJoinRequests[identityId].length;
}

function addCuratedNode(bytes32 paranetId, uint72 identityId) external onlyContracts {
function addCuratedNode(bytes32 paranetId, uint72 identityId, bytes calldata nodeId) external onlyContracts {
paranets[paranetId].curatedNodesIndexes[identityId] = paranets[paranetId].curatedNodes.length;
paranets[paranetId].curatedNodes.push(identityId);
paranets[paranetId].curatedNodes.push(ParanetStructs.Node({identityId: identityId, nodeId: nodeId}));
}

function removeCuratedNode(bytes32 paranetId, uint72 identityId) external onlyContracts {
paranets[paranetId].curatedNodes[paranets[paranetId].curatedNodesIndexes[identityId]] = paranets[paranetId]
.curatedNodes[paranets[paranetId].curatedNodes.length - 1];
paranets[paranetId].curatedNodesIndexes[
paranets[paranetId].curatedNodes[paranets[paranetId].curatedNodes.length - 1]
paranets[paranetId].curatedNodes[paranets[paranetId].curatedNodes.length - 1].identityId
] = paranets[paranetId].curatedNodesIndexes[identityId];

delete paranets[paranetId].curatedNodesIndexes[identityId];
paranets[paranetId].curatedNodes.pop();
}

function getCuratedNodes(bytes32 paranetId) external view returns (uint72[] memory) {
function getCuratedNodes(bytes32 paranetId) external view returns (ParanetStructs.Node[] memory) {
return paranets[paranetId].curatedNodes;
}

Expand All @@ -219,7 +219,8 @@ contract ParanetsRegistry is Named, Versioned, HubDependentV2 {

function isCuratedNode(bytes32 paranetId, uint72 identityId) external view returns (bool) {
return (paranets[paranetId].curatedNodes.length != 0 &&
paranets[paranetId].curatedNodes[paranets[paranetId].curatedNodesIndexes[identityId]] == identityId);
paranets[paranetId].curatedNodes[paranets[paranetId].curatedNodesIndexes[identityId]].identityId ==
identityId);
}

function getIncentivesPoolAddress(
Expand Down
7 changes: 6 additions & 1 deletion contracts/v2/structs/paranets/ParanetStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ library ParanetStructs {
OPEN
}

struct Node {
uint72 identityId;
bytes nodeId;
}

enum RequestStatus {
NONE,
PENDING,
Expand Down Expand Up @@ -55,7 +60,7 @@ library ParanetStructs {
KnowledgeAssetsAccessPolicy knowledgeAssetsAccessPolicy;
uint96 cumulativeKnowledgeValue;
UnorderedNamedContractDynamicSetStructs.Set incentivesPools;
uint72[] curatedNodes;
Node[] curatedNodes;
// Identity ID => Index in the array
mapping(uint72 => uint256) curatedNodesIndexes;
// Identity ID => Requests Array
Expand Down

0 comments on commit de5edfd

Please sign in to comment.