InspectionRules
InspectionRules
Manages the lifecycle of regeneration inspections, from request to realization and validation.
This contract allows Regenerators to request inspections, and Inspectors to accept, perform, and submit them. It integrates with various other rule contracts for user validation, level updates, and penalty management.
MAX_REGENERATOR_INSPECTIONS
uint8 MAX_REGENERATOR_INSPECTIONS
The maximum number of inspections a Regenerator can receive.
MAX_BIODIVERSITY_RESULT
uint32 MAX_BIODIVERSITY_RESULT
The maximum result value for the biodiversity score in an inspection.
allowedInitialRequests
uint8 allowedInitialRequests
Number of initial inspection requests a regenerator can make without timeBetweenInspections delay.
timeBetweenInspections
uint32 timeBetweenInspections
Time (in blocks) a regenerator must wait between inspection requests after exceeding initial allowed requests.
blocksToExpireAcceptedInspection
uint32 blocksToExpireAcceptedInspection
Amount of blocks an accepted inspection has before it expires if not realized.
acceptInspectionDelayBlocks
uint32 acceptInspectionDelayBlocks
Amount of blocks that inspectors must wait after a request is made before they can accept it.
securityBlocksToValidation
uint32 securityBlocksToValidation
Amount of blocks for validators to analyze inspections before an era ends.
inspectionsCount
uint64 inspectionsCount
Valid inspections count (inspections not invalidated).
inspectionsTotalCount
uint64 inspectionsTotalCount
Total inspections count, including open, accepted, realized, and invalidated ones.
realizedInspectionsCount
uint256 realizedInspectionsCount
Realized inspections count (inspections that have been completed and submitted).
inspectionsTreesImpact
uint256 inspectionsTreesImpact
Sum of all valid inspections' trees impact from all past settled eras.
inspectionsBiodiversityImpact
uint256 inspectionsBiodiversityImpact
Sum of all valid inspections' biodiversity impact from all past settled eras.
totalImpactRegenerators
uint256 totalImpactRegenerators
The total count of regenerators who are considered "impact regenerators", have reached the minimum of one inspection validated.
inspectionPenalized
mapping(uint64 => bool) inspectionPenalized
Tracks inspection IDs that have already been invalidated.
inspectorRules
contract IInspectorRules inspectorRules
InspectorRules contract interface for interacting with inspector-specific logic.
regeneratorRules
contract IRegeneratorRules regeneratorRules
RegeneratorRules contract interface for interacting with regenerator-specific logic.
communityRules
contract ICommunityRules communityRules
CommunityRules contract interface for checking user types and other community-wide rules.
validationRules
contract IValidationRules validationRules
ValidationRules contract interface for handling inspection invalidations.
activistRules
contract IActivistRules activistRules
ActivistRules contract interface for updating activist levels based on inspection activities.
voteRules
contract IVoteRules voteRules
VoteRules contract interface for checking voter eligibility.
regenerationIndexRules
contract IRegenerationIndexRules regenerationIndexRules
RegenerationIndexRules contract interface for calculating regeneration scores.
impactPerEra
mapping(uint256 => struct EraImpact) impactPerEra
Tracks the impact generated within each specific era.
lastSettledEra
uint256 lastSettledEra
Tracks the number of the last era that impact has been set.
constructor
constructor(uint32 timeBetweenInspections_, uint32 blocksToExpireAcceptedInspection_, uint8 allowedInitialRequests_, uint32 acceptInspectionDelayBlocks_, uint32 securityBlocksToValidation_) public
Initializes the InspectionRules contract with key time and quantity parameters.
Sets immutable values that govern inspection delays, expiration, and initial allowances.
Parameters
| Name | Type | Description |
|---|---|---|
| timeBetweenInspections_ | uint32 | The number of blocks a regenerator must wait between requests. |
| blocksToExpireAcceptedInspection_ | uint32 | The number of blocks before an accepted inspection expires. |
| allowedInitialRequests_ | uint8 | The number of initial requests allowed without delay. |
| acceptInspectionDelayBlocks_ | uint32 | The number of blocks inspectors must wait before accept a new inspection. |
| securityBlocksToValidation_ | uint32 | The number of security blocks for validators before era end. |
setContractInterfaces
function setContractInterfaces(struct ContractsDependency contractDependency) external
Sets the addresses of all essential external contracts interfaces this contract depends on.
This function can only be called once by the contract owner after deployment. It initializes references to various *Rules contracts and the VoteRules contract. Ownership should be renounced after this call.
Parameters
| Name | Type | Description |
|---|---|---|
| contractDependency | struct ContractsDependency | Struct containing addresses of necessary system contracts. |
requestInspection
function requestInspection() external
Regenerators agree to receive an inspector to assess their registered area.
They can make an allowedInitialRequests number of requests without delay.
After that, they must wait timeBetweenInspections blocks between requests.
A hard limit of 6 total inspections is enforced.
Requirements:
- The caller (
msg.sender) must be a registeredREGENERATOR. - The regenerator must not have a
_pendingInspectionalready open. - The regenerator must adhere to the
timeBetweenInspectionsdelay ifallowedInitialRequestsare used up. - The regenerator must have completed less than 6 total inspections.
Allows a regenerator to request a new inspection for their registered area.
acceptInspection
function acceptInspection(uint64 inspectionId) external
Inspectors must only accept inspections they are capable of performing, being aware of the safety risks and responsibilities. By accepting an inspection, inspectors agree that the they are responsible for their own safety at the data collection. It is recommended to use long sleeves clothes, hats, boots that can prevent bites from animals, gloves to protect from spines and any other useful safety equipment, such as machetes or pepper spray. Accepting an inspection counts as a 'give-up' until realized. Inspectors can only accept one open inspection at a time and cannot inspect the same regenerator twice. They must also adhere to specific delays and security windows.
Requirements:
- The caller (
msg.sender) must be a registeredINSPECTOR. - The inspector must have less than
MAX_GIVEUPS(from InspectorRules). - The
inspectionIdmust correspond to an existing inspection. - The inspector must not already have an inspection
ACCEPTEDthat is not yetINSPECTEDorINVALIDATEDorEXPIRED. - The inspector must not have previously inspected this specific regenerator.
- The inspection's status must be
OPENorEXPIRED. - The
acceptInspectionDelayBlocksmust have passed since the inspection was created. - The system must not be within the
securityBlocksToValidationwindow before an era ends. - The inspector must adhere to
inspectorRules.canAcceptInspection(delay from last realized inspection). - The
inspection.regeneratormust be a validREGENERATOR.
Allows an inspector to accept an open or expired inspection request.
Parameters
| Name | Type | Description |
|---|---|---|
| inspectionId | uint64 | The unique ID of the inspection the inspector wishes to accept. |
realizeInspection
function realizeInspection(uint64 inspectionId, string proofPhotos, string justificationReport, uint32 treesResult, uint32 biodiversityResult) external
Inspectors must evaluate the amount of trees and species of the regeneration area. How many trees, palm trees and other plants over 1m high and 3cm in diameter there is in the regenerating area? Justify your answer in the report. How many different species of those plants/trees were found? Each different species is equivalent to one unity and only trees and plants managed or planted by the regenerator should be counted. Justify your answer in the report. Max result of 200.000 trees and 300 biodiversity. Zero score means invalid inspection. NOTE: If the inspector finds something suspicous about the inspected regenerator, such as invalid area, suspicious of fake account, or if the Regenerator is not findable, inspectors are encourage to realize passing 0 as values with his justification at the report to avoid being penalized.
Allow a inspector realize a inspection and mark as INSPECTED.
Parameters
| Name | Type | Description |
|---|---|---|
| inspectionId | uint64 | The id of the inspection to be realized. |
| proofPhotos | string | The string of a photo with the regenerator or the string of a document with the proofPhoto with the regenerator and other area photos. |
| justificationReport | string | The justification and report of the result found. |
| treesResult | uint32 | The number of trees, palm trees and other plants over 1m high and 3cm in diameter found in the regeneration area. Only plants managed or planted by the regenerator must be counted. |
| biodiversityResult | uint32 | The number of different species of trees, palm trees and other plants over 1m high and 3cm in diameter found in the regeneration area. Only plants managed or planted by the regenerator must be counted. |
addInspectionValidation
function addInspectionValidation(uint64 id, string justification) external
Allows a voter to cast a vote to invalidate an inspection. This function increments the validation count for the inspection and may trigger its invalidation.
Requirements:
- The
justificationstring must not exceedMAX_VALIDATION_JUSTIFICATION_LENGTH(300) characters. - The caller (
msg.sender) must be a registeredvoter(voteRules.canVote). - The caller must have waited the required
timeBetweenVotes(fromvalidationRules.waitedTimeBetweenVotes). - The
inspectionIdmust correspond to an existing and currently valid inspection. - The inspection must have been realized (
INSPECTEDstatus). - The current
poolCurrentEra() must be less than or equal to theinspection'sinspectedAtEra.
Parameters
| Name | Type | Description |
|---|---|---|
| id | uint64 | The unique ID of the inspection to be validated/invalidated. |
| justification | string | A string explaining why the inspection is being invalidated. |
getInspection
function getInspection(uint64 id) public view returns (struct Inspection)
Returns a inspection by id if that exists.
Parameters
| Name | Type | Description |
|---|---|---|
| id | uint64 | The id of the inspection to return. |
getInspectionsHistory
function getInspectionsHistory(address addr) public view returns (uint64[])
Get all regenerators inspections ID's list.
Allows to get all regenerator inspections with status INSPECTED.
Parameters
| Name | Type | Description |
|---|---|---|
| addr | address | Regenerator address to check. |
waitToRequest
function waitToRequest(struct Regenerator regenerator) public view returns (bool)
Checks if regenerator waited timeBetweenInspections.
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bool | bool True if can request. |
calculateBlocksToExpire
function calculateBlocksToExpire(uint64 inspectionId) public view returns (uint256)
Function to calculate amount of blocks to expire an inspection.
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | uint256 Return amount of blocks to expire an inspection. |
alreadyHaveInspectionAccepted
function alreadyHaveInspectionAccepted() public view returns (bool)
Function that checks if an inspector already have an open inspection.
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bool | bool True if can accept new inspection. False if has already an open inspection. |
acceptInspectionDelayBlocksPassed
function acceptInspectionDelayBlocksPassed(struct Inspection inspection) public view returns (bool)
Function that checks if the inspection delay blocks has passed.
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bool | bool True if can accept, false if not. |
InspectionRequested
event InspectionRequested(uint256 inspectionId, address regeneratorAddress, uint256 createdAt)
Emitted when a new inspection request is successfully created by a Regenerator.
Parameters
| Name | Type | Description |
|---|---|---|
| inspectionId | uint256 | The unique ID of the newly created inspection. |
| regeneratorAddress | address | The address of the Regenerator who requested the inspection. |
| createdAt | uint256 | The block number when the inspection was requested. |
InspectionAccepted
event InspectionAccepted(uint256 inspectionId, address inspectorAddress, uint256 acceptedAt)
Emitted when an Inspector successfully accepts an open inspection.
Parameters
| Name | Type | Description |
|---|---|---|
| inspectionId | uint256 | The ID of the inspection that was accepted. |
| inspectorAddress | address | The address of the Inspector who accepted the inspection. |
| acceptedAt | uint256 | The block number when the inspection was accepted. |
InspectionRealized
event InspectionRealized(uint256 inspectionId, address inspectorAddress, address regeneratorAddress, uint32 treesResult, uint32 biodiversityResult, uint32 regenerationScore, uint256 inspectedAt)
Emitted when an accepted inspection is successfully realized and submitted by an Inspector.
Parameters
| Name | Type | Description |
|---|---|---|
| inspectionId | uint256 | The ID of the inspection that was realized. |
| inspectorAddress | address | The address of the Inspector who realized the inspection. |
| regeneratorAddress | address | The address of the Regenerator whose area was inspected. |
| treesResult | uint32 | The reported number of trees. |
| biodiversityResult | uint32 | The reported number of species. |
| regenerationScore | uint32 | The calculated regeneration score. |
| inspectedAt | uint256 | The block number when the inspection was realized. |
InspectionValidation
event InspectionValidation(address _validatorAddress, uint256 _resourceId, string _justification)
Emitted
Parameters
| Name | Type | Description |
|---|---|---|
| _validatorAddress | address | The address of the validator. |
| _resourceId | uint256 | The id of the resource receiving the vote. |
| _justification | string | The justification provided for the vote. |
InspectionInvalidated
event InspectionInvalidated(uint256 inspectionId, address inspectorAddress, address regeneratorAddress, uint256 invalidatedAt)
Emitted when an inspection is successfully invalidated due to validator votes.
Parameters
| Name | Type | Description |
|---|---|---|
| inspectionId | uint256 | The ID of the inspection that was invalidated. |
| inspectorAddress | address | The address of the Inspector who performed the invalidated inspection. |
| regeneratorAddress | address | The address of the Regenerator whose inspection was invalidated. |
| invalidatedAt | uint256 | The block number when the inspection was invalidated. |