Skip to main content

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

NameTypeDescription
timeBetweenInspections_uint32The number of blocks a regenerator must wait between requests.
blocksToExpireAcceptedInspection_uint32The number of blocks before an accepted inspection expires.
allowedInitialRequests_uint8The number of initial requests allowed without delay.
acceptInspectionDelayBlocks_uint32The number of blocks inspectors must wait before accept a new inspection.
securityBlocksToValidation_uint32The 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

NameTypeDescription
contractDependencystruct ContractsDependencyStruct 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 registered REGENERATOR.
  • The regenerator must not have a _pendingInspection already open.
  • The regenerator must adhere to the timeBetweenInspections delay if allowedInitialRequests are 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 registered INSPECTOR.
  • The inspector must have less than MAX_GIVEUPS (from InspectorRules).
  • The inspectionId must correspond to an existing inspection.
  • The inspector must not already have an inspection ACCEPTED that is not yet INSPECTED or INVALIDATED or EXPIRED.
  • The inspector must not have previously inspected this specific regenerator.
  • The inspection's status must be OPEN or EXPIRED.
  • The acceptInspectionDelayBlocks must have passed since the inspection was created.
  • The system must not be within the securityBlocksToValidation window before an era ends.
  • The inspector must adhere to inspectorRules.canAcceptInspection (delay from last realized inspection).
  • The inspection.regenerator must be a valid REGENERATOR.

Allows an inspector to accept an open or expired inspection request.

Parameters

NameTypeDescription
inspectionIduint64The 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

NameTypeDescription
inspectionIduint64The id of the inspection to be realized.
proofPhotosstringThe string of a photo with the regenerator or the string of a document with the proofPhoto with the regenerator and other area photos.
justificationReportstringThe justification and report of the result found.
treesResultuint32The 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.
biodiversityResultuint32The 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 justification string must not exceed MAX_VALIDATION_JUSTIFICATION_LENGTH (300) characters.
  • The caller (msg.sender) must be a registered voter (voteRules.canVote).
  • The caller must have waited the required timeBetweenVotes (from validationRules.waitedTimeBetweenVotes).
  • The inspectionId must correspond to an existing and currently valid inspection.
  • The inspection must have been realized (INSPECTED status).
  • The current poolCurrentEra() must be less than or equal to the inspection's inspectedAtEra .

Parameters

NameTypeDescription
iduint64The unique ID of the inspection to be validated/invalidated.
justificationstringA 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

NameTypeDescription
iduint64The 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

NameTypeDescription
addraddressRegenerator address to check.

waitToRequest

function waitToRequest(struct Regenerator regenerator) public view returns (bool)

Checks if regenerator waited timeBetweenInspections.

Return Values

NameTypeDescription
[0]boolbool 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

NameTypeDescription
[0]uint256uint256 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

NameTypeDescription
[0]boolbool 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

NameTypeDescription
[0]boolbool 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

NameTypeDescription
inspectionIduint256The unique ID of the newly created inspection.
regeneratorAddressaddressThe address of the Regenerator who requested the inspection.
createdAtuint256The 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

NameTypeDescription
inspectionIduint256The ID of the inspection that was accepted.
inspectorAddressaddressThe address of the Inspector who accepted the inspection.
acceptedAtuint256The 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

NameTypeDescription
inspectionIduint256The ID of the inspection that was realized.
inspectorAddressaddressThe address of the Inspector who realized the inspection.
regeneratorAddressaddressThe address of the Regenerator whose area was inspected.
treesResultuint32The reported number of trees.
biodiversityResultuint32The reported number of species.
regenerationScoreuint32The calculated regeneration score.
inspectedAtuint256The block number when the inspection was realized.

InspectionValidation

event InspectionValidation(address _validatorAddress, uint256 _resourceId, string _justification)

Emitted

Parameters

NameTypeDescription
_validatorAddressaddressThe address of the validator.
_resourceIduint256The id of the resource receiving the vote.
_justificationstringThe 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

NameTypeDescription
inspectionIduint256The ID of the inspection that was invalidated.
inspectorAddressaddressThe address of the Inspector who performed the invalidated inspection.
regeneratorAddressaddressThe address of the Regenerator whose inspection was invalidated.
invalidatedAtuint256The block number when the inspection was invalidated.