From bb37c8fec6cc2ca6a637239c3f12d366fa7fae50 Mon Sep 17 00:00:00 2001 From: tipusinghaw Date: Wed, 8 May 2024 12:38:02 +0530 Subject: [PATCH 1/2] refactor: removed active dids and did count Signed-off-by: tipusinghaw --- contracts/PolygonDidRegistry.sol | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/contracts/PolygonDidRegistry.sol b/contracts/PolygonDidRegistry.sol index d174210..0fa898e 100644 --- a/contracts/PolygonDidRegistry.sol +++ b/contracts/PolygonDidRegistry.sol @@ -6,7 +6,6 @@ pragma solidity 0.8.16; *@dev Smart Contract for Polygon DID Method */ contract PolygonDidRegistry { - uint256 totalDIDs; address owner; struct PolyDID { address controller; @@ -16,8 +15,6 @@ contract PolygonDidRegistry { } 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); @@ -46,7 +43,6 @@ contract PolygonDidRegistry { modifier nonReentrant() { require(!initialized, 'Contract instance has already been initialized'); initialized = true; - totalDIDs = 0; _; } @@ -109,13 +105,11 @@ contract PolygonDidRegistry { ) { require(_id != address(0), 'Invalid address provided'); - polyDIDs[_id].controller = msg.sender; + require(polyDIDs[_id].controller != _id, 'DID already exist'); + polyDIDs[_id].controller = _id; polyDIDs[_id].created = block.timestamp; polyDIDs[_id].updated = block.timestamp; polyDIDs[_id].didDoc = _doc; - activeDIDs[totalDIDs] = msg.sender; - activeAddress[_id] = totalDIDs; - ++totalDIDs; emit DIDCreated(_id, _doc); return ( polyDIDs[_id].controller, @@ -141,26 +135,6 @@ contract PolygonDidRegistry { return (polyDIDs[_id].didDoc, result); } - /** - *@dev Reads total number of DIDs and total number of active DIDs from Chain - */ - - 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) { - return polyDIDs[activeDIDs[_index]].didDoc; - } - /** *@dev To Update the DID doc *@param _id - Address that refers to the DID doc From dacfffac31ae708aab27bde3f4ea63df0bbec456 Mon Sep 17 00:00:00 2001 From: tipusinghaw Date: Wed, 8 May 2024 13:37:46 +0530 Subject: [PATCH 2/2] refactor: removed and migration.sol and deployed Signed-off-by: tipusinghaw --- .openzeppelin/unknown-80002.json | 127 +++++++++++++++++++++++++++++++ contracts/Migrations.sol | 19 ----- 2 files changed, 127 insertions(+), 19 deletions(-) delete mode 100644 contracts/Migrations.sol diff --git a/.openzeppelin/unknown-80002.json b/.openzeppelin/unknown-80002.json index 054225f..78fd86f 100644 --- a/.openzeppelin/unknown-80002.json +++ b/.openzeppelin/unknown-80002.json @@ -10,6 +10,11 @@ "address": "0xC1c392DC1073a86821B4ae37f1F0faCDcFFf45bF", "txHash": "0x82f79c38e7d6c943e76deb166a87515c32441708443abf1b410944fcb848a448", "kind": "transparent" + }, + { + "address": "0x8e8E732a564735C18b84F6d51f1F58599EE48211", + "txHash": "0x8e1bd9439bff5a69fa632d9801702adf9da77df2cd1c4d9aedc29dc520f28430", + "kind": "transparent" } ], "impls": { @@ -320,6 +325,128 @@ }, "namespaces": {} } + }, + "75b86adb6471aac29a596c2ab95b6cc3ffb19eb6c1bc7aafd10402d4762a892a": { + "address": "0xddBC6C77E7AA2E220C845b365b3CF76455157aaF", + "txHash": "0x82c4ad2dac45630071255f9171e2fb01767ff4ddc85b7b59bab26029b7552532", + "layout": { + "solcVersion": "0.8.16", + "storage": [ + { + "label": "owner", + "offset": 0, + "slot": "0", + "type": "t_address", + "contract": "PolygonDidRegistry", + "src": "contracts/PolygonDidRegistry.sol:9" + }, + { + "label": "polyDIDs", + "offset": 0, + "slot": "1", + "type": "t_mapping(t_address,t_struct(PolyDID)13_storage)", + "contract": "PolygonDidRegistry", + "src": "contracts/PolygonDidRegistry.sol:17" + }, + { + "label": "resourceData", + "offset": 0, + "slot": "2", + "type": "t_mapping(t_address,t_mapping(t_string_memory_ptr,t_string_storage))", + "contract": "PolygonDidRegistry", + "src": "contracts/PolygonDidRegistry.sol:18" + }, + { + "label": "keysById", + "offset": 0, + "slot": "3", + "type": "t_mapping(t_address,t_array(t_string_storage)dyn_storage)", + "contract": "PolygonDidRegistry", + "src": "contracts/PolygonDidRegistry.sol:19" + }, + { + "label": "initialized", + "offset": 0, + "slot": "4", + "type": "t_bool", + "contract": "PolygonDidRegistry", + "src": "contracts/PolygonDidRegistry.sol:29" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_string_storage)dyn_storage": { + "label": "string[]", + "numberOfBytes": "32" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_mapping(t_address,t_array(t_string_storage)dyn_storage)": { + "label": "mapping(address => string[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_mapping(t_string_memory_ptr,t_string_storage))": { + "label": "mapping(address => mapping(string => string))", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_struct(PolyDID)13_storage)": { + "label": "mapping(address => struct PolygonDidRegistry.PolyDID)", + "numberOfBytes": "32" + }, + "t_mapping(t_string_memory_ptr,t_string_storage)": { + "label": "mapping(string => string)", + "numberOfBytes": "32" + }, + "t_string_memory_ptr": { + "label": "string", + "numberOfBytes": "32" + }, + "t_string_storage": { + "label": "string", + "numberOfBytes": "32" + }, + "t_struct(PolyDID)13_storage": { + "label": "struct PolygonDidRegistry.PolyDID", + "members": [ + { + "label": "controller", + "type": "t_address", + "offset": 0, + "slot": "0" + }, + { + "label": "created", + "type": "t_uint256", + "offset": 0, + "slot": "1" + }, + { + "label": "updated", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "didDoc", + "type": "t_string_storage", + "offset": 0, + "slot": "3" + } + ], + "numberOfBytes": "128" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + } + }, + "namespaces": {} + } } } } diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol deleted file mode 100644 index 9aac975..0000000 --- a/contracts/Migrations.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.4.22 <0.9.0; - -contract Migrations { - address public owner = msg.sender; - uint public last_completed_migration; - - modifier restricted() { - require( - msg.sender == owner, - "This function is restricted to the contract's owner" - ); - _; - } - - function setCompleted(uint completed) public restricted { - last_completed_migration = completed; - } -}