Skip to content

Commit

Permalink
fix: removed delete method and veriable
Browse files Browse the repository at this point in the history
Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>
  • Loading branch information
tipusinghaw committed Jan 19, 2024
1 parent c638956 commit 1185ac0
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 462 deletions.
93 changes: 37 additions & 56 deletions contracts/PolygonDidRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pragma solidity ^0.8.16;
contract PolygonDidRegistry {
uint256 totalDIDs;
address owner;
uint256 deletedDID;
struct PolyDID {
address controller;
uint256 created;
Expand All @@ -19,41 +18,35 @@ contract PolygonDidRegistry {
modifier onlyController(address _id) {
require(
polyDIDs[_id].controller == msg.sender,
'message sender is not the controller of the DID Doc'
"message sender is not the controller of the DID Doc"
);
_;
}
mapping(address => PolyDID) polyDIDs;
mapping(uint256 => address) activeDIDs;
mapping(address => uint256) activeAddress;

mapping(address => mapping(string => string)) resourceData;
mapping(address => string[]) private keysById;
event DIDCreated(address id, string doc);
event DIDUpdated(address id, string doc);
event TransferOwnership(address newOwner);
event ResourceAdded(
address _id,
string _resourceId,
string _resourcePayload
);
event ResourceAdded(address _id, string _resourceId, string _resourcePayload);

bool private initialized;

/**
*@dev initializes the ownership of contract
**/

mapping(address => string[]) private keysById;
mapping(address => mapping(string => string)) resourceData;

function initialize() public {
require(!initialized, 'Contract instance has already been initialized');
require(!initialized, "Contract instance has already been initialized");
initialized = true;
owner = msg.sender;
totalDIDs = 0;
}

modifier onlyOwner() {
require(msg.sender == owner, 'message sender is not the owner');
require(msg.sender == owner, "message sender is not the owner");
_;
}

Expand All @@ -62,15 +55,17 @@ contract PolygonDidRegistry {
*@param _newOwner - Address of the new owner to whom the ownership needs to be passed
**/

function transferOwnership(
address _newOwner
) public onlyOwner returns (string memory) {
function transferOwnership(address _newOwner)
public
onlyOwner
returns (string memory)
{
if (owner != _newOwner) {
owner = _newOwner;
emit TransferOwnership(owner);
return ('Ownership transferred successfully');
return ("Ownership transferred successfully");
} else {
return ('Ownership cannot be transferred to the same account');
return ("Ownership cannot be transferred to the same account");
}
}

Expand All @@ -88,10 +83,7 @@ contract PolygonDidRegistry {
*@param _doc - A string object that holds the DID Doc
*/

function createDID(
address _id,
string memory _doc
)
function createDID(address _id, string memory _doc)
public
returns (
address controller,
Expand Down Expand Up @@ -121,9 +113,7 @@ contract PolygonDidRegistry {
*@param _id - Address that refers to the DID doc position
*/

function getDIDDoc(
address _id
) public view returns (string memory, string[] memory) {
function getDIDDoc(address _id) public view returns (string memory, string[] memory) {
string[] memory result = new string[](keysById[_id].length);

for (uint256 i = 0; i < keysById[_id].length; i++) {
Expand All @@ -136,19 +126,26 @@ contract PolygonDidRegistry {
*@dev Reads total number of DIDs and total number of active DIDs from Chain
*/

function getTotalNumberOfDIDs() public view returns (uint256 _totalDIDs) {
function getTotalNumberOfDIDs()
public
view
returns (uint256 _totalDIDs)
{
return (totalDIDs);
}


/**
*@dev Reads one DID at a time from Chain based on index
*@param _index - Uint256 type variable that refers to the DID position
*@return _did - returns the DID Doc assciated with the index. Returns null if the DID Doc is deleted.
*/

function getDIDDocByIndex(
uint256 _index
) public view returns (string memory) {
function getDIDDocByIndex(uint256 _index)
public
view
returns (string memory)
{
return polyDIDs[activeDIDs[_index]].didDoc;
}

Expand All @@ -158,10 +155,7 @@ contract PolygonDidRegistry {
*@param _doc - A String that holds the DID doc
*/

function updateDIDDoc(
address _id,
string memory _doc
)
function updateDIDDoc(address _id, string memory _doc)
public
onlyController(_id)
returns (
Expand All @@ -187,31 +181,20 @@ contract PolygonDidRegistry {
*@param _id - Address that refers to the DID doc
*@param _resourceId - Id that refers to the resource
*/
function addResource(
address _id,
string memory _resourceId,
string memory _resourcePayload
)
public
onlyController(_id)
returns (address, string memory, string memory)
{
resourceData[_id][_resourceId] = _resourcePayload;
keysById[_id].push(_resourceId);
emit ResourceAdded(_id, _resourceId, _resourcePayload);
return (_id, _resourceId, _resourcePayload);
}

/**
function addResource(address _id, string memory _resourceId, string memory _resourcePayload) public onlyController(_id) returns (address, string memory, string memory) {
resourceData[_id][_resourceId] = _resourcePayload;
keysById[_id].push(_resourceId);
emit ResourceAdded(_id, _resourceId, _resourcePayload);
return (_id, _resourceId, _resourcePayload);
}

/**
*@dev Reads DID linked resource from Chain
*@param _id - Address that refers to the DID doc
*@param _resourceId - Id that refers to a specific resource
*/

function getResource(
address _id,
string memory _resourceId
) public view returns (string memory) {
function getResource(address _id, string memory _resourceId) public view returns (string memory) {
return resourceData[_id][_resourceId];
}

Expand All @@ -220,9 +203,7 @@ contract PolygonDidRegistry {
*@param _id - Address that refers to the DID doc
*/

function getAllResources(
address _id
) public view returns (string[] memory) {
function getAllResources(address _id) public view returns (string[] memory) {
string[] memory result = new string[](keysById[_id].length);

for (uint256 i = 0; i < keysById[_id].length; i++) {
Expand Down
6 changes: 6 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// import 'hardhat';
require('@nomicfoundation/hardhat-ethers')
require('@openzeppelin/hardhat-upgrades')
require("@nomicfoundation/hardhat-verify");

require('dotenv/config')

Expand All @@ -25,4 +26,9 @@ module.exports = {
accounts: [`0x${process.env.SIGNER}`],
},
},
etherscan: {
apiKey: {
polygonMumbai:process.env.VERIFICATION_KEY
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"deploy": "node deploy.js",
"test": "node compile.js && mocha --timeout 30000",
"test": "node --require ts-node/register --test ./tests/polygon_did_registry_test.test.js",
"clean": "rm -rf build",
"clean:deps": "pnpm clean && rm -rf node_modules",
"build": "pnpm clean && pnpm build:sol && tsc",
Expand All @@ -22,6 +22,7 @@
"license": "MIT",
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-verify": "^2.0.3",
"@openzeppelin/hardhat-upgrades": "^3.0.1",
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.17.0",
Expand Down
80 changes: 78 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1185ac0

Please sign in to comment.