Skip to content

Commit

Permalink
Merge pull request #296 from OriginTrail/improvement/curated-paranet-…
Browse files Browse the repository at this point in the history
…nodes

Added node id to the list of nodes in curated paranet
  • Loading branch information
u-hubar authored Sep 26, 2024
2 parents 48cf151 + c524b19 commit f28dfca
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 42 deletions.
21 changes: 19 additions & 2 deletions abi/ParanetsRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"internalType": "uint72",
"name": "identityId",
"type": "uint72"
},
{
"internalType": "bytes",
"name": "nodeId",
"type": "bytes"
}
],
"name": "addCuratedNode",
Expand Down Expand Up @@ -220,9 +225,21 @@
"name": "getCuratedNodes",
"outputs": [
{
"internalType": "uint72[]",
"components": [
{
"internalType": "uint72",
"name": "identityId",
"type": "uint72"
},
{
"internalType": "bytes",
"name": "nodeId",
"type": "bytes"
}
],
"internalType": "struct ParanetStructs.Node[]",
"name": "",
"type": "uint72[]"
"type": "tuple[]"
}
],
"stateMutability": "view",
Expand Down
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
File renamed without changes.
Loading

0 comments on commit f28dfca

Please sign in to comment.