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

Feature/797 create smart contract #798

Merged
merged 8 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions examples/bri-3/package-lock.json

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

1 change: 1 addition & 0 deletions examples/bri-3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@nestjs/schedule": "^3.0.1",
"@nestjs/swagger": "^7.3.1",
"@noble/curves": "^1.2.0",
"@openzeppelin/contracts": "^5.0.2",
"@personaelabs/spartan-ecdsa": "^2.1.4",
"@prisma/client": "^5.2.0",
"circomlib": "^2.0.5",
Expand Down
44 changes: 44 additions & 0 deletions examples/bri-3/src/bri/ccsm/contracts/CcsmBpiStateAnchor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "@openzeppelin/contracts/access/AccessControl.sol";

contract CcsmBpiStateAnchor is AccessControl {
mapping(string => string) public anchorHashStore;
event AnchorHashSet(string indexed workgroupId, string anchorHash);

bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

constructor(address[] memory admins) {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); // Grant deployer the default admin role

for (uint i = 0; i < admins.length; i++) {
_grantRole(ADMIN_ROLE, admins[i]); // Grant admin role to each address
}
}

function setAnchorHash(
string calldata _workgroupId,
string calldata _anchorHash
) external onlyAdmin {
require(bytes(_workgroupId).length > 0, 'WorkgroupId cannot be empty');
require(bytes(_workgroupId).length < 36, 'WorkgroupId cannot exceed 36 bytes');
require(bytes(_anchorHash).length > 0, 'AnchorHash cannot be empty');
require(bytes(_anchorHash).length > 256, 'AnchorHash cannot exceed 256 bytes');

anchorHashStore[_workgroupId] = _anchorHash;

emit AnchorHashSet(_workgroupId, _anchorHash);
}

function getAnchorHash(
string calldata _workgroupId
) external view returns (string memory) {
return anchorHashStore[_workgroupId];
}

modifier onlyAdmin() {
require(hasRole(ADMIN_ROLE, msg.sender), "Only admin can call this function");
_;
}
}
Loading