User Registry
This smart contract is responsible for registering and managing users in the NFT Protect system and handling affiliate and partner payments.
The contract code can be found here.
Prerequisites
Before diving into each function's details, let's understand some of the key entities, variables, and concepts used in the contract:
NFT Protect: The main system or service that uses the UserRegistry contract.
DID (Decentralized Identifier): A new type of identifier that enables verifiable, decentralized digital identity.
NFTP Coupons: A contract managing coupons that users can use for specific actions.
Successor: A user designated to take over another user's account for specific events.
Arbitrator: A third-party entity or service used to resolve disputes.
Referrer: A user who refers another user to the platform.
Partner: A user or entity with a specific partnership agreement with the platform.
Constructor
The contract's constructor sets initial values for several key variables and emits the Deployed
event. It also calls the setAffiliatePercent
, setArbitratorRegistry
, and registerDID
functions, establishes a new NFTPCoupons
contract, and transfers ownership of the coupon contract to the message sender.
Modifiers
The contract uses the onlyNFTProtect
modifier to restrict certain function calls to the address stored in the nftprotect
variable.
Events
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.
Variables
The contract uses a variety of variables to store data, including public addresses for various system components (like the nftprotect
and metaEvidenceLoader
), the affiliatePercent
for referrers, a numberOfRulingOptions
constant, and several mappings to store referrers, partners, successors, and requests for successors.
Structs
The contract defines a SuccessorRequest
struct to store information about a request for a successor, including the user, the successor, the arbitrator, and dispute IDs.
Functions
constructor
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.
setArbitratorRegistry
Sets the arbitrator registry to a new address. This can only be called by the contract owner. It also emits the ArbitratorRegistryChanged
event.
setAffiliatePercent
Sets the percentage of affiliate commission. This function can only be called by the contract owner and emits an AffiliatePercentChanged
event.
setPartner
Sets a partner with a specific commission percentage. Only the contract owner can call this function. It emits a PartnerSet
event.
processPayment
This function is used to process payments from users. If the user has coupons and canUseCoupons
is 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.
registerDID
Registers a new decentralized identifier (DID) for a user. This function can only be called by the contract owner and emits a DIDRegistered
event.
unregisterDID
Unregisters a user's decentralized identifier (DID). This function can only be called by the contract owner and emits a DIDUnregistered
event.
isRegistered
Checks whether a user is registered by iterating over all DIDs and checking if the user is identified by any of them.
scores
Returns the maximum score among all DIDs for a user.
isSuccessor
Checks if the given address is set as a successor for a user.
hasSuccessor
Checks if a user has a successor.
successorRequest
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 SuccessorRequested
event.
fetchRuling
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.
Last updated