From 9c06a823f0227142773d69d592068c30302e4f25 Mon Sep 17 00:00:00 2001 From: Alain Nicolas Date: Wed, 20 Sep 2023 15:57:04 +0200 Subject: [PATCH] chore: Cleanup and improvements (underscore on private/internal fields) --- src/AttestationRegistry.sol | 50 ++++++++++++++++++------------------- src/PortalRegistry.sol | 28 ++++++++++----------- src/Router.sol | 32 ++++++++++++------------ src/SchemaRegistry.sol | 10 ++++---- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/AttestationRegistry.sol b/src/AttestationRegistry.sol index 085dae48..11efad94 100644 --- a/src/AttestationRegistry.sol +++ b/src/AttestationRegistry.sol @@ -15,10 +15,10 @@ import { IRouter } from "./interface/IRouter.sol"; contract AttestationRegistry is OwnableUpgradeable { IRouter public router; - uint16 private version; - uint32 private attestationIdCounter; + uint16 private _version; + uint32 private _attestationIdCounter; - mapping(bytes32 attestationId => Attestation attestation) private attestations; + mapping(bytes32 attestationId => Attestation attestation) private _attestations; /// @notice Error thrown when a non-portal tries to call a method that can only be called by a portal error OnlyPortal(); @@ -95,10 +95,10 @@ contract AttestationRegistry is OwnableUpgradeable { // Verify the attestationData field is not blank if (attestationPayload.attestationData.length == 0) revert AttestationDataFieldEmpty(); // Auto increment attestation counter - attestationIdCounter++; - bytes32 id = bytes32(abi.encode(attestationIdCounter)); + _attestationIdCounter++; + bytes32 id = bytes32(abi.encode(_attestationIdCounter)); // Create attestation - attestations[id] = Attestation( + _attestations[id] = Attestation( id, attestationPayload.schemaId, bytes32(0), @@ -107,7 +107,7 @@ contract AttestationRegistry is OwnableUpgradeable { uint64(block.timestamp), attestationPayload.expirationDate, 0, - version, + _version, false, attestationPayload.subject, attestationPayload.attestationData @@ -128,10 +128,10 @@ contract AttestationRegistry is OwnableUpgradeable { function massImport(AttestationPayload[] calldata attestationsPayloads, address portal) public onlyOwner { for (uint256 i = 0; i < attestationsPayloads.length; i++) { // Auto increment attestation counter - attestationIdCounter++; - bytes32 id = bytes32(abi.encode(attestationIdCounter)); + _attestationIdCounter++; + bytes32 id = bytes32(abi.encode(_attestationIdCounter)); // Create attestation - attestations[id] = Attestation( + _attestations[id] = Attestation( id, attestationsPayloads[i].schemaId, bytes32(0), @@ -140,7 +140,7 @@ contract AttestationRegistry is OwnableUpgradeable { uint64(block.timestamp), attestationsPayloads[i].expirationDate, 0, - version, + _version, false, attestationsPayloads[i].subject, attestationsPayloads[i].attestationData @@ -158,8 +158,8 @@ contract AttestationRegistry is OwnableUpgradeable { function replace(bytes32 attestationId, AttestationPayload calldata attestationPayload, address attester) public { attest(attestationPayload, attester); revoke(attestationId); - bytes32 replacedBy = bytes32(abi.encode(attestationIdCounter)); - attestations[attestationId].replacedBy = replacedBy; + bytes32 replacedBy = bytes32(abi.encode(_attestationIdCounter)); + _attestations[attestationId].replacedBy = replacedBy; emit AttestationReplaced(attestationId, replacedBy); } @@ -187,12 +187,12 @@ contract AttestationRegistry is OwnableUpgradeable { */ function revoke(bytes32 attestationId) public { if (!isRegistered(attestationId)) revert AttestationNotAttested(); - if (attestations[attestationId].revoked) revert AlreadyRevoked(); - if (msg.sender != attestations[attestationId].portal) revert OnlyAttestingPortal(); - if (!isRevocable(attestations[attestationId].portal)) revert AttestationNotRevocable(); + if (_attestations[attestationId].revoked) revert AlreadyRevoked(); + if (msg.sender != _attestations[attestationId].portal) revert OnlyAttestingPortal(); + if (!isRevocable(_attestations[attestationId].portal)) revert AttestationNotRevocable(); - attestations[attestationId].revoked = true; - attestations[attestationId].revocationDate = uint64(block.timestamp); + _attestations[attestationId].revoked = true; + _attestations[attestationId].revocationDate = uint64(block.timestamp); emit AttestationRevoked(attestationId); } @@ -213,7 +213,7 @@ contract AttestationRegistry is OwnableUpgradeable { * @return true if the attestation is registered, false otherwise */ function isRegistered(bytes32 attestationId) public view returns (bool) { - return attestations[attestationId].attestationId != bytes32(0); + return _attestations[attestationId].attestationId != bytes32(0); } /** @@ -233,7 +233,7 @@ contract AttestationRegistry is OwnableUpgradeable { */ function getAttestation(bytes32 attestationId) public view returns (Attestation memory) { if (!isRegistered(attestationId)) revert AttestationNotAttested(); - return attestations[attestationId]; + return _attestations[attestationId]; } /** @@ -241,9 +241,9 @@ contract AttestationRegistry is OwnableUpgradeable { * @return The new version number */ function incrementVersionNumber() public onlyOwner returns (uint16) { - ++version; - emit VersionUpdated(version); - return version; + ++_version; + emit VersionUpdated(_version); + return _version; } /** @@ -251,7 +251,7 @@ contract AttestationRegistry is OwnableUpgradeable { * @return The current version number */ function getVersionNumber() public view returns (uint16) { - return version; + return _version; } /** @@ -259,6 +259,6 @@ contract AttestationRegistry is OwnableUpgradeable { * @return The attestationIdCounter */ function getAttestationIdCounter() public view returns (uint32) { - return attestationIdCounter; + return _attestationIdCounter; } } diff --git a/src/PortalRegistry.sol b/src/PortalRegistry.sol index e77172b3..9db947c0 100644 --- a/src/PortalRegistry.sol +++ b/src/PortalRegistry.sol @@ -17,11 +17,11 @@ import { IRouter } from "./interface/IRouter.sol"; contract PortalRegistry is OwnableUpgradeable { IRouter public router; - mapping(address id => Portal portal) private portals; + mapping(address id => Portal portal) private _portals; - mapping(address issuerAddress => bool isIssuer) private issuers; + mapping(address issuerAddress => bool isIssuer) private _issuers; - address[] private portalAddresses; + address[] private _portalAddresses; /// @notice Error thrown when an invalid Router address is given error RouterInvalid(); @@ -70,7 +70,7 @@ contract PortalRegistry is OwnableUpgradeable { * @param issuer the address to register as an issuer */ function setIssuer(address issuer) public onlyOwner { - issuers[issuer] = true; + _issuers[issuer] = true; } /** @@ -78,7 +78,7 @@ contract PortalRegistry is OwnableUpgradeable { * @param issuer the address to be revoked as an issuer */ function removeIssuer(address issuer) public onlyOwner { - issuers[issuer] = false; + _issuers[issuer] = false; } /** @@ -86,7 +86,7 @@ contract PortalRegistry is OwnableUpgradeable { * @return A flag indicating whether the given address is an issuer */ function isIssuer(address issuer) public view returns (bool) { - return issuers[issuer]; + return _issuers[issuer]; } /** @@ -114,10 +114,10 @@ contract PortalRegistry is OwnableUpgradeable { string memory ownerName ) public onlyIssuers(msg.sender) { // Check if portal already exists - if (portals[id].id != address(0)) revert PortalAlreadyExists(); + if (_portals[id].id != address(0)) revert PortalAlreadyExists(); // Check if portal is a smart contract - if (!isContractAddress(id)) revert PortalAddressInvalid(); + if (!_isContractAddress(id)) revert PortalAddressInvalid(); // Check if name is not empty if (bytes(name).length == 0) revert PortalNameMissing(); @@ -136,8 +136,8 @@ contract PortalRegistry is OwnableUpgradeable { // Add portal to mapping Portal memory newPortal = Portal(id, msg.sender, modules, isRevocable, name, description, ownerName); - portals[id] = newPortal; - portalAddresses.push(id); + _portals[id] = newPortal; + _portalAddresses.push(id); // Emit event emit PortalRegistered(name, description, id); @@ -168,7 +168,7 @@ contract PortalRegistry is OwnableUpgradeable { */ function getPortalByAddress(address id) public view returns (Portal memory) { if (!isRegistered(id)) revert PortalNotRegistered(); - return portals[id]; + return _portals[id]; } /** @@ -177,7 +177,7 @@ contract PortalRegistry is OwnableUpgradeable { * @return True if the Portal is registered, false otherwise */ function isRegistered(address id) public view returns (bool) { - return portals[id].id != address(0); + return _portals[id].id != address(0); } /** @@ -186,7 +186,7 @@ contract PortalRegistry is OwnableUpgradeable { * @dev Returns the length of the `portalAddresses` array */ function getPortalsCount() public view returns (uint256) { - return portalAddresses.length; + return _portalAddresses.length; } /** @@ -194,7 +194,7 @@ contract PortalRegistry is OwnableUpgradeable { * @param contractAddress address to be verified * @return the result as true if it is a smart contract else false */ - function isContractAddress(address contractAddress) internal view returns (bool) { + function _isContractAddress(address contractAddress) internal view returns (bool) { return contractAddress.code.length > 0; } } diff --git a/src/Router.sol b/src/Router.sol index 31d2ecd4..f5a22198 100644 --- a/src/Router.sol +++ b/src/Router.sol @@ -10,10 +10,10 @@ import { IRouter } from "./interface/IRouter.sol"; * @notice This contract aims to provides a single entrypoint for the Verax registries */ contract Router is IRouter, OwnableUpgradeable { - address private ATTESTATION_REGISTRY; - address private MODULE_REGISTRY; - address private PORTAL_REGISTRY; - address private SCHEMA_REGISTRY; + address private _attestationRegistry; + address private _moduleRegistry; + address private _portalRegistry; + address private _schemaRegistry; event AttestationRegistryUpdated(address indexed registryAddress); event ModuleRegistryUpdated(address indexed registryAddress); @@ -25,38 +25,38 @@ contract Router is IRouter, OwnableUpgradeable { } function getAttestationRegistry() external view override returns (address) { - return ATTESTATION_REGISTRY; + return _attestationRegistry; } - function updateAttestationRegistry(address _attestationRegistry) public onlyOwner { - ATTESTATION_REGISTRY = _attestationRegistry; + function updateAttestationRegistry(address attestationRegistry) public onlyOwner { + _attestationRegistry = attestationRegistry; emit AttestationRegistryUpdated(_attestationRegistry); } function getModuleRegistry() external view override returns (address) { - return MODULE_REGISTRY; + return _moduleRegistry; } - function updateModuleRegistry(address _moduleRegistry) public onlyOwner { - MODULE_REGISTRY = _moduleRegistry; + function updateModuleRegistry(address moduleRegistry) public onlyOwner { + _moduleRegistry = moduleRegistry; emit ModuleRegistryUpdated(_moduleRegistry); } function getPortalRegistry() external view override returns (address) { - return PORTAL_REGISTRY; + return _portalRegistry; } - function updatePortalRegistry(address _portalRegistry) public onlyOwner { - PORTAL_REGISTRY = _portalRegistry; + function updatePortalRegistry(address portalRegistry) public onlyOwner { + _portalRegistry = portalRegistry; emit PortalRegistryUpdated(_portalRegistry); } function getSchemaRegistry() external view override returns (address) { - return SCHEMA_REGISTRY; + return _schemaRegistry; } - function updateSchemaRegistry(address _schemaRegistry) public onlyOwner { - SCHEMA_REGISTRY = _schemaRegistry; + function updateSchemaRegistry(address schemaRegistry) public onlyOwner { + _schemaRegistry = schemaRegistry; emit SchemaRegistryUpdated(_schemaRegistry); } } diff --git a/src/SchemaRegistry.sol b/src/SchemaRegistry.sol index 1ad8c5c0..25ed3393 100644 --- a/src/SchemaRegistry.sol +++ b/src/SchemaRegistry.sol @@ -14,7 +14,7 @@ import { IRouter } from "./interface/IRouter.sol"; contract SchemaRegistry is OwnableUpgradeable { IRouter public router; /// @dev The list of Schemas, accessed by their ID - mapping(bytes32 id => Schema schema) private schemas; + mapping(bytes32 id => Schema schema) private _schemas; /// @dev The list of Schema IDs bytes32[] public schemaIds; @@ -99,7 +99,7 @@ contract SchemaRegistry is OwnableUpgradeable { revert SchemaAlreadyExists(); } - schemas[schemaId] = Schema(name, description, context, schemaString); + _schemas[schemaId] = Schema(name, description, context, schemaString); schemaIds.push(schemaId); emit SchemaCreated(schemaId, name, description, context, schemaString); } @@ -111,7 +111,7 @@ contract SchemaRegistry is OwnableUpgradeable { */ function updateContext(bytes32 schemaId, string memory context) public onlyIssuers(msg.sender) { if (!isRegistered(schemaId)) revert SchemaNotRegistered(); - schemas[schemaId].context = context; + _schemas[schemaId].context = context; } /** @@ -121,7 +121,7 @@ contract SchemaRegistry is OwnableUpgradeable { */ function getSchema(bytes32 schemaId) public view returns (Schema memory) { if (!isRegistered(schemaId)) revert SchemaNotRegistered(); - return schemas[schemaId]; + return _schemas[schemaId]; } /** @@ -139,6 +139,6 @@ contract SchemaRegistry is OwnableUpgradeable { * @return True if the Schema is registered, false otherwise */ function isRegistered(bytes32 schemaId) public view returns (bool) { - return bytes(schemas[schemaId].name).length > 0; + return bytes(_schemas[schemaId].name).length > 0; } }