Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement access manager #8

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .yarn/install-state.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"./cache",
"./node_modules",
"./coverage",
"./coverage.json"
"./coverage.json",
"./ignition/deployments"
]
}
}
15 changes: 9 additions & 6 deletions contracts/ApplicationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
pragma solidity 0.8.26;

import {IApplicationManager} from "./IApplicationManager.sol";
import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";

contract ApplicationManager is IApplicationManager {
contract ApplicationManager is IApplicationManager, AccessManaged {
mapping(uint => Application) private applications;
mapping(address => bool) private addressUsed;
uint private nextApplicationId;

constructor() {}
constructor(address initialAuthority) AccessManaged(initialAuthority) {}

function applicationExists(uint id) internal view returns (bool) {
return applications[id].account != address(0);
Expand All @@ -18,40 +19,42 @@
return nextApplicationId;
}

function createApplication(Application memory newApplication) external {
function createApplication(
Application memory newApplication
) external restricted {
cyri113 marked this conversation as resolved.
Show resolved Hide resolved
require(
!addressUsed[newApplication.account],
"Address already used for another application"
);
applications[nextApplicationId] = newApplication;
addressUsed[newApplication.account] = true;
emit ApplicationCreated(
nextApplicationId,
applications[nextApplicationId]
);
nextApplicationId++;
}

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low


function updateApplication(
uint id,
Application memory updatedApplication
) external {
) external restricted {
require(applicationExists(id), "Application does not exist");
require(
!addressUsed[updatedApplication.account] ||
applications[id].account == updatedApplication.account,
"Address already used for another application"
"Account used by another application"
cyri113 marked this conversation as resolved.
Show resolved Hide resolved
);
applications[id] = updatedApplication;
emit ApplicationUpdated(id, applications[id]);
}

function deleteApplication(uint id) external {
function deleteApplication(uint id) external restricted {
cyri113 marked this conversation as resolved.
Show resolved Hide resolved
require(applicationExists(id), "Application does not exist");
addressUsed[applications[id].account] = false;
emit ApplicationDeleted(id, applications[id]);
delete applications[id];
}

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low


function getApplication(
uint id
Expand Down
11 changes: 11 additions & 0 deletions contracts/OIDAccessManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

// solhint-disable-next-line max-line-length
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";

contract OIDAccessManager is AccessManagerUpgradeable {
function initialize() public initializer {
__AccessManager_init(msg.sender);
}
}
18 changes: 0 additions & 18 deletions ignition/modules/Lock.ts

This file was deleted.

17 changes: 17 additions & 0 deletions ignition/modules/OIDAccessManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

const OIDAccessManagerModule = buildModule("OIDAccessManagerModule", (m) => {
// const deployer = m.getAccount(0);

const manager = m.contract("OIDAccessManager", [], {});
m.call(manager, "initialize", []);

// m.call(manager, "labelRole", [1n, "APP_MANAGER_ROLE"]);

// console.log(appManager);
// m.call(manager, "grantRole", [1n, appManager, 0]);

return { manager };
});

export default OIDAccessManagerModule;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomicfoundation/hardhat-viem": "^2.0.0",
"@nomiclabs/hardhat-solhint": "^3.1.0",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/contracts-upgradeable": "^5.0.2",
"@types/chai": "^4.2.0",
"@types/chai-as-promised": "^7.1.6",
"@types/mocha": ">=9.1.0",
Expand Down
Loading