Skip to content

Commit

Permalink
Merge pull request #2 from ayanworks/POLYNDI-45-schema-manager
Browse files Browse the repository at this point in the history
feat: Implemented schema manager for W3C schema related operations
  • Loading branch information
sairanjit authored Jan 30, 2024
2 parents e99f92d + 6bdd395 commit 1e5f864
Show file tree
Hide file tree
Showing 18 changed files with 3,983 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
- name: Check types
run: pnpm check-types

- name: Test
run: pnpm test
# - name: Test
# run: pnpm test

continuous-deployment:
if: github.event_name == 'workflow_dispatch'
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
.DS_Store
build
build
.env
artifacts
cache
166 changes: 166 additions & 0 deletions .openzeppelin/polygon-mumbai.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"manifestVersion": "3.2",
"proxies": [
{
"address": "0xCdB4e190d6A5702294A7f825e04257E7ed5480a3",
"txHash": "0x75d31570997138059eb7ed38c367792308d6539e1c0045415ef3b555054d9781",
"kind": "transparent"
},
{
"address": "0xF5B03bAaACC7dCc5a693B91b8EfD684EF52b8B68",
"txHash": "0x95039b4bcca7c540f1a6be0218037078e0de50739ab6c59957095e31659eafb0",
"kind": "transparent"
},
{
"address": "0x568633430714858702D49c0C3E8482B70752236f",
"txHash": "0x23c42837cf6ff6393fb73a9c2e6d9d19f440baac196f96898ee70b6ce89b6e3b",
"kind": "transparent"
}
],
"impls": {
"ac1be2cf50e687736d809a3dbe19cb2fc2ead745f43705f7c57296f823630136": {
"address": "0x84347670881A56ED2B42fab1bC157286223260D0",
"txHash": "0x83fa6cf4a1a900bb316c5c94b7bb7deaea460ce4defa8c607c10f147e5d074ac",
"layout": {
"solcVersion": "0.8.16",
"storage": [
{
"label": "owner",
"offset": 0,
"slot": "0",
"type": "t_address",
"contract": "SchemaRegistry",
"src": "contracts/SchemaRegistry.sol:9"
},
{
"label": "schemas",
"offset": 0,
"slot": "1",
"type": "t_mapping(t_address,t_mapping(t_string_memory_ptr,t_struct(Schema)40_storage))",
"contract": "SchemaRegistry",
"src": "contracts/SchemaRegistry.sol:15"
},
{
"label": "initialized",
"offset": 0,
"slot": "2",
"type": "t_bool",
"contract": "SchemaRegistry",
"src": "contracts/SchemaRegistry.sol:19"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_mapping(t_address,t_mapping(t_string_memory_ptr,t_struct(Schema)40_storage))": {
"label": "mapping(address => mapping(string => struct SchemaRegistry.Schema))",
"numberOfBytes": "32"
},
"t_mapping(t_string_memory_ptr,t_struct(Schema)40_storage)": {
"label": "mapping(string => struct SchemaRegistry.Schema)",
"numberOfBytes": "32"
},
"t_string_memory_ptr": {
"label": "string",
"numberOfBytes": "32"
},
"t_string_storage": {
"label": "string",
"numberOfBytes": "32"
},
"t_struct(Schema)40_storage": {
"label": "struct SchemaRegistry.Schema",
"members": [
{
"label": "schemaJson",
"type": "t_string_storage",
"offset": 0,
"slot": "0"
}
],
"numberOfBytes": "32"
}
},
"namespaces": {}
}
},
"2b89bc9b5130220a32261fccba0ee7dd3aaafb98bb9d4018ecbdb1be7ff48623": {
"address": "0x6b045643F2c29b430427Fa0A6eaef7eE57bbC26e",
"txHash": "0x715b0ee8af2c6c761628d5b4ad7273bb6b68533a935f77566e15fed8f3134a47",
"layout": {
"solcVersion": "0.8.16",
"storage": [
{
"label": "owner",
"offset": 0,
"slot": "0",
"type": "t_address",
"contract": "SchemaRegistry",
"src": "contracts/SchemaRegistry.sol:9"
},
{
"label": "schemas",
"offset": 0,
"slot": "1",
"type": "t_mapping(t_address,t_mapping(t_string_memory_ptr,t_struct(Schema)7_storage))",
"contract": "SchemaRegistry",
"src": "contracts/SchemaRegistry.sol:15"
},
{
"label": "initialized",
"offset": 0,
"slot": "2",
"type": "t_bool",
"contract": "SchemaRegistry",
"src": "contracts/SchemaRegistry.sol:19"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_mapping(t_address,t_mapping(t_string_memory_ptr,t_struct(Schema)7_storage))": {
"label": "mapping(address => mapping(string => struct SchemaRegistry.Schema))",
"numberOfBytes": "32"
},
"t_mapping(t_string_memory_ptr,t_struct(Schema)7_storage)": {
"label": "mapping(string => struct SchemaRegistry.Schema)",
"numberOfBytes": "32"
},
"t_string_memory_ptr": {
"label": "string",
"numberOfBytes": "32"
},
"t_string_storage": {
"label": "string",
"numberOfBytes": "32"
},
"t_struct(Schema)7_storage": {
"label": "struct SchemaRegistry.Schema",
"members": [
{
"label": "schemaJson",
"type": "t_string_storage",
"offset": 0,
"slot": "0"
}
],
"numberOfBytes": "32"
}
},
"namespaces": {}
}
}
}
}
19 changes: 19 additions & 0 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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;
}
}
83 changes: 83 additions & 0 deletions contracts/SchemaRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.16;

/**
* @title SchemaRegistry
* @dev Smart Contract for Polygon Schema Methods
*/
contract SchemaRegistry {
address private owner;

struct Schema {
string schemaJson;
}

mapping(address => mapping(string => Schema)) private schemas;

event TransferOwnership(address indexed newOwner);
event SchemaCreate(address indexed id, string schemaId, string schemaJson);
bool private initialized;

/**
* @dev Initializes the ownership of the contract.
*/
function initialize() public {
require(!initialized, "Contract instance has already been initialized");
initialized = true;
owner = msg.sender;
}

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

/**
* @dev Transfers the ownership of the contract.
* @param _newOwner Address of the new owner.
* @return Message indicating the success or failure of ownership transfer.
*/
function transferOwnership(address _newOwner) public onlyOwner returns (string memory) {
if (owner != _newOwner) {
owner = _newOwner;
emit TransferOwnership(owner);
return "Ownership transferred successfully";
} else {
return "Ownership cannot be transferred to the same account";
}
}

/*
* @dev Reads the contract owner from the chain.
* @return The address of the contract owner.
*/
function getOwner() public view returns (address _owner) {
return owner;
}

/*
* @dev Creates a new schema.
* @param _id Address identifier.
* @param newSchemaId Identifier for the new schema.
* @param _json JSON representation of the schema.
* @return The created schema ID.
*/
function createSchema(address _id, string memory newSchemaId, string memory _json) public returns (string memory schemaId) {
Schema memory newSchema = Schema(_json);
schemas[_id][newSchemaId] = newSchema;

emit SchemaCreate(msg.sender, newSchemaId, _json);
return newSchemaId;
}

/**
* @dev Gets a schema by its ID.
* @param _id Address identifier.
* @param _schemaId Identifier of the schema.
* @return The schema object.
*/
function getSchemaById(address _id, string memory _schemaId) external view returns (Schema memory) {
Schema memory schema = schemas[_id][_schemaId];
return schema;
}
}
34 changes: 34 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @type import('hardhat/config').HardhatUserConfig
*/

// import 'hardhat';
require('@nomicfoundation/hardhat-ethers')
require('@openzeppelin/hardhat-upgrades')
require('@nomicfoundation/hardhat-verify')

require('dotenv/config')

module.exports = {
solidity: {
version: '0.8.16',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
networks: {
hardhat: {},
mumbai: {
url: process.env.RPCURL, // Update with Mumbai Matic RPC URL
accounts: [`0x${process.env.SIGNER}`],
},
},
etherscan: {
apiKey: {
polygonMumbai: process.env.VERIFICATION_KEY,
},
},
}
35 changes: 28 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polygon-schema-manager",
"version": "1.0.0",
"name": "@ayanworks/polygon-schema-manager",
"version": "0.0.2-alpha.1",
"description": "Polygon schema manager",
"main": "build/index.js",
"files": [
Expand All @@ -9,23 +9,44 @@
"scripts": {
"clean": "rm -rf build",
"clean:deps": "pnpm clean && rm -rf node_modules",
"build": "tsc",
"test": "node --require ts-node/register --test ./tests/*.test.ts",
"build": "pnpm clean && tsc",
"test": "node --require ts-node/register --test ./tests/schema-manager.test.ts",
"prettier": "prettier --ignore-path .prettierignore .",
"check-format": "pnpm prettier --list-different",
"check-types": "pnpm build --noEmit",
"format": "pnpm prettier --write",
"release": "release-it"
},
"keywords": [],
"author": "",
"author": "Sai Ranjit Tummalapalli",
"license": "Apache-2.0",
"dependencies": {},
"dependencies": {
"@ayanworks/polygon-did-registry-contract": "2.0.1-alpha.3",
"@nomicfoundation/hardhat-verify": "^2.0.3",
"axios": "^1.6.3",
"ethers": "^6.9.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@openzeppelin/hardhat-upgrades": "^3.0.1",
"@types/node": "^18.17.0",
"@types/uuid": "^9.0.7",
"dotenv": "^16.0.2",
"hardhat": "^2.19.4",
"mocha": "^7.0.0",
"prettier": "^3.0.2",
"release-it": "^16.1.5",
"solc": "^0.8.21",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/ayanworks/polygon-schema-manager.git"
},
"bugs": {
"url": "https://github.com/ayanworks/polygon-schema-manager/issues"
},
"homepage": "https://github.com/ayanworks/polygon-schema-manager#readme"
}
Loading

0 comments on commit 1e5f864

Please sign in to comment.