Skip to main content

InspectorRules

InspectorRules​

This contract defines and manages the rules and data specific to "Inspector" users within the system. Inspectors are primarily responsible for collecting data from regenerators. and performing inspections, which may be subject to penalties for non-compliance.

Inherits functionalities from Callable (for whitelisted function access) and Ownable (for contract deploy setup). It interacts with CommunityRules for general user management and InspectorPool for reward distribution. This contract handles inspector registration, inspection tracking, give-ups, and penalties.

MINIMUM_INSPECTIONS_TO_POOL​

uint8 MINIMUM_INSPECTIONS_TO_POOL

The minimum number of completed inspections required for an inspector to be eligible for pool rewards.

MAX_GIVEUPS​

uint8 MAX_GIVEUPS

The maximum allowed number of "give-ups" (accepted but unrealized inspections) before an inspector's validity is affected (blocked from accepting new inspections).

BLOCKS_TO_ACCEPT​

uint32 BLOCKS_TO_ACCEPT

The number of blocks an inspector must wait to accept a new inspection after realizing one.

maxPenalties​

uint8 maxPenalties

The maximum number of penalties an inspector can accumulate before facing invalidation.

penalties​

mapping(address => struct Penalty[]) penalties

A mapping from an inspector's wallet address to an array of Penalty structs they have received.

inspectorsAddress​

mapping(uint256 => address) inspectorsAddress

A mapping from a unique inspector ID to their corresponding wallet address.

communityRules​

contract ICommunityRules communityRules

The address of the CommunityRules contract, used to interact with community-wide rules and user types.

inspectorPool​

contract IInspectorPool inspectorPool

The address of the InspectorPool contract, responsible for managing and distributing token rewards to inspectors.

inspectionRulesAddress​

address inspectionRulesAddress

The address of the InspectionRules contract.

constructor​

constructor(address communityRulesAddress, address inspectorPoolAddress, uint8 maxPenalties_) public

Initializes the InspectorRules contract with key parameters.

Parameters​

NameTypeDescription
communityRulesAddressaddressThe address of the deployed CommunityRules contract.
inspectorPoolAddressaddressThe address of the deployed InspectorPool contract.
maxPenalties_uint8The maximum allowed penalties for an inspector.

setContractCall​

function setContractCall(address _inspectionRulesAddress) public

onlyOwner function to set contract call addresses. This function must be called only once after the contract deploy and ownership must be renounced.

Parameters​

NameTypeDescription
_inspectionRulesAddressaddressAddress of InspectionRules.

addInspector​

function addInspector(string name, string proofPhoto) external

Users must meet specific criteria (previous invitation, system vacancies) to successfully register as an inspector.

Requirements:

  • The caller (msg.sender) must not already be a registered user.
  • The name string must not exceed MAX_NAME_LENGTH (50) characters in byte length.
  • The proofPhoto string must not exceed MAX_PROOF_PHOTO_LENGTH (150) characters in byte length.
  • Number of vacancies is proportional to the number of regenerators.
  • The caller must have a previous valid invitation.

Allows a user to attempt to register as an inspector. Creates a new Inspector profile for the caller if all requirements are met.

Parameters​

NameTypeDescription
namestringThe chosen name for the inspector.
proofPhotostringA hash or identifier (e.g., URL) for the inspector's identity verification photo.

withdraw​

function withdraw() external

Inspectors can claim tokens for their inspection service, provided they meet the minimum inspection threshold and are eligible for the current era.

Requirements:

  • The caller (msg.sender) must be a registered INSPECTOR.
  • The inspector must have completed at least (3) inspections.
  • The inspector must be eligible for withdrawal in their current era (checked via inspectorPool.canWithdraw).
  • The inspector's current era (inspector.pool.currentEra) will be incremented upon successful withdrawal attempt.

Allows an inspector to initiate a withdrawal of Regeneration Credits based on their completed inspections and current era.

afterAcceptInspection​

function afterAcceptInspection(address addr, uint64 lastInspectionId) external

This function is intended to be called by the InspectionRules contract.

Processes actions after an inspection is accepted by an inspector. This marks the time of acceptance and increments the inspector's "give-up" count.

Parameters​

NameTypeDescription
addraddressThe inspector's wallet address.
lastInspectionIduint64The ID of the inspection that was accepted.

afterRealizeInspection​

function afterRealizeInspection(address addr, uint32 score, uint64 inspectionId) external returns (uint256)

This function is called by the InspectionRules contract after an inspection is realized.

MustBeAllowedCaller function to handle actions after an inspector successfully realizes (completes) an inspection. This decrements give-ups and increments total inspections.

Parameters​

