Comment on page
This smart contract is responsible for registering and managing users in the NFT Protect system and handling affiliate and partner payments.
Before diving into each function's details, let's understand some of the key entities, variables, and concepts used in the contract:
- 1.NFT Protect: The main system or service that uses the UserRegistry contract.
- 2.DID (Decentralized Identifier): A new type of identifier that enables verifiable, decentralized digital identity.
- 3.NFTP Coupons: A contract managing coupons that users can use for specific actions.
- 4.Successor: A user designated to take over another user's account for specific events.
- 5.Arbitrator: A third-party entity or service used to resolve disputes.
- 6.Referrer: A user who refers another user to the platform.
- 7.Partner: A user or entity with a specific partnership agreement with the platform.
The contract's constructor sets initial values for several key variables and emits the
Deployedevent. It also calls the
registerDIDfunctions, establishes a new
NFTPCouponscontract, and transfers ownership of the coupon contract to the message sender.
The contract uses the
onlyNFTProtectmodifier to restrict certain function calls to the address stored in the
The contract emits several events to log significant actions, such as changing the arbitrator registry, setting a referrer, registering a DID, or requesting/approving/rejecting a successor.
The contract uses a variety of variables to store data, including public addresses for various system components (like the
affiliatePercentfor referrers, a
numberOfRulingOptionsconstant, and several mappings to store referrers, partners, successors, and requests for successors.
The contract defines a
SuccessorRequeststruct to store information about a request for a successor, including the user, the successor, the arbitrator, and dispute IDs.
constructor(address areg, IUserDID did, address nftprotectaddr)
This is the contract's constructor function, which is executed once when the contract is deployed. It initializes the contract with the provided parameters:
areg: The address of the arbitrator registry.
did: The decentralized identifier (DID) of the user.
nftprotectaddr: The address of the NFT Protect service.
Sets the arbitrator registry to a new address. This can only be called by the contract owner. It also emits the
Sets the percentage of affiliate commission. This function can only be called by the contract owner and emits an
setPartner(address partner, uint256 percent)
Sets a partner with a specific commission percentage. Only the contract owner can call this function. It emits a
processPayment(address user, address payable referrer, bool canUseCoupons, uint256 fee)
This function is used to process payments from users. If the user has coupons and
canUseCouponsis true, a coupon will be used. Otherwise, the function checks that the correct fee is paid and handles the affiliate payment if a referrer exists. The function can only be called by the NFT Protect service.
Registers a new decentralized identifier (DID) for a user. This function can only be called by the contract owner and emits a
Unregisters a user's decentralized identifier (DID). This function can only be called by the contract owner and emits a
Checks whether a user is registered by iterating over all DIDs and checking if the user is identified by any of them.
Returns the maximum score among all DIDs for a user.
isSuccessor(address user, address successor)
Checks if the given address is set as a successor for a user.
Checks if a user has a successor.
successorRequest(address user, uint256 arbitratorId, string memory evidence)
Allows a user to request a successor. It requires that the user is registered. The function creates a dispute with the arbitrator service, stores the request, and emits a
Fetches the ruling of a dispute about a successor request. If the dispute is resolved, the function sets the successor or rejects the request, depending on the ruling, and deletes the request.