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

DO NOT MERGE - chore: Cleanup and improvements (underscore on private/internal fields) #219

Closed
wants to merge 1 commit into from
Closed
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
50 changes: 25 additions & 25 deletions src/AttestationRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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),
Expand All @@ -107,7 +107,7 @@ contract AttestationRegistry is OwnableUpgradeable {
uint64(block.timestamp),
attestationPayload.expirationDate,
0,
version,
_version,
false,
attestationPayload.subject,
attestationPayload.attestationData
Expand All @@ -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),
Expand All @@ -140,7 +140,7 @@ contract AttestationRegistry is OwnableUpgradeable {
uint64(block.timestamp),
attestationsPayloads[i].expirationDate,
0,
version,
_version,
false,
attestationsPayloads[i].subject,
attestationsPayloads[i].attestationData
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

/**
Expand All @@ -233,32 +233,32 @@ contract AttestationRegistry is OwnableUpgradeable {
*/
function getAttestation(bytes32 attestationId) public view returns (Attestation memory) {
if (!isRegistered(attestationId)) revert AttestationNotAttested();
return attestations[attestationId];
return _attestations[attestationId];
}

/**
* @notice Increments the registry version
* @return The new version number
*/
function incrementVersionNumber() public onlyOwner returns (uint16) {
++version;
emit VersionUpdated(version);
return version;
++_version;
emit VersionUpdated(_version);
return _version;
}

/**
* @notice Gets the registry version
* @return The current version number
*/
function getVersionNumber() public view returns (uint16) {
return version;
return _version;
}

/**
* @notice Gets the attestation id counter
* @return The attestationIdCounter
*/
function getAttestationIdCounter() public view returns (uint32) {
return attestationIdCounter;
return _attestationIdCounter;
}
}
28 changes: 14 additions & 14 deletions src/PortalRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -70,23 +70,23 @@ 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;
}

/**
* @notice Revokes issuer status from an address
* @param issuer the address to be revoked as an issuer
*/
function removeIssuer(address issuer) public onlyOwner {
issuers[issuer] = false;
_issuers[issuer] = false;
}

/**
* @notice Checks if a given address is an issuer
* @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];
}

/**
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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];
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -186,15 +186,15 @@ contract PortalRegistry is OwnableUpgradeable {
* @dev Returns the length of the `portalAddresses` array
*/
function getPortalsCount() public view returns (uint256) {
return portalAddresses.length;
return _portalAddresses.length;
}

/**
* Check if address is smart contract and not EOA
* @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;
}
}
32 changes: 16 additions & 16 deletions src/Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
10 changes: 5 additions & 5 deletions src/SchemaRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}

/**
Expand All @@ -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];
}

/**
Expand All @@ -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;
}
}
Loading