NameTypeDescription
addraddressThe inspector's wallet address.
scoreuint32The inspection regenerationScore.
inspectionIduint64The inspection unique ID.

Return Values​

NameTypeDescription
[0]uint256uint256 The updated total number of inspections completed by the inspector.

addPenalty​

function addPenalty(address addr, uint64 inspectionId) external returns (uint256)

This function can only be called by addresses whitelisted via the Callable contract's mechanisms.

Allows an authorized caller (ValidationRules contract) to add a penalty to an inspector's record. This function should be called when an inspector's performance is unsatisfactory, for example, without justification or proofPhoto.

Parameters​

NameTypeDescription
addraddressThe wallet address of the inspector receiving the penalty.
inspectionIduint64The ID of the inspection associated with this penalty.

Return Values​

NameTypeDescription
[0]uint256uint256 The total number of penalties the inspector has accumulated.

removePoolLevels​

function removePoolLevels(address addr, bool denied) external

Should only be called by the ValidatorRules address.

Allows the validator rules to remove levels from an inspector's pool. This function updates the inspector's local level and notifies the InspectorPool contract.

Parameters​

NameTypeDescription
addraddressThe wallet address of the inspector from whom levels are to be removed.
deniedboolRemove level user status. If true, user is being denied.

decrementInspections​

function decrementInspections(address addr) external

Should only be called by the ValidatorRules address.

Decrements an inspector's total completed inspections count. This function is called when an inspection previously counted as valid is invalidated.

Parameters​

NameTypeDescription
addraddressThe inspector's wallet address. Requirements: - The inspector's totalInspections count must be greater than 0.

denyInspector​

function denyInspector(address userAddress) external

Sets a user's to DENIED in CommunityRules and removes their levels from pools.

Parameters​

NameTypeDescription
userAddressaddressThe address of the user to deny.

totalPenalties​

function totalPenalties(address addr) public view returns (uint256)

Provides the current penalty count for a specific inspector.

Returns the total number of penalties an inspector address has accumulated.

Parameters​

NameTypeDescription
addraddressThe inspector's wallet address.

Return Values​

NameTypeDescription
[0]uint256uint256 The total number of penalties for the given address.

getInspector​

function getInspector(address addr) public view returns (struct Inspector)

Provides the full profile of an inspector.

Returns the detailed Inspector data for a given address.

Parameters​

NameTypeDescription
addraddressThe address of the inspector to retrieve.

Return Values​

NameTypeDescription
[0]struct InspectorInspector The Inspector struct containing the user's data.

poolCurrentEra​

function poolCurrentEra() public view returns (uint256)

This function provides the current era from the perspective of the reward pool. * @return uint256 The current era of the InspectorPool.

Returns the current era as determined by the InspectorPool contract.

isInspectorValid​

function isInspectorValid(address addr) public view returns (bool)

Checks if an inspector has less than MAX_GIVEUPS (maximum allowed give-ups). Inspectors with MAX_GIVEUPS or more are considered invalid and blocked from core actions.

Parameters​

NameTypeDescription
addraddressThe inspector's wallet address.

Return Values​

NameTypeDescription
[0]boolbool true if the inspector is currently valid (has less than max give-ups), false otherwise.

canAcceptInspection​

function canAcceptInspection(address addr) public view returns (bool)

Checks if an inspector is able to accept a new inspection, based on the time elapsed since their last realized inspection.

Parameters​

NameTypeDescription
addraddressThe inspector's wallet address.

Return Values​

NameTypeDescription
[0]boolbool true if the inspector can accept a new inspection, false otherwise.

InspectorRegistered​

event InspectorRegistered(uint256 id, address inspectorAddress, string name, uint256 blockNumber)

Emitted when a new inspector successfully registers.

Parameters​

NameTypeDescription
iduint256The unique ID of the newly registered inspector.
inspectorAddressaddressThe wallet address of the inspector.
namestringThe name provided by the inspector.
blockNumberuint256The block number at which the registration occurred.

InspectorWithdrawalInitiated​

event InspectorWithdrawalInitiated(address inspectorAddress, uint256 era, uint256 blockNumber)

Emitted when an inspector successfully initiates a withdrawal of tokens.

Parameters​

NameTypeDescription
inspectorAddressaddressThe address of the inspector initiating the withdrawal.
erauint256The era for which the withdrawal was initiated.
blockNumberuint256The block number at which the withdrawal was initiated.

InspectorLevelIncreased​

event InspectorLevelIncreased(address inspectorAddress, uint256 newLevel, uint256 blockNumber)

Emitted when an inspector's level is increased.

Parameters​

NameTypeDescription
inspectorAddressaddressThe address of the inspector whose level was increased.
newLeveluint256The new total level of the inspector.
blockNumberuint256The block number at which the level increase occurred.