Created
January 22, 2026 09:48
-
-
Save sedhu-orbitx/0b74cbc90879b14e14f0b3bd9be90411 to your computer and use it in GitHub Desktop.
transaction registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| // Compatible with OpenZeppelin Contracts ^5.5.0 | |
| pragma solidity ^0.8.27; | |
| import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; | |
| import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; | |
| import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; | |
| import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; | |
| contract TransactionRegistry is Initializable, PausableUpgradeable, AccessControlUpgradeable, UUPSUpgradeable { | |
| enum TransactionType { | |
| DEBIT, | |
| CREDIT | |
| } | |
| bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); | |
| bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE"); | |
| bytes32 public constant RECORDER_ROLE = keccak256("RECORDER_ROLE"); | |
| event TransactionRecorded( | |
| bytes32 indexed transactionId, | |
| uint256 amount, | |
| TransactionType transactionType, | |
| uint256 timestamp, | |
| address recorder | |
| ); | |
| /// @custom:oz-upgrades-unsafe-allow constructor | |
| constructor() { | |
| _disableInitializers(); | |
| } | |
| function initialize(address defaultAdmin, address pauser, address upgrader, address recorder) | |
| public | |
| initializer | |
| { | |
| __Pausable_init(); | |
| __AccessControl_init(); | |
| _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin); | |
| _grantRole(PAUSER_ROLE, pauser); | |
| _grantRole(UPGRADER_ROLE, upgrader); | |
| _grantRole(RECORDER_ROLE, recorder); | |
| } | |
| function pause() public onlyRole(PAUSER_ROLE) { | |
| _pause(); | |
| } | |
| function unpause() public onlyRole(PAUSER_ROLE) { | |
| _unpause(); | |
| } | |
| function recordTransaction( | |
| bytes32 transactionId, | |
| uint256 amount, | |
| TransactionType transactionType, | |
| uint256 timestamp | |
| ) external onlyRole(RECORDER_ROLE) whenNotPaused { | |
| require(transactionId != bytes32(0), "Invalid transaction ID"); | |
| require(amount > 0, "Invalid amount"); | |
| require(timestamp > 0, "Invalid timestamp"); | |
| emit TransactionRecorded(transactionId, amount, transactionType, timestamp, msg.sender); | |
| } | |
| function version() external pure returns (uint8) { | |
| return 1; | |
| } | |
| function _authorizeUpgrade(address newImplementation) | |
| internal | |
| override | |
| onlyRole(UPGRADER_ROLE) | |
| {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